Disable type registration when buscribe connects to the DB

Because those types don't exist in the buscribe DB.
pull/414/head
Mike Lang 1 month ago
parent b16ceef96a
commit ff8475dc48

@ -40,7 +40,7 @@ def main(channel, database="", base_dir=".",
segments_dir = os.path.join(base_dir, channel, "source") segments_dir = os.path.join(base_dir, channel, "source")
logging.debug("Grabbing database...") logging.debug("Grabbing database...")
db_manager = DBManager(dsn=database) db_manager = DBManager(dsn=database, register_types=False)
db_conn = db_manager.get_conn() db_conn = db_manager.get_conn()
db_cursor = db_conn.cursor() db_cursor = db_conn.cursor()
logging.debug("Got database cursor.") logging.debug("Got database cursor.")

@ -41,16 +41,22 @@ class DBManager(object):
for easy creation of new connections, and sets some defaults before for easy creation of new connections, and sets some defaults before
returning them. returning them.
By default, assumes it is connecting to the main wubloader database
and registers known composite types (so they get returned as namedtuples).
If you don't want this (eg. you're not connecting to the main database),
set register_types=False.
It has the ability to serve as a primitive connection pool, as getting a It has the ability to serve as a primitive connection pool, as getting a
new conn will return existing conns it knows about first, but you new conn will return existing conns it knows about first, but you
should use a real conn pool for any non-trivial use. should use a real conn pool for any non-trivial use.
Returned conns are set to seralizable isolation level, autocommit, and use Returned conns are set to seralizable isolation level, autocommit, and use
NamedTupleCursor cursors.""" NamedTupleCursor cursors."""
def __init__(self, connect_timeout=30, **connect_kwargs): def __init__(self, connect_timeout=30, register_types=True, **connect_kwargs):
patch_psycopg() patch_psycopg()
self.conns = [] self.conns = []
self.connect_timeout = connect_timeout self.connect_timeout = connect_timeout
self.register_types = register_types
self.connect_kwargs = connect_kwargs self.connect_kwargs = connect_kwargs
def put_conn(self, conn): def put_conn(self, conn):
@ -67,8 +73,9 @@ class DBManager(object):
# searches or targetted single-row updates. # searches or targetted single-row updates.
conn.isolation_level = psycopg2.extensions.ISOLATION_LEVEL_SERIALIZABLE conn.isolation_level = psycopg2.extensions.ISOLATION_LEVEL_SERIALIZABLE
conn.autocommit = True conn.autocommit = True
for composite in COMPOSITE_TYPES: if self.register_types:
psycopg2.extras.register_composite(composite, conn) for composite in COMPOSITE_TYPES:
psycopg2.extras.register_composite(composite, conn)
return conn return conn

Loading…
Cancel
Save