-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathSqliteOptions.ts
More file actions
93 lines (82 loc) · 2.45 KB
/
SqliteOptions.ts
File metadata and controls
93 lines (82 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
export interface SqliteOptions {
/**
* SQLite journal mode. Defaults to [SqliteJournalMode.wal].
*/
journalMode?: SqliteJournalMode;
/**
* SQLite synchronous flag. Defaults to [SqliteSynchronous.normal], which
* is safe for WAL mode.
*/
synchronous?: SqliteSynchronous;
/**
* Journal/WAL size limit. Defaults to 6MB.
* The WAL may grow larger than this limit during writes, but SQLite will
* attempt to truncate the file afterwards.
*/
journalSizeLimit?: number;
/**
* Timeout in milliseconds waiting for locks to be released by other connections.
* Defaults to 30 seconds.
* Set to null or zero to fail immediately when the database is locked.
*/
lockTimeoutMs?: number;
/**
* Encryption key for the database.
* If set, the database will be encrypted using SQLCipher.
*/
encryptionKey?: string | null;
/**
* Where to store SQLite temporary files. Defaults to 'MEMORY'.
* Setting this to `FILESYSTEM` can cause issues with larger queries or datasets.
*
* For details, see: https://www.sqlite.org/pragma.html#pragma_temp_store
*/
temporaryStorage?: TemporaryStorageOption;
/**
* Maximum SQLite cache size. Defaults to 50MB.
*
* For details, see: https://www.sqlite.org/pragma.html#pragma_cache_size
*/
cacheSizeKb?: number;
/**
* Load extensions using the path and entryPoint.
* More info can be found here https://op-engineering.github.io/op-sqlite/docs/api#loading-extensions.
*/
extensions?: Array<{
path: string;
entryPoint?: string;
}>;
}
export enum TemporaryStorageOption {
MEMORY = 'memory',
FILESYSTEM = 'file'
}
// SQLite journal mode. Set on the primary connection.
// This library is written with WAL mode in mind - other modes may cause
// unexpected locking behavior.
enum SqliteJournalMode {
// Use a write-ahead log instead of a rollback journal.
// This provides good performance and concurrency.
wal = 'WAL',
delete = 'DELETE',
truncate = 'TRUNCATE',
persist = 'PERSIST',
memory = 'MEMORY',
off = 'OFF'
}
// SQLite file commit mode.
enum SqliteSynchronous {
normal = 'NORMAL',
full = 'FULL',
off = 'OFF'
}
export const DEFAULT_SQLITE_OPTIONS: Required<SqliteOptions> = {
journalMode: SqliteJournalMode.wal,
synchronous: SqliteSynchronous.normal,
journalSizeLimit: 6 * 1024 * 1024,
cacheSizeKb: 50 * 1024,
temporaryStorage: TemporaryStorageOption.MEMORY,
lockTimeoutMs: 30000,
encryptionKey: null,
extensions: []
};