CRUDKit update.
This commit is contained in:
parent
de29d45106
commit
f1fa1f2407
8 changed files with 391 additions and 44 deletions
14
crudkit/_sqlite.py
Normal file
14
crudkit/_sqlite.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
from __future__ import annotations
|
||||
from sqlalchemy import event
|
||||
from sqlalchemy.engine import Engine
|
||||
|
||||
def apply_sqlite_pragmas(engine: Engine, pragmas: dict[str, str]) -> None:
|
||||
if not str(engine.url).startswith("sqlite://"):
|
||||
return
|
||||
|
||||
@event.listens_for(engine, "connect")
|
||||
def set_sqlite_pragma(dbapi_connection, connection_record):
|
||||
cursor = dbapi_connection.cursor()
|
||||
for key, value in pragmas.items():
|
||||
cursor.execute(f"PRAGMA {key}={value}")
|
||||
cursor.close()
|
||||
Loading…
Add table
Add a link
Reference in a new issue