Reputation: 835
I want to run PRAGMA journal_mode = WAL
on my database connection as soon as it is connected using the Kysely library.
Here's what I've tried:
const dialect = new SqliteDialect({
database: new SQLite(":memory:"),
onCreateConnection: async connnection => {
const pragmaQuery = sql<string>`PRAGMA journal_mode = WAL`;
connection.executeQuery(pragmaQuery.compile());
},
});
However, pragmaQuery.compile()
requires a reference to the database, which I don't have in this function's scope. (I instantiate db
below, which needs dialect
as an argument.)
I'm having trouble using the DatabaseConnection interface, as it has very few callable methods.
Upvotes: 1
Views: 529
Reputation: 46
const dialect = new SqliteDialect({
database: new SQLite(":memory:"),
onCreateConnection: async connnection => {
await connnection.executeQuery(CompiledQuery.raw(`PRAGMA journal_mode = WAL`));
},
});
Upvotes: 3
Reputation: 187
Option A (execute raw SQL via Kysely):
const dialect = new SqliteDialect({
database: new SQLite(":memory:")
});
export const db = new Kysely<Database>({
dialect
})
sql`PRAGMA journal_mode=WAL`.execute(db)
Option B (execute SQL directly on SQLite instance):
const sqlite = new SQLite(":memory:")
const dialect = new SqliteDialect({
database: sqlite
});
sqlite.exec('PRAGMA journal_mode=WAL')
Upvotes: 0