@storecraft/database-sqlite 1.0.11 → 1.0.13
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/index.js +27 -3
- package/package.json +1 -1
package/index.js
CHANGED
@@ -1,17 +1,29 @@
|
|
1
|
+
/**
|
2
|
+
* @import { Config } from './types.public.js';
|
3
|
+
* @import { ENV } from '@storecraft/core';
|
4
|
+
*/
|
1
5
|
import { SQL } from '@storecraft/database-sql-base';
|
2
6
|
import { SqliteDialect } from 'kysely';
|
3
7
|
import BetterSQLite from 'better-sqlite3';
|
4
8
|
|
5
9
|
|
10
|
+
|
6
11
|
/**
|
7
|
-
* @description `better-sqlite` driver for storecraft
|
12
|
+
* @description `better-sqlite` driver for `storecraft`
|
8
13
|
*
|
9
14
|
*/
|
10
15
|
export class SQLite extends SQL {
|
11
16
|
|
17
|
+
/** @satisfies {ENV<Config>} */
|
18
|
+
static EnvConfig = /** @type{const} */ (
|
19
|
+
{
|
20
|
+
filepath: 'SQLITE_FILEPATH',
|
21
|
+
}
|
22
|
+
);
|
23
|
+
|
12
24
|
/**
|
13
25
|
*
|
14
|
-
* @param {
|
26
|
+
* @param {Config} [config] config
|
15
27
|
*/
|
16
28
|
constructor(config={ filepath: 'database.db' }) {
|
17
29
|
super(
|
@@ -19,12 +31,24 @@ export class SQLite extends SQL {
|
|
19
31
|
dialect_type: 'SQLITE',
|
20
32
|
dialect: new SqliteDialect(
|
21
33
|
{
|
22
|
-
database: async () => new BetterSQLite(
|
34
|
+
database: async () => new BetterSQLite(
|
35
|
+
config.filepath, config.options
|
36
|
+
)
|
23
37
|
}
|
24
38
|
),
|
25
39
|
}
|
26
40
|
);
|
27
41
|
|
42
|
+
// a bit hacky
|
43
|
+
this.dialect_config = config;
|
44
|
+
}
|
45
|
+
|
46
|
+
|
47
|
+
/** @type {SQL["init"]} */
|
48
|
+
init = (app) => {
|
49
|
+
this.dialect_config.filepath ??= app.platform.env[SQLite.EnvConfig.filepath];
|
50
|
+
super.init(app);
|
28
51
|
}
|
29
52
|
|
30
53
|
}
|
54
|
+
|