@ocap/statedb-sqlite 1.30.10 → 1.30.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/index.d.mts +2 -2
- package/esm/index.mjs +2 -1
- package/esm/kysely.d.mts +12 -0
- package/esm/kysely.mjs +15 -0
- package/lib/index.cjs +3 -1
- package/lib/index.d.cts +2 -2
- package/lib/kysely.cjs +15 -0
- package/lib/kysely.d.cts +12 -0
- package/package.json +5 -5
package/esm/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Database, SqliteOperationContext } from "./interfaces.mjs";
|
|
2
|
-
import { SqliteConfig } from "./kysely.mjs";
|
|
2
|
+
import { SqliteConfig, getRawDatabase } from "./kysely.mjs";
|
|
3
3
|
import SqliteStateDB from "./db.mjs";
|
|
4
|
-
export { type Database, type SqliteConfig, type SqliteOperationContext, SqliteStateDB, SqliteStateDB as default };
|
|
4
|
+
export { type Database, type SqliteConfig, type SqliteOperationContext, SqliteStateDB, SqliteStateDB as default, getRawDatabase };
|
package/esm/index.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { getRawDatabase } from "./kysely.mjs";
|
|
1
2
|
import db_default from "./db.mjs";
|
|
2
3
|
|
|
3
4
|
//#region src/index.ts
|
|
4
5
|
var src_default = db_default;
|
|
5
6
|
|
|
6
7
|
//#endregion
|
|
7
|
-
export { db_default as SqliteStateDB, src_default as default };
|
|
8
|
+
export { db_default as SqliteStateDB, src_default as default, getRawDatabase };
|
package/esm/kysely.d.mts
CHANGED
|
@@ -15,6 +15,18 @@ interface SqliteConfig {
|
|
|
15
15
|
create?: boolean;
|
|
16
16
|
/** Enable WAL mode (default: true) */
|
|
17
17
|
walMode?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* `PRAGMA wal_autocheckpoint` value (in 4KB pages) when WAL is enabled.
|
|
20
|
+
* SQLite default is 1000 pages (~4MB) which forces a synchronous WAL→main
|
|
21
|
+
* DB checkpoint inside writer transactions every ~30s at 100 TPS, causing
|
|
22
|
+
* latency spikes. Bumping it spreads I/O over a larger window. Set to 0
|
|
23
|
+
* to disable auto-checkpoint entirely (caller must run periodic
|
|
24
|
+
* `wal_checkpoint(PASSIVE)` from a background worker).
|
|
25
|
+
*
|
|
26
|
+
* Falls back to `SQLITE_WAL_AUTOCHECKPOINT` env (process-global) when not
|
|
27
|
+
* provided. If neither is set, SQLite's default (1000) is left untouched.
|
|
28
|
+
*/
|
|
29
|
+
walAutoCheckpoint?: number;
|
|
18
30
|
}
|
|
19
31
|
/**
|
|
20
32
|
* Create a Kysely instance with SQLite dialect
|
package/esm/kysely.mjs
CHANGED
|
@@ -6,6 +6,17 @@ function isBunRuntime() {
|
|
|
6
6
|
return typeof globalThis.Bun !== "undefined";
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
|
+
* Resolve the wal_autocheckpoint value, preferring explicit config over env.
|
|
10
|
+
* Env is read at call time (not module load) so test harnesses and lazy
|
|
11
|
+
* config flows work uniformly. Returns undefined when no override is set
|
|
12
|
+
* (SQLite default — typically 1000 pages — applies).
|
|
13
|
+
*/
|
|
14
|
+
function resolveWalAutoCheckpoint(config) {
|
|
15
|
+
const fromEnv = process.env.SQLITE_WAL_AUTOCHECKPOINT ? Number(process.env.SQLITE_WAL_AUTOCHECKPOINT) : void 0;
|
|
16
|
+
const v = config.walAutoCheckpoint ?? fromEnv;
|
|
17
|
+
return Number.isFinite(v) ? v : void 0;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
9
20
|
* Create a Kysely instance with SQLite dialect
|
|
10
21
|
* Automatically uses kysely-bun-sqlite in Bun or better-sqlite3 in Node.js
|
|
11
22
|
*
|
|
@@ -32,6 +43,8 @@ function createKysely(config) {
|
|
|
32
43
|
if (config.walMode !== false && !config.readonly && config.filename !== ":memory:") {
|
|
33
44
|
sqlite$1.exec("PRAGMA journal_mode = WAL");
|
|
34
45
|
sqlite$1.exec("PRAGMA synchronous = NORMAL");
|
|
46
|
+
const walCp = resolveWalAutoCheckpoint(config);
|
|
47
|
+
if (walCp !== void 0) sqlite$1.exec(`PRAGMA wal_autocheckpoint = ${walCp}`);
|
|
35
48
|
}
|
|
36
49
|
sqlite$1.exec("PRAGMA foreign_keys = ON");
|
|
37
50
|
sqlite$1.exec("PRAGMA busy_timeout = 5000");
|
|
@@ -44,6 +57,8 @@ function createKysely(config) {
|
|
|
44
57
|
if (config.walMode !== false && !config.readonly && config.filename !== ":memory:") {
|
|
45
58
|
sqlite.pragma("journal_mode = WAL");
|
|
46
59
|
sqlite.pragma("synchronous = NORMAL");
|
|
60
|
+
const walCp = resolveWalAutoCheckpoint(config);
|
|
61
|
+
if (walCp !== void 0) sqlite.pragma(`wal_autocheckpoint = ${walCp}`);
|
|
47
62
|
}
|
|
48
63
|
sqlite.pragma("foreign_keys = ON");
|
|
49
64
|
sqlite.pragma("busy_timeout = 5000");
|
package/lib/index.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_kysely = require('./kysely.cjs');
|
|
2
3
|
const require_db = require('./db.cjs');
|
|
3
4
|
|
|
4
5
|
//#region src/index.ts
|
|
@@ -6,4 +7,5 @@ var src_default = require_db.default;
|
|
|
6
7
|
|
|
7
8
|
//#endregion
|
|
8
9
|
exports.SqliteStateDB = require_db.default;
|
|
9
|
-
exports.default = src_default;
|
|
10
|
+
exports.default = src_default;
|
|
11
|
+
exports.getRawDatabase = require_kysely.getRawDatabase;
|
package/lib/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Database, SqliteOperationContext } from "./interfaces.cjs";
|
|
2
|
-
import { SqliteConfig } from "./kysely.cjs";
|
|
2
|
+
import { SqliteConfig, getRawDatabase } from "./kysely.cjs";
|
|
3
3
|
import SqliteStateDB from "./db.cjs";
|
|
4
|
-
export { type Database, type SqliteConfig, type SqliteOperationContext, SqliteStateDB, SqliteStateDB as default };
|
|
4
|
+
export { type Database, type SqliteConfig, type SqliteOperationContext, SqliteStateDB, SqliteStateDB as default, getRawDatabase };
|
package/lib/kysely.cjs
CHANGED
|
@@ -6,6 +6,17 @@ function isBunRuntime() {
|
|
|
6
6
|
return typeof globalThis.Bun !== "undefined";
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
|
+
* Resolve the wal_autocheckpoint value, preferring explicit config over env.
|
|
10
|
+
* Env is read at call time (not module load) so test harnesses and lazy
|
|
11
|
+
* config flows work uniformly. Returns undefined when no override is set
|
|
12
|
+
* (SQLite default — typically 1000 pages — applies).
|
|
13
|
+
*/
|
|
14
|
+
function resolveWalAutoCheckpoint(config) {
|
|
15
|
+
const fromEnv = process.env.SQLITE_WAL_AUTOCHECKPOINT ? Number(process.env.SQLITE_WAL_AUTOCHECKPOINT) : void 0;
|
|
16
|
+
const v = config.walAutoCheckpoint ?? fromEnv;
|
|
17
|
+
return Number.isFinite(v) ? v : void 0;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
9
20
|
* Create a Kysely instance with SQLite dialect
|
|
10
21
|
* Automatically uses kysely-bun-sqlite in Bun or better-sqlite3 in Node.js
|
|
11
22
|
*
|
|
@@ -32,6 +43,8 @@ function createKysely(config) {
|
|
|
32
43
|
if (config.walMode !== false && !config.readonly && config.filename !== ":memory:") {
|
|
33
44
|
sqlite$1.exec("PRAGMA journal_mode = WAL");
|
|
34
45
|
sqlite$1.exec("PRAGMA synchronous = NORMAL");
|
|
46
|
+
const walCp = resolveWalAutoCheckpoint(config);
|
|
47
|
+
if (walCp !== void 0) sqlite$1.exec(`PRAGMA wal_autocheckpoint = ${walCp}`);
|
|
35
48
|
}
|
|
36
49
|
sqlite$1.exec("PRAGMA foreign_keys = ON");
|
|
37
50
|
sqlite$1.exec("PRAGMA busy_timeout = 5000");
|
|
@@ -44,6 +57,8 @@ function createKysely(config) {
|
|
|
44
57
|
if (config.walMode !== false && !config.readonly && config.filename !== ":memory:") {
|
|
45
58
|
sqlite.pragma("journal_mode = WAL");
|
|
46
59
|
sqlite.pragma("synchronous = NORMAL");
|
|
60
|
+
const walCp = resolveWalAutoCheckpoint(config);
|
|
61
|
+
if (walCp !== void 0) sqlite.pragma(`wal_autocheckpoint = ${walCp}`);
|
|
47
62
|
}
|
|
48
63
|
sqlite.pragma("foreign_keys = ON");
|
|
49
64
|
sqlite.pragma("busy_timeout = 5000");
|
package/lib/kysely.d.cts
CHANGED
|
@@ -15,6 +15,18 @@ interface SqliteConfig {
|
|
|
15
15
|
create?: boolean;
|
|
16
16
|
/** Enable WAL mode (default: true) */
|
|
17
17
|
walMode?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* `PRAGMA wal_autocheckpoint` value (in 4KB pages) when WAL is enabled.
|
|
20
|
+
* SQLite default is 1000 pages (~4MB) which forces a synchronous WAL→main
|
|
21
|
+
* DB checkpoint inside writer transactions every ~30s at 100 TPS, causing
|
|
22
|
+
* latency spikes. Bumping it spreads I/O over a larger window. Set to 0
|
|
23
|
+
* to disable auto-checkpoint entirely (caller must run periodic
|
|
24
|
+
* `wal_checkpoint(PASSIVE)` from a background worker).
|
|
25
|
+
*
|
|
26
|
+
* Falls back to `SQLITE_WAL_AUTOCHECKPOINT` env (process-global) when not
|
|
27
|
+
* provided. If neither is set, SQLite's default (1000) is left untouched.
|
|
28
|
+
*/
|
|
29
|
+
walAutoCheckpoint?: number;
|
|
18
30
|
}
|
|
19
31
|
/**
|
|
20
32
|
* Create a Kysely instance with SQLite dialect
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ocap/statedb-sqlite",
|
|
3
3
|
"description": "OCAP statedb adapter that uses SQLite as backend",
|
|
4
|
-
"version": "1.30.
|
|
4
|
+
"version": "1.30.12",
|
|
5
5
|
"author": "wangshijun <shijun@arcblock.io> (https://www.arcblock.io)",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/ArcBlock/blockchain/issues",
|
|
@@ -61,10 +61,10 @@
|
|
|
61
61
|
"clean": "rm -rf lib esm"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@ocap/state": "1.30.
|
|
65
|
-
"@ocap/statedb": "1.30.
|
|
66
|
-
"@ocap/types": "1.30.
|
|
67
|
-
"@ocap/util": "1.30.
|
|
64
|
+
"@ocap/state": "1.30.12",
|
|
65
|
+
"@ocap/statedb": "1.30.12",
|
|
66
|
+
"@ocap/types": "1.30.12",
|
|
67
|
+
"@ocap/util": "1.30.12",
|
|
68
68
|
"better-sqlite3": "^11.8.1",
|
|
69
69
|
"kysely": "^0.28.14",
|
|
70
70
|
"kysely-bun-sqlite": "^0.4.0",
|