forked from pgvector/pgvector-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbit.py
More file actions
31 lines (19 loc) · 712 Bytes
/
bit.py
File metadata and controls
31 lines (19 loc) · 712 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from psycopg.adapt import Dumper
from psycopg.pq import Format
from ..utils import Bit
class BitDumper(Dumper):
format = Format.TEXT
def dump(self, obj):
return Bit._to_db(obj).encode('utf8')
class BitBinaryDumper(BitDumper):
format = Format.BINARY
def dump(self, obj):
return Bit._to_db_binary(obj)
def register_bit_info(context, info):
info.register(context)
# add oid to anonymous class for set_types
text_dumper = type('', (BitDumper,), {'oid': info.oid})
binary_dumper = type('', (BitBinaryDumper,), {'oid': info.oid})
adapters = context.adapters
adapters.register_dumper(Bit, text_dumper)
adapters.register_dumper(Bit, binary_dumper)