fix: Add flag to allow SQLite to use foreign keys
This commit is contained in:
parent
d4453e4a1d
commit
de19016494
1 changed files with 9 additions and 6 deletions
|
|
@ -92,14 +92,17 @@ class SQLAlchemyAdapter:
|
|||
return 0
|
||||
|
||||
try:
|
||||
# Dialect-agnostic table reference
|
||||
if self.engine.dialect.name == "sqlite":
|
||||
table = await self.get_table(table_name) # SQLite ignores schemas
|
||||
else:
|
||||
table = await self.get_table(table_name, schema_name)
|
||||
|
||||
# Use SQLAlchemy Core insert with execution options
|
||||
async with self.engine.begin() as conn:
|
||||
# Dialect-agnostic table reference
|
||||
if self.engine.dialect.name == "sqlite":
|
||||
# Foreign key constraints are disabled by default in SQLite (for backwards compatibility),
|
||||
# so must be enabled for each database connection/session separately.
|
||||
await conn.execute(text("PRAGMA foreign_keys=ON"))
|
||||
table = await self.get_table(table_name) # SQLite ignores schemas
|
||||
else:
|
||||
table = await self.get_table(table_name, schema_name)
|
||||
|
||||
result = await conn.execute(table.insert().values(data))
|
||||
|
||||
# Return rowcount for validation
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue