lorefnon
lorefnon
Explore posts from servers
KKysely
Created by lorefnon on 2/6/2024 in #help
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 ?
4 replies