K
Kysely11mo ago
lorefnon

How to enable pragmas with SqliteDialect

Hello, I am using SqliteDialect and want to enable foreign_keys pragma. From SQLite Docs:
Foreign key constraints are disabled by default (for backwards compatibility), so must be enabled separately for each database connection.
sqlite> PRAGMA foreign_keys = ON;
sqlite> PRAGMA foreign_keys = ON;
I was trying to use SqliteDialect's onCreateConnection to enable this.
new SqliteDialect({
database: new SQLite(getNbDBPath(id)),
onCreateConnection: async (conn) => {
conn.executeQuery(/* ... */)
}
})
new SqliteDialect({
database: new SQLite(getNbDBPath(id)),
onCreateConnection: async (conn) => {
conn.executeQuery(/* ... */)
}
})
But the issue is that onCreateConnection provides me a DatabaseConnection instance. DatabaseConnection.executeQuery expects a CompiledQuery. To compile a query I can do something like
sql`PRAGMA foreign_keys = ON;`.compile(db)
sql`PRAGMA foreign_keys = ON;`.compile(db)
but the problem is that I don't have a db because I am creating a dialect which I will then use to create a db. Is there something I am missing or is there a better way to achieve this ?
Solution:
Message Not Public
Sign In & Join Server To View
Jump to solution
2 Replies
Solution
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
lorefnon
lorefnonOP11mo ago
Oh great. Thank you. Your repo looks very useful too.
Want results from more Discord servers?
Add your server