Changeset View
Changeset View
Standalone View
Standalone View
swh/core/db/__init__.py
Show First 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | class BaseDb: | ||||
cf. swh.storage.db.Db, swh.archiver.db.ArchiverDb | cf. swh.storage.db.Db, swh.archiver.db.ArchiverDb | ||||
""" | """ | ||||
@classmethod | @classmethod | ||||
def adapt_conn(cls, conn): | def adapt_conn(cls, conn): | ||||
"""Makes psycopg2 use 'bytes' to decode bytea instead of | """Makes psycopg2 use 'bytes' to decode bytea instead of | ||||
'memoryview', for this connection.""" | 'memoryview', for this connection.""" | ||||
cur = conn.cursor() | |||||
cur.execute("SELECT null::bytea, null::bytea[]") | |||||
bytea_oid = cur.description[0][1] | |||||
bytea_array_oid = cur.description[1][1] | |||||
t_bytes = psycopg2.extensions.new_type( | t_bytes = psycopg2.extensions.new_type( | ||||
(bytea_oid,), "bytea", typecast_bytea) | (17,), "bytea", typecast_bytea) | ||||
psycopg2.extensions.register_type(t_bytes, conn) | psycopg2.extensions.register_type(t_bytes, conn) | ||||
t_bytes_array = psycopg2.extensions.new_array_type( | t_bytes_array = psycopg2.extensions.new_array_type( | ||||
(bytea_array_oid,), "bytea[]", t_bytes) | (1001,), "bytea[]", t_bytes) | ||||
psycopg2.extensions.register_type(t_bytes_array, conn) | psycopg2.extensions.register_type(t_bytes_array, conn) | ||||
@classmethod | @classmethod | ||||
def connect(cls, *args, **kwargs): | def connect(cls, *args, **kwargs): | ||||
"""factory method to create a DB proxy | """factory method to create a DB proxy | ||||
Accepts all arguments of psycopg2.connect; only some specific | Accepts all arguments of psycopg2.connect; only some specific | ||||
possibilities are reported below. | possibilities are reported below. | ||||
▲ Show 20 Lines • Show All 122 Lines • Show Last 20 Lines |