mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
feat: support busy_timeout param parameter for sqlite (#9623)
Co-authored-by: sinkhaha <1468709606@qq.com>
This commit is contained in:
parent
4eda5df869
commit
8668c29d83
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "typeorm",
|
||||
"version": "0.3.10",
|
||||
"version": "0.3.11",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "typeorm",
|
||||
"version": "0.3.10",
|
||||
"version": "0.3.11",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@sqltools/formatter": "^1.2.2",
|
||||
|
||||
@ -53,4 +53,12 @@ export interface SqliteConnectionOptions extends BaseDataSourceOptions {
|
||||
readonly flags?: number
|
||||
|
||||
readonly poolSize?: never
|
||||
|
||||
/**
|
||||
* Query or change the setting of the busy timeout.
|
||||
* Time in milliseconds.
|
||||
*
|
||||
* @see https://www.sqlite.org/pragma.html#pragma_busy_timeout
|
||||
*/
|
||||
readonly busyTimeout?: number
|
||||
}
|
||||
|
||||
@ -173,6 +173,14 @@ export class SqliteDriver extends AbstractSqliteDriver {
|
||||
await run(`PRAGMA journal_mode = WAL`)
|
||||
}
|
||||
|
||||
if (
|
||||
this.options.busyTimeout &&
|
||||
typeof this.options.busyTimeout === "number" &&
|
||||
this.options.busyTimeout > 0
|
||||
) {
|
||||
await run(`PRAGMA busy_timeout = ${this.options.busyTimeout}`)
|
||||
}
|
||||
|
||||
// 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.
|
||||
await run(`PRAGMA foreign_keys = ON`)
|
||||
|
||||
32
test/functional/sqlite/busy-timeout.ts
Normal file
32
test/functional/sqlite/busy-timeout.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import "reflect-metadata"
|
||||
import { expect } from "chai"
|
||||
import { DataSource } from "../../../src/data-source/DataSource"
|
||||
import {
|
||||
closeTestingConnections,
|
||||
createTestingConnections,
|
||||
reloadTestingDatabases,
|
||||
} from "../../utils/test-utils"
|
||||
|
||||
describe("sqlite driver > busy-timeout", () => {
|
||||
let connections: DataSource[]
|
||||
before(
|
||||
async () =>
|
||||
(connections = await createTestingConnections({
|
||||
entities: [],
|
||||
enabledDrivers: ["sqlite"],
|
||||
driverSpecific: {
|
||||
busyTimeout: 2000,
|
||||
},
|
||||
})),
|
||||
)
|
||||
beforeEach(() => reloadTestingDatabases(connections))
|
||||
after(() => closeTestingConnections(connections))
|
||||
|
||||
it("should set the busy_timeout as expected", () =>
|
||||
Promise.all(
|
||||
connections.map(async (connection) => {
|
||||
const result = await connection.query("PRAGMA busy_timeout")
|
||||
expect(result).to.eql([{ timeout: 2000 }])
|
||||
}),
|
||||
))
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user