Skip to content

Commit 05349f9

Browse files
committed
feat: add method to read from database and make method to write to database more general
1 parent ee3e71c commit 05349f9

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

pgvector/bit.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,12 @@ def from_binary(cls, value):
6262

6363
@classmethod
6464
def _to_db(cls, value):
65+
if value is None:
66+
return value
67+
6568
if not isinstance(value, cls):
66-
raise ValueError('expected bit')
67-
69+
value = cls(value)
70+
6871
return value.to_text()
6972

7073
@classmethod
@@ -73,3 +76,9 @@ def _to_db_binary(cls, value):
7376
raise ValueError('expected bit')
7477

7578
return value.to_binary()
79+
80+
@classmethod
81+
def _from_db(cls, value):
82+
if value is None or isinstance(value, cls):
83+
return value
84+
return cls.from_text(value)

0 commit comments

Comments
 (0)