File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change 1+ import asyncpg
2+ from sqlalchemy .dialects .postgresql .asyncpg import PGDialect_asyncpg
13from sqlalchemy .dialects .postgresql .base import ischema_names
24from sqlalchemy .types import UserDefinedType , Float
3-
5+ from .. import Bit
46
57class BIT (UserDefinedType ):
68 cache_ok = True
@@ -14,6 +16,21 @@ def get_col_spec(self, **kw):
1416 return 'BIT'
1517 return 'BIT(%d)' % self .length
1618
19+ def bind_processor (self , dialect ):
20+ def process (value ):
21+ value = Bit ._to_db (value )
22+ if value and isinstance (dialect , PGDialect_asyncpg ):
23+ return asyncpg .BitString (value )
24+ return value
25+ return process
26+
27+ def result_processor (self , dialect , coltype ):
28+ def process (value ):
29+ if value and isinstance (dialect , PGDialect_asyncpg ):
30+ return value .as_string ()
31+ return Bit ._from_db (value ).to_text ()
32+ return process
33+
1734 class comparator_factory (UserDefinedType .Comparator ):
1835 def hamming_distance (self , other ):
1936 return self .op ('<~>' , return_type = Float )(other )
You can’t perform that action at this time.
0 commit comments