@ocap/statedb-sqlite 1.29.5

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.
Files changed (50) hide show
  1. package/README.md +66 -0
  2. package/esm/_virtual/rolldown_runtime.mjs +21 -0
  3. package/esm/db.d.mts +92 -0
  4. package/esm/db.mjs +257 -0
  5. package/esm/index.d.mts +4 -0
  6. package/esm/index.mjs +7 -0
  7. package/esm/interfaces.d.mts +201 -0
  8. package/esm/interfaces.mjs +1 -0
  9. package/esm/kysely.d.mts +43 -0
  10. package/esm/kysely.mjs +62 -0
  11. package/esm/migrations/001-genesis.d.mts +14 -0
  12. package/esm/migrations/001-genesis.mjs +52 -0
  13. package/esm/migrations/index.d.mts +24 -0
  14. package/esm/migrations/index.mjs +60 -0
  15. package/esm/package.mjs +70 -0
  16. package/esm/table/account.d.mts +40 -0
  17. package/esm/table/account.mjs +99 -0
  18. package/esm/table/balance.d.mts +39 -0
  19. package/esm/table/balance.mjs +69 -0
  20. package/esm/table/base.d.mts +84 -0
  21. package/esm/table/base.mjs +217 -0
  22. package/esm/table/rollup.d.mts +22 -0
  23. package/esm/table/rollup.mjs +44 -0
  24. package/esm/table/token.d.mts +23 -0
  25. package/esm/table/token.mjs +42 -0
  26. package/lib/_virtual/rolldown_runtime.cjs +43 -0
  27. package/lib/db.cjs +259 -0
  28. package/lib/db.d.cts +92 -0
  29. package/lib/index.cjs +9 -0
  30. package/lib/index.d.cts +4 -0
  31. package/lib/interfaces.cjs +0 -0
  32. package/lib/interfaces.d.cts +201 -0
  33. package/lib/kysely.cjs +63 -0
  34. package/lib/kysely.d.cts +43 -0
  35. package/lib/migrations/001-genesis.cjs +59 -0
  36. package/lib/migrations/001-genesis.d.cts +14 -0
  37. package/lib/migrations/index.cjs +62 -0
  38. package/lib/migrations/index.d.cts +24 -0
  39. package/lib/package.cjs +76 -0
  40. package/lib/table/account.cjs +101 -0
  41. package/lib/table/account.d.cts +40 -0
  42. package/lib/table/balance.cjs +71 -0
  43. package/lib/table/balance.d.cts +39 -0
  44. package/lib/table/base.cjs +221 -0
  45. package/lib/table/base.d.cts +84 -0
  46. package/lib/table/rollup.cjs +45 -0
  47. package/lib/table/rollup.d.cts +22 -0
  48. package/lib/table/token.cjs +43 -0
  49. package/lib/table/token.d.cts +23 -0
  50. package/package.json +75 -0
