Skip to content

Commit

Permalink
feat: support enableWal for the better-sqlite3 driver (#9619)
Browse files Browse the repository at this point in the history
  • Loading branch information
xtremebiker committed Feb 7, 2023
1 parent c418aae commit 8731858
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/driver/better-sqlite3/BetterSqlite3ConnectionOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,11 @@ export interface BetterSqlite3ConnectionOptions extends BaseDataSourceOptions {
readonly nativeBinding?: string

readonly poolSize?: never

/**
* Enables WAL mode. By default its disabled.
*
* @see https://www.sqlite.org/wal.html
*/
readonly enableWAL?: boolean
}
4 changes: 3 additions & 1 deletion src/driver/better-sqlite3/BetterSqlite3Driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ export class BetterSqlite3Driver extends AbstractSqliteDriver {
databaseConnection.exec(`PRAGMA foreign_keys = ON`)

// turn on WAL mode to enhance performance
databaseConnection.exec(`PRAGMA journal_mode = WAL`)
if (this.options.enableWAL) {
databaseConnection.exec(`PRAGMA journal_mode = WAL`)
}

return databaseConnection
}
Expand Down
33 changes: 33 additions & 0 deletions test/github-issues/9410/issue-9410.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import "reflect-metadata"
import { expect } from "chai"
import { DataSource } from "../../../src/data-source/DataSource"
import {
closeTestingConnections,
createTestingConnections,
reloadTestingDatabases,
} from "../../utils/test-utils"

describe("better-sqlite3 driver > enable wal", () => {
let connections: DataSource[]
before(
async () =>
(connections = await createTestingConnections({
entities: [],
enabledDrivers: ["better-sqlite3"],
driverSpecific: {
enableWAL: true,
},
})),
)
beforeEach(() => reloadTestingDatabases(connections))
after(() => closeTestingConnections(connections))

it("github issues > #9410 The better-sqlite3 driver should support the enableWal flag", () =>
Promise.all(
connections.map(async (connection) => {
const result = await connection.query("PRAGMA journal_mode")

expect(result).to.eql([{ journal_mode: "wal" }])
}),
))
})

0 comments on commit 8731858

Please sign in to comment.