@easy-cms/db-sqlite 0.8.0 → 0.9.1
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/dist/index.d.ts +5 -0
- package/dist/index.js +25 -6
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,11 @@ interface SQLiteAdapterOptions extends DrizzleAdapterOptions {
|
|
|
7
7
|
readonly url: string;
|
|
8
8
|
/** Auth token for Turso / remote libSQL. */
|
|
9
9
|
readonly authToken?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Local files: how long (ms) a write waits while another process (a second server, the CLI)
|
|
12
|
+
* is writing to the same file. Default 10000.
|
|
13
|
+
*/
|
|
14
|
+
readonly busyTimeout?: number;
|
|
10
15
|
}
|
|
11
16
|
declare const sqliteDialect: Dialect;
|
|
12
17
|
/** SQLite / libSQL database adapter. */
|
package/dist/index.js
CHANGED
|
@@ -38,10 +38,24 @@ var sqliteDialect = {
|
|
|
38
38
|
});
|
|
39
39
|
return sql`exists (select 1 from json_each(${onlyArray(array)}) as ${el}${where ? sql` where ${where}` : sql``})`;
|
|
40
40
|
},
|
|
41
|
-
firstElementValue: (array, path) => {
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
|
|
41
|
+
firstElementValue: (array, lists, path) => {
|
|
42
|
+
const els = [alias()];
|
|
43
|
+
const from = [sql`json_each(${onlyArray(array)}) as ${els[0]}`];
|
|
44
|
+
for (const list of lists) {
|
|
45
|
+
const outer = els.at(-1);
|
|
46
|
+
const el = alias();
|
|
47
|
+
els.push(el);
|
|
48
|
+
from.push(
|
|
49
|
+
sql`json_each(${onlyArray(sql`json_extract(${outer}.value, ${jsonPath(list)})`)}) as ${el}`
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
const last = els.at(-1);
|
|
53
|
+
const value = path.length === 0 ? sql`${last}.value` : sql`json_extract(${last}.value, ${jsonPath(path)})`;
|
|
54
|
+
const order = sql.join(
|
|
55
|
+
els.map((el) => sql`${el}.key`),
|
|
56
|
+
sql`, `
|
|
57
|
+
);
|
|
58
|
+
return sql`(select ${value} from ${sql.join(from, sql`, `)} where ${value} is not null order by ${order} limit 1)`;
|
|
45
59
|
},
|
|
46
60
|
param: () => "?",
|
|
47
61
|
migrationsTableSQL: (name) => `CREATE TABLE IF NOT EXISTS \`${name}\` (
|
|
@@ -59,14 +73,19 @@ function sqlite(options) {
|
|
|
59
73
|
return {
|
|
60
74
|
name: "sqlite",
|
|
61
75
|
init: async (args) => {
|
|
76
|
+
const url = resolveUrl(options.url, args.cwd);
|
|
62
77
|
const client = createClient({
|
|
63
|
-
url
|
|
64
|
-
...options.authToken ? { authToken: options.authToken } : {}
|
|
78
|
+
url,
|
|
79
|
+
...options.authToken ? { authToken: options.authToken } : {},
|
|
80
|
+
// SQLite has one writer. Writes in this process share a queue (`writeQueue`); this waits
|
|
81
|
+
// for other processes. Its wait blocks the process, but only for another's short write.
|
|
82
|
+
timeout: options.busyTimeout ?? 1e4
|
|
65
83
|
});
|
|
66
84
|
if (options.url.startsWith("file:")) await client.execute("PRAGMA journal_mode = WAL");
|
|
67
85
|
const toStatement = (s) => ({ sql: s.sql, args: [...s.params ?? []] });
|
|
68
86
|
const connection = {
|
|
69
87
|
db: drizzle(client),
|
|
88
|
+
writeQueue: url,
|
|
70
89
|
runner: {
|
|
71
90
|
async query(text2, params = []) {
|
|
72
91
|
const result = await client.execute({ sql: text2, args: [...params] });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easy-cms/db-sqlite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "SQLite / libSQL database adapter for Easy CMS",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -22,14 +22,14 @@
|
|
|
22
22
|
"@libsql/client": "^0.18.0",
|
|
23
23
|
"drizzle-kit": "0.31.11",
|
|
24
24
|
"drizzle-orm": "0.45.3",
|
|
25
|
-
"@easy-cms/drizzle": "^0.
|
|
25
|
+
"@easy-cms/drizzle": "^0.9.1"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@easy-cms/core": "^0.
|
|
28
|
+
"@easy-cms/core": "^0.9.1"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"sharp": "^0.35.4",
|
|
32
|
-
"@easy-cms/core": "^0.
|
|
32
|
+
"@easy-cms/core": "^0.9.1"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public"
|