package/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # [**@ocap/statedb-sqlite**](https://github.com/arcblock/blockchain)
2
+
3
+ > OCAP statedb adapter that uses SQLite as backend via [Kysely](https://kysely.dev/)
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install @ocap/statedb-sqlite
9
+ // or
10
+ bun install @ocap/statedb-sqlite
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ### In-Memory Mode
16
+
17
+ For testing or ephemeral data:
18
+
19
+ ```js
20
+ const SqliteStateDB = require('@ocap/statedb-sqlite').default;
21
+
22
+ const statedb = new SqliteStateDB({ filename: ':memory:' });
23
+ await statedb.initialize();
24
+
25
+ // Use statedb...
26
+ await statedb.account.create('z1abc...', { balance: '1000' });
27
+
28
+ // Close when done
29
+ await statedb.close();
30
+ ```
31
+
32
+ ### File Mode
33
+
34
+ For persistent storage:
35
+
36
+ ```js
37
+ const SqliteStateDB = require('@ocap/statedb-sqlite').default;
38
+
39
+ const statedb = new SqliteStateDB({ filename: '/path/to/statedb.sqlite' });
40
+ await statedb.initialize();
41
+
42
+ // Data persists across restarts
43
+ ```
44
+
45
+ ## Features
46
+
47
+ - WAL mode enabled by default for better concurrent read performance
48
+ - Automatic migrations on initialization
49
+ - Transaction support via `runAsLambda()`
50
+ - All 13 state tables: account, asset, token, factory, stake, delegation, rollup, etc.
51
+
52
+ ## API
53
+
54
+ ### Constructor Options
55
+
56
+ ```typescript
57
+ interface SqliteStateDBOptions {
58
+ filename: string; // ':memory:' or file path
59
+ }
60
+ ```
61
+
62
+ ### Methods
63
+
64
+ - `initialize()` - Run migrations and prepare database
65
+ - `close()` - Close database connection
66
+ - `runAsLambda(fn)` - Execute function within a transaction
@@ -0,0 +1,21 @@
1
+ import { createRequire } from "node:module";
2
+
3
+ //#region rolldown:runtime
4
+ var __defProp = Object.defineProperty;
5
+ var __exportAll = (all, symbols) => {
6
+ let target = {};
7
+ for (var name in all) {
8
+ __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ }
13
+ if (symbols) {
14
+ __defProp(target, Symbol.toStringTag, { value: "Module" });
15
+ }
16
+ return target;
17
+ };
18
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
19
+
20
+ //#endregion
21
+ export { __exportAll, __require };
package/esm/db.d.mts ADDED
@@ -0,0 +1,92 @@
1
+ import { Database } from "./interfaces.mjs";
2
+ import { SqliteConfig } from "./kysely.mjs";
3
+ import { StateDB } from "@ocap/statedb";
4
+ import { Kysely, Transaction } from "kysely";
5
+ import { IAccountState, IAssetFactoryState, IAssetState, IBalanceTable, IChainState, IDelegateState, IEvidenceState, IRollupBlock, IRollupTable, IStakeState, IStateDB, IStateTable, ITokenFactoryState, ITokenTable, ITxState } from "@ocap/types";
6
+
7
+ //#region src/db.d.ts
8
+
9
+ /**
10
+ * SQLite StateDB Implementation
11
+ * Uses SQLite via Kysely as the storage backend
12
+ */
13
+ declare class SqliteStateDB extends StateDB implements IStateDB {
14
+ name: string;
15
+ version: string;
16
+ private db;
17
+ private config;
18
+ private initialized;
19
+ balance: IBalanceTable;
20
+ account: IStateTable<IAccountState>;
21
+ factory: IStateTable<IAssetFactoryState>;
22
+ stake: IStateTable<IStakeState>;
23
+ asset: IStateTable<IAssetState>;
24
+ delegation: IStateTable<IDelegateState>;
25
+ tx: IStateTable<ITxState>;
26
+ token: ITokenTable;
27
+ chain: IStateTable<IChainState>;
28
+ rollup: IRollupTable;
29
+ rollupBlock: IStateTable<IRollupBlock>;
30
+ evidence: IStateTable<IEvidenceState>;
31
+ tokenFactory: IStateTable<ITokenFactoryState>;
32
+ /**
33
+ * Creates an instance of SqliteStateDB
34
+ *
35
+ * @param config - SQLite configuration (defaults to in-memory)
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * // In-memory database for testing
40
+ * const db = new SqliteStateDB();
41
+ * await db.initialize();
42
+ *
43
+ * // File-based database for production
44
+ * const db = new SqliteStateDB({ filename: './data/state.sqlite' });
45
+ * await db.initialize();
46
+ * ```
47
+ */
48
+ constructor(config?: SqliteConfig);
49
+ /**
50
+ * Synchronous initialization
51
+ * Called from constructor for immediate table availability
52
+ */
53
+ private initSync;
54
+ /**
55
+ * Async initialization - runs migrations
56
+ * Call this after constructor to ensure database schema is ready
57
+ */
58
+ initialize(): Promise<void>;
59
+ /**
60
+ * Execute multiple operations within a database transaction
61
+ * Provides retry logic for SQLite BUSY errors (lock conflicts)
62
+ *
63
+ * @param fn - Function receiving Kysely transaction object
64
+ * @param options - Optional retry configuration
65
+ * @returns Result of the transaction function
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * await db.runAsLambda(async (txn) => {
70
+ * await txn.insertInto('account').values({ ... }).execute();
71
+ * await txn.updateTable('balance').set({ ... }).execute();
72
+ * });
73
+ * ```
74
+ */
75
+ runAsLambda<T>(fn: (txn: Transaction<Database>) => T | Promise<T>, options?: {
76
+ retryLimit?: number;
77
+ }): Promise<T>;
78
+ /**
79
+ * Reset all tables (for testing)
80
+ */
81
+ reset(): Promise<void>;
82
+ /**
83
+ * Close database connection
84
+ */
85
+ close(): Promise<void>;
86
+ /**
87
+ * Get the underlying Kysely instance (for advanced operations)
88
+ */
89
+ getKysely(): Kysely<Database>;
90
+ }
91
+ //#endregion
92
+ export { SqliteStateDB as default };
package/esm/db.mjs ADDED
@@ -0,0 +1,257 @@
1
+ import { createKysely } from "./kysely.mjs";
2
+ import { runMigrations } from "./migrations/index.mjs";
3
+ import base_default from "./table/base.mjs";
4
+ import account_default from "./table/account.mjs";
5
+ import balance_default from "./table/balance.mjs";
6
+ import rollup_default from "./table/rollup.mjs";
7
+ import token_default from "./table/token.mjs";
8
+ import package_default from "./package.mjs";
9
+ import { StateDB } from "@ocap/statedb";
10
+
11
+ //#region src/db.ts
12
+ const { name, version } = package_default;
13
+ const SQLITE_BUSY_CODES = ["SQLITE_BUSY", "SQLITE_LOCKED"];
14
+ /**
15
+ * SQLite StateDB Implementation
16
+ * Uses SQLite via Kysely as the storage backend
17
+ */
18
+ var SqliteStateDB = class extends StateDB {
19
+ /**
20
+ * Creates an instance of SqliteStateDB
21
+ *
22
+ * @param config - SQLite configuration (defaults to in-memory)
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * // In-memory database for testing
27
+ * const db = new SqliteStateDB();
28
+ * await db.initialize();
29
+ *
30
+ * // File-based database for production
31
+ * const db = new SqliteStateDB({ filename: './data/state.sqlite' });
32
+ * await db.initialize();
33
+ * ```
34
+ */
35
+ constructor(config = { filename: ":memory:" }) {
36
+ super();
37
+ this.initialized = false;
38
+ this.name = name;
39
+ this.version = version;
40
+ this.config = config;
41
+ this.initSync();
42
+ }
43
+ /**
44
+ * Synchronous initialization
45
+ * Called from constructor for immediate table availability
46
+ */
47
+ initSync() {
48
+ this.db = createKysely(this.config);
49
+ this.balance = new balance_default({ db: this.db });
50
+ this.account = new account_default({
51
+ db: this.db,
52
+ syncBalance: true,
53
+ balanceTable: this.balance
54
+ });
55
+ this.factory = new base_default({
56
+ name: "factory",
57
+ uniqIndex: "address",
58
+ db: this.db,
59
+ syncBalance: true,
60
+ balanceTable: this.balance,
61
+ schema: { jsonFields: [
62
+ "trustedIssuers",
63
+ "tokens",
64
+ "input",
65
+ "output",
66
+ "display",
67
+ "hooks",
68
+ "data",
69
+ "context",
70
+ "stake"
71
+ ] }
72
+ });
73
+ this.stake = new base_default({
74
+ name: "stake",
75
+ uniqIndex: "address",
76
+ db: this.db,
77
+ syncBalance: true,
78
+ balanceTable: this.balance,
79
+ schema: {
80
+ jsonFields: [
81
+ "tokens",
82
+ "assets",
83
+ "slashers",
84
+ "revokedTokens",
85
+ "revokedAssets",
86
+ "data",
87
+ "context"
88
+ ],
89
+ booleanFields: ["revocable"]
90
+ }
91
+ });
92
+ this.asset = new base_default({
93
+ name: "asset",
94
+ uniqIndex: "address",
95
+ db: this.db,
96
+ schema: {
97
+ jsonFields: [
98
+ "endpoint",
99
+ "display",
100
+ "tags",
101
+ "stake",
102
+ "data",
103
+ "context"
104
+ ],
105
+ booleanFields: ["readonly", "transferrable"]
106
+ }
107
+ });
108
+ this.delegation = new base_default({
109
+ name: "delegation",
110
+ uniqIndex: "address",
111
+ db: this.db,
112
+ schema: {
113
+ jsonFields: [
114
+ "ops",
115
+ "data",
116
+ "context"
117
+ ],
118
+ columnMapping: {
119
+ from: "from_",
120
+ to: "to_"
121
+ }
122
+ }
123
+ });
124
+ this.tx = new base_default({
125
+ name: "tx",
126
+ uniqIndex: "hash",
127
+ db: this.db,
128
+ schema: {
129
+ jsonFields: [
130
+ "receipts",
131
+ "tx",
132
+ "context"
133
+ ],
134
+ columnMapping: { index: "index_" },
135
+ booleanFields: [
136
+ "receiptsVerified",
137
+ "finalized",
138
+ "valid"
139
+ ]
140
+ }
141
+ });
142
+ this.token = new token_default({ db: this.db });
143
+ this.chain = new base_default({
144
+ name: "chain",
145
+ uniqIndex: "address",
146
+ db: this.db,
147
+ schema: { jsonFields: [
148
+ "accounts",
149
+ "moderator",
150
+ "token",
151
+ "transaction",
152
+ "vaults",
153
+ "context"
154
+ ] }
155
+ });
156
+ this.rollup = new rollup_default({ db: this.db });
157
+ this.rollupBlock = new base_default({
158
+ name: "rollupBlock",
159
+ uniqIndex: "hash",
160
+ db: this.db,
161
+ schema: {
162
+ jsonFields: [
163
+ "txs",
164
+ "signatures",
165
+ "data",
166
+ "context"
167
+ ],
168
+ booleanFields: ["governance"]
169
+ }
170
+ });
171
+ this.evidence = new base_default({
172
+ name: "evidence",
173
+ uniqIndex: "hash",
174
+ db: this.db,
175
+ schema: { jsonFields: ["data", "context"] }
176
+ });
177
+ this.tokenFactory = new base_default({
178
+ name: "tokenFactory",
179
+ uniqIndex: "address",
180
+ db: this.db,
181
+ schema: { jsonFields: [
182
+ "curve",
183
+ "input",
184
+ "output",
185
+ "data",
186
+ "context"
187
+ ] }
188
+ });
189
+ this.attachReadyListeners();
190
+ }
191
+ /**
192
+ * Async initialization - runs migrations
193
+ * Call this after constructor to ensure database schema is ready
194
+ */
195
+ async initialize() {
196
+ if (this.initialized) return;
197
+ await runMigrations(this.db);
198
+ this.initialized = true;
199
+ }
200
+ /**
201
+ * Execute multiple operations within a database transaction
202
+ * Provides retry logic for SQLite BUSY errors (lock conflicts)
203
+ *
204
+ * @param fn - Function receiving Kysely transaction object
205
+ * @param options - Optional retry configuration
206
+ * @returns Result of the transaction function
207
+ *
208
+ * @example
209
+ * ```typescript
210
+ * await db.runAsLambda(async (txn) => {
211
+ * await txn.insertInto('account').values({ ... }).execute();
212
+ * await txn.updateTable('balance').set({ ... }).execute();
213
+ * });
214
+ * ```
215
+ */
216
+ async runAsLambda(fn, options = {}) {
217
+ const { retryLimit = 2 } = options;
218
+ let lastError;
219
+ for (let attempt = 0; attempt <= retryLimit; attempt++) try {
220
+ return await this.db.transaction().execute(async (txn) => {
221
+ return await fn(txn);
222
+ });
223
+ } catch (err) {
224
+ lastError = err;
225
+ const code = err?.code;
226
+ if (!SQLITE_BUSY_CODES.includes(code)) throw err;
227
+ if (attempt < retryLimit) await new Promise((r) => setTimeout(r, 10 * 2 ** attempt));
228
+ }
229
+ throw lastError;
230
+ }
231
+ /**
232
+ * Reset all tables (for testing)
233
+ */
234
+ async reset() {
235
+ const tables = Object.keys(this.readyMarks);
236
+ for (const table of tables) {
237
+ const tableInstance = this[table];
238
+ if (tableInstance?.reset) await tableInstance.reset();
239
+ }
240
+ }
241
+ /**
242
+ * Close database connection
243
+ */
244
+ async close() {
245
+ await this.db.destroy();
246
+ }
247
+ /**
248
+ * Get the underlying Kysely instance (for advanced operations)
249
+ */
250
+ getKysely() {
251
+ return this.db;
252
+ }
253
+ };
254
+ var db_default = SqliteStateDB;
255
+
256
+ //#endregion
257
+ export { db_default as default };
@@ -0,0 +1,4 @@
1
+ import { Database, SqliteOperationContext } from "./interfaces.mjs";
2
+ import { SqliteConfig } from "./kysely.mjs";
3
+ import SqliteStateDB from "./db.mjs";
4
+ export { type Database, type SqliteConfig, type SqliteOperationContext, SqliteStateDB, SqliteStateDB as default };
package/esm/index.mjs ADDED
@@ -0,0 +1,7 @@
1
+ import db_default from "./db.mjs";
2
+
3
+ //#region src/index.ts
4
+ var src_default = db_default;
5
+
6
+ //#endregion
7
+ export { db_default as SqliteStateDB, src_default as default };
@@ -0,0 +1,201 @@
1
+ import { Transaction } from "kysely";
2
+ import { IOperationContext } from "@ocap/types";
3
+
4
+ //#region src/interfaces.d.ts
5
+
6
+ /**
7
+ * SQLite-specific operation context
8
+ * Extends base operation context with optional transaction
9
+ */
10
+ interface SqliteOperationContext extends IOperationContext {
11
+ txn?: Transaction<Database>;
12
+ }
13
+ /**
14
+ * Database schema types for Kysely
15
+ * Each table is defined with its column types
16
+ */
17
+ interface Database {
18
+ account: AccountTable;
19
+ balance: BalanceTable;
20
+ chain: ChainTable;
21
+ tx: TxTable;
22
+ asset: AssetTable;
23
+ token: TokenTable;
24
+ factory: FactoryTable;
25
+ tokenFactory: TokenFactoryTable;
26
+ stake: StakeTable;
27
+ delegation: DelegationTable;
28
+ rollup: RollupTable;
29
+ rollupBlock: RollupBlockTable;
30
+ evidence: EvidenceTable;
31
+ }
32
+ interface AccountTable {
33
+ address: string;
34
+ balance: string;
35
+ gasBalance: string | null;
36
+ moniker: string | null;
37
+ pk: string | null;
38
+ nonce: number;
39
+ numTxs: number;
40
+ numAssets: number;
41
+ issuer: string | null;
42
+ migratedTo: string | null;
43
+ migratedFrom: string | null;
44
+ stake: string | null;
45
+ tokens: string | null;
46
+ data: string | null;
47
+ context: string | null;
48
+ _retrievedAt: string | null;
49
+ }
50
+ interface BalanceTable {
51
+ address: string;
52
+ tokenAddress: string;
53
+ balance: string;
54
+ context: string | null;
55
+ }
56
+ interface ChainTable {
57
+ address: string;
58
+ chainId: string | null;
59
+ version: string | null;
60
+ accounts: string | null;
61
+ moderator: string | null;
62
+ token: string | null;
63
+ transaction: string | null;
64
+ vaults: string | null;
65
+ context: string | null;
66
+ }
67
+ interface TxTable {
68
+ hash: string;
69
+ code: string | null;
70
+ height: number | null;
71
+ index_: number | null;
72
+ receipts: string | null;
73
+ receiptsVerified: number | null;
74
+ receiver: string | null;
75
+ sender: string | null;
76
+ time: string | null;
77
+ tx: string | null;
78
+ type: string | null;
79
+ finalized: number | null;
80
+ valid: number | null;
81
+ }
82
+ interface AssetTable {
83
+ address: string;
84
+ owner: string | null;
85
+ moniker: string | null;
86
+ readonly: number | null;
87
+ transferrable: number | null;
88
+ issuer: string | null;
89
+ parent: string | null;
90
+ ttl: number | null;
91
+ consumedTime: string | null;
92
+ endpoint: string | null;
93
+ display: string | null;
94
+ tags: string | null;
95
+ stake: string | null;
96
+ data: string | null;
97
+ context: string | null;
98
+ }
99
+ interface TokenTable {
100
+ address: string;
101
+ symbol: string | null;
102
+ name: string | null;
103
+ decimal: number | null;
104
+ unit: string | null;
105
+ description: string | null;
106
+ icon: string | null;
107
+ totalSupply: string | null;
108
+ initialSupply: string | null;
109
+ maxTotalSupply: string | null;
110
+ foreignToken: string | null;
111
+ issuer: string | null;
112
+ website: string | null;
113
+ metadata: string | null;
114
+ tokenFactoryAddress: string | null;
115
+ spenders: string | null;
116
+ minters: string | null;
117
+ type: string | null;
118
+ data: string | null;
119
+ context: string | null;
120
+ }
121
+ interface FactoryTable {
122
+ address: string;
123
+ owner: string | null;
124
+ name: string | null;
125
+ description: string | null;
126
+ settlement: string | null;
127
+ limit: number | null;
128
+ trustedIssuers: string | null;
129
+ tokens: string | null;
130
+ numMinted: number | null;
131
+ lastSettlement: string | null;
132
+ input: string | null;
133
+ output: string | null;
134
+ display: string | null;
135
+ hooks: string | null;
136
+ data: string | null;
137
+ context: string | null;
138
+ }
139
+ interface TokenFactoryTable {
140
+ address: string;
141
+ owner: string | null;
142
+ name: string | null;
143
+ description: string | null;
144
+ moniker: string | null;
145
+ status: string | null;
146
+ curve: string | null;
147
+ input: string | null;
148
+ output: string | null;
149
+ data: string | null;
150
+ context: string | null;
151
+ }
152
+ interface StakeTable {
153
+ address: string;
154
+ sender: string | null;
155
+ receiver: string | null;
156
+ tokens: string | null;
157
+ revokedTokens: string | null;
158
+ message: string | null;
159
+ data: string | null;
160
+ context: string | null;
161
+ }
162
+ interface DelegationTable {
163
+ address: string;
164
+ from_: string | null;
165
+ to_: string | null;
166
+ ops: string | null;
167
+ data: string | null;
168
+ context: string | null;
169
+ }
170
+ interface RollupTable {
171
+ address: string;
172
+ tokenAddress: string | null;
173
+ paused: number | null;
174
+ seedValidators: string | null;
175
+ validators: string | null;
176
+ vaultAddress: string | null;
177
+ blockHash: string | null;
178
+ issuer: string | null;
179
+ data: string | null;
180
+ context: string | null;
181
+ }
182
+ interface RollupBlockTable {
183
+ hash: string;
184
+ rollup: string | null;
185
+ height: number | null;
186
+ previousHash: string | null;
187
+ mintedAmount: string | null;
188
+ burnedAmount: string | null;
189
+ rewardAmount: string | null;
190
+ signatures: string | null;
191
+ data: string | null;
192
+ context: string | null;
193
+ }
194
+ interface EvidenceTable {
195
+ hash: string;
196
+ type: string | null;
197
+ data: string | null;
198
+ context: string | null;
199
+ }
200
+ //#endregion
201
+ export { AccountTable, AssetTable, BalanceTable, ChainTable, Database, DelegationTable, EvidenceTable, FactoryTable, RollupBlockTable, RollupTable, SqliteOperationContext, StakeTable, TokenFactoryTable, TokenTable, TxTable };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,43 @@
1
+ import { Database } from "./interfaces.mjs";
2
+ import { Kysely } from "kysely";
3
+
4
+ //#region src/kysely.d.ts
5
+
6
+ /**
7
+ * SQLite configuration options
8
+ */
9
+ interface SqliteConfig {
10
+ /** Database file path. Use ':memory:' for in-memory database */
11
+ filename: string;
12
+ /** Open database in readonly mode */
13
+ readonly?: boolean;
14
+ /** Throw error if file doesn't exist (default: false, creates new file) */
15
+ create?: boolean;
16
+ /** Enable WAL mode (default: true) */
17
+ walMode?: boolean;
18
+ }
19
+ /**
20
+ * Create a Kysely instance with SQLite dialect
21
+ * Automatically uses kysely-bun-sqlite in Bun or better-sqlite3 in Node.js
22
+ *
23
+ * @param config - SQLite configuration
24
+ * @returns Kysely instance configured for the database
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * // In-memory database for testing
29
+ * const db = createKysely({ filename: ':memory:' });
30
+ *
31
+ * // File-based database for production
32
+ * const db = createKysely({ filename: './data/state.sqlite' });
33
+ * ```
34
+ */
35
+ declare function createKysely(config: SqliteConfig): Kysely<Database>;
36
+ /**
37
+ * Get the underlying SQLite database instance from Kysely
38
+ * Useful for executing raw SQL or pragmas
39
+ * Returns either bun:sqlite Database or better-sqlite3 Database depending on runtime
40
+ */
41
+ declare function getRawDatabase(db: Kysely<Database>): any;
42
+ //#endregion
43
+ export { SqliteConfig, createKysely, getRawDatabase };