To make binary string storing compatible with both SQLite and PostgreSQL, convert the bin data to hex to store and convert hex back to binary to get
| 138 | |
| 139 | |
| 140 | class PgAdminDbBinaryString(types.TypeDecorator): |
| 141 | """ |
| 142 | To make binary string storing compatible with both |
| 143 | SQLite and PostgreSQL, convert the bin data to hex |
| 144 | to store and convert hex back to binary to get |
| 145 | """ |
| 146 | cache_ok = True |
| 147 | impl = types.String |
| 148 | |
| 149 | def process_bind_param(self, value, dialect): |
| 150 | return value.hex() if hasattr(value, 'hex') \ |
| 151 | else value |
| 152 | |
| 153 | def process_result_value(self, value, dialect): |
| 154 | try: |
| 155 | return bytes.fromhex(value) |
| 156 | except Exception as _: |
| 157 | return value |
| 158 | |
| 159 | |
| 160 | class Version(db.Model): |
no outgoing calls
no test coverage detected