blob: 1452edc28580707175d6402537c585b979f28ca6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
from debian.debian_support import version_compare
import sqlalchemy.event
def fetchiter(cursor):
rows = cursor.fetchmany(1024)
while rows:
for row in rows:
yield row
rows = cursor.fetchmany(1024)
def enable_sqlite_foreign_keys(engine):
if engine.dialect.name != "sqlite":
return
@sqlalchemy.event.listens_for(engine, "connect")
def pragma_foreign_keys(connection, _):
connection.execute("PRAGMA foreign_keys=ON;")
def sqlite_add_version_compare(engine):
if engine.dialect.name != "sqlite":
return
@sqlalchemy.event.listens_for(engine, "connect")
def add_version_compare(connection, _):
connection.create_collation("debian_version", version_compare)
connection.create_function("debian_version_compare", 2, version_compare)
def postgres_enable_result_streaming(engine):
if engine.dialect.driver != "psycopg2":
return
engine.server_side_cursors = True
def configure_database_engine(engine):
enable_sqlite_foreign_keys(engine)
sqlite_add_version_compare(engine)
postgres_enable_result_streaming(engine)
|