-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Types: Add support for BINARY columns and improve support for FLOATs
- Loading branch information
Showing
4 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from .array import ObjectArray | ||
from .binary import LargeBinary | ||
from .geo import Geopoint, Geoshape | ||
from .object import ObjectType | ||
from .vector import FloatVector |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import base64 | ||
import sqlalchemy as sa | ||
|
||
|
||
class LargeBinary(sa.String): | ||
|
||
"""A type for large binary byte data. | ||
The :class:`.LargeBinary` type corresponds to a large and/or unlengthed | ||
binary type for the target platform, such as BLOB on MySQL and BYTEA for | ||
PostgreSQL. It also handles the necessary conversions for the DBAPI. | ||
""" | ||
|
||
__visit_name__ = "large_binary" | ||
|
||
def bind_processor(self, dialect): | ||
if dialect.dbapi is None: | ||
return None | ||
|
||
# TODO: DBAPIBinary = dialect.dbapi.Binary | ||
|
||
def process(value): | ||
if value is not None: | ||
# TODO: return DBAPIBinary(value) | ||
return base64.b64encode(value).decode() | ||
else: | ||
return None | ||
|
||
return process | ||
|
||
# Python 3 has native bytes() type | ||
# both sqlite3 and pg8000 seem to return it, | ||
# psycopg2 as of 2.5 returns 'memoryview' | ||
def result_processor(self, dialect, coltype): | ||
if dialect.returns_native_bytes: | ||
return None | ||
|
||
def process(value): | ||
if value is not None: | ||
return base64.b64decode(value) | ||
return value | ||
|
||
return process |