mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
refactor: use pragma method in better-sqlite3 (#10684)
This commit is contained in:
parent
c4f5d12f3f
commit
ec3ea10b44
@ -138,7 +138,7 @@ export class BetterSqlite3Driver extends AbstractSqliteDriver {
|
||||
nativeBinding = null,
|
||||
prepareDatabase,
|
||||
} = this.options
|
||||
const databaseConnection = this.sqlite(database, {
|
||||
const databaseConnection = new this.sqlite(database, {
|
||||
readonly,
|
||||
fileMustExist,
|
||||
timeout,
|
||||
@ -148,8 +148,8 @@ export class BetterSqlite3Driver extends AbstractSqliteDriver {
|
||||
// in the options, if encryption key for SQLCipher is setted.
|
||||
// Must invoke key pragma before trying to do any other interaction with the database.
|
||||
if (this.options.key) {
|
||||
databaseConnection.exec(
|
||||
`PRAGMA key = ${JSON.stringify(this.options.key)}`,
|
||||
databaseConnection.pragma(
|
||||
`key = ${JSON.stringify(this.options.key)}`,
|
||||
)
|
||||
}
|
||||
|
||||
@ -160,11 +160,11 @@ export class BetterSqlite3Driver extends AbstractSqliteDriver {
|
||||
|
||||
// we need to enable foreign keys in sqlite to make sure all foreign key related features
|
||||
// working properly. this also makes onDelete to work with sqlite.
|
||||
databaseConnection.exec(`PRAGMA foreign_keys = ON`)
|
||||
databaseConnection.pragma("foreign_keys = ON")
|
||||
|
||||
// turn on WAL mode to enhance performance
|
||||
if (this.options.enableWAL) {
|
||||
databaseConnection.exec(`PRAGMA journal_mode = WAL`)
|
||||
databaseConnection.pragma("journal_mode = WAL")
|
||||
}
|
||||
|
||||
return databaseConnection
|
||||
|
||||
@ -62,14 +62,16 @@ export class BetterSqlite3QueryRunner extends AbstractSqliteQueryRunner {
|
||||
* Called before migrations are run.
|
||||
*/
|
||||
async beforeMigration(): Promise<void> {
|
||||
await this.query(`PRAGMA foreign_keys = OFF`)
|
||||
const databaseConnection = await this.connect()
|
||||
databaseConnection.pragma("foreign_keys = OFF")
|
||||
}
|
||||
|
||||
/**
|
||||
* Called after migrations are run.
|
||||
*/
|
||||
async afterMigration(): Promise<void> {
|
||||
await this.query(`PRAGMA foreign_keys = ON`)
|
||||
const databaseConnection = await this.connect()
|
||||
databaseConnection.pragma("foreign_keys = ON")
|
||||
}
|
||||
|
||||
/**
|
||||
@ -172,10 +174,9 @@ export class BetterSqlite3QueryRunner extends AbstractSqliteQueryRunner {
|
||||
}
|
||||
protected async loadPragmaRecords(tablePath: string, pragma: string) {
|
||||
const [database, tableName] = this.splitTablePath(tablePath)
|
||||
const res = await this.query(
|
||||
`PRAGMA ${
|
||||
database ? `"${database}".` : ""
|
||||
}${pragma}("${tableName}")`,
|
||||
const databaseConnection = await this.connect()
|
||||
const res = databaseConnection.pragma(
|
||||
`${database ? `"${database}".` : ""}${pragma}("${tableName}")`,
|
||||
)
|
||||
return res
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user