@easy-cms/drizzle 0.8.0 → 0.9.0
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 -2
- package/dist/index.js +25 -4
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -58,8 +58,11 @@ interface Dialect {
|
|
|
58
58
|
* (any element when it returns undefined). Anything but an array has no elements.
|
|
59
59
|
*/
|
|
60
60
|
someElement(array: AnyColumn | SQL, condition: (el: JsonElement) => SQL | undefined): SQL;
|
|
61
|
-
/**
|
|
62
|
-
|
|
61
|
+
/**
|
|
62
|
+
* For sorting: the value at `path` in the first element that has one, stepping through the
|
|
63
|
+
* nested `lists` in each element (in order) like `someElement`.
|
|
64
|
+
*/
|
|
65
|
+
firstElementValue(array: AnyColumn | SQL, lists: readonly (readonly string[])[], path: readonly string[], type: JsonValueType): SQL;
|
|
63
66
|
/** Placeholder for the n-th parameter (1-based) in raw SQL. */
|
|
64
67
|
param(n: number): string;
|
|
65
68
|
/** CREATE TABLE IF NOT EXISTS for the migrations table. */
|
package/dist/index.js
CHANGED
|
@@ -968,11 +968,12 @@ var WhereBuilder = class {
|
|
|
968
968
|
}
|
|
969
969
|
return subquery(this.build(table, { [rest.join(".")]: { [op]: value } }));
|
|
970
970
|
}
|
|
971
|
-
/** A column, or the value in the
|
|
971
|
+
/** A column, or the first value in blocks (and the lists in them, in order) that has it. */
|
|
972
972
|
sortValue(target, path) {
|
|
973
973
|
if (target.kind === "column") return target.column;
|
|
974
|
-
if (target.kind === "blocks" && target.value.
|
|
975
|
-
|
|
974
|
+
if (target.kind === "blocks" && target.value.path) {
|
|
975
|
+
const { lists, path: inner, type } = target.value;
|
|
976
|
+
return this.dialect.firstElementValue(target.column, lists, inner, type);
|
|
976
977
|
}
|
|
977
978
|
throw new QueryError(`Cannot sort by "${path}"`);
|
|
978
979
|
}
|
|
@@ -1087,7 +1088,7 @@ var DrizzleDatabase = class {
|
|
|
1087
1088
|
/** Runs a write; with a single-writer database, after the writes before it are done. */
|
|
1088
1089
|
write(run) {
|
|
1089
1090
|
if (!this.dialect.singleWriter) return run();
|
|
1090
|
-
const result = this.writing.then(run);
|
|
1091
|
+
const result = this.writing.then(() => retryWhileBusy(run));
|
|
1091
1092
|
this.writing = result.catch(() => {
|
|
1092
1093
|
});
|
|
1093
1094
|
return result;
|
|
@@ -1153,6 +1154,26 @@ var DrizzleDatabase = class {
|
|
|
1153
1154
|
await this.connection.close();
|
|
1154
1155
|
}
|
|
1155
1156
|
};
|
|
1157
|
+
var BUSY_TIMEOUT = 1e4;
|
|
1158
|
+
async function retryWhileBusy(run) {
|
|
1159
|
+
const until = Date.now() + BUSY_TIMEOUT;
|
|
1160
|
+
for (let delay = 5; ; delay = Math.min(delay * 2, 250)) {
|
|
1161
|
+
try {
|
|
1162
|
+
return await run();
|
|
1163
|
+
} catch (error) {
|
|
1164
|
+
if (!isBusy(error) || Date.now() + delay > until) throw error;
|
|
1165
|
+
await new Promise((resolve2) => setTimeout(resolve2, delay + Math.random() * delay));
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
function isBusy(error) {
|
|
1170
|
+
for (let e = error; e; e = e.cause) {
|
|
1171
|
+
const code = e.code;
|
|
1172
|
+
if (typeof code === "string" && code.startsWith("SQLITE_BUSY")) return true;
|
|
1173
|
+
if (e === e.cause) break;
|
|
1174
|
+
}
|
|
1175
|
+
return false;
|
|
1176
|
+
}
|
|
1156
1177
|
export {
|
|
1157
1178
|
DEFAULT_MIGRATION_DIR,
|
|
1158
1179
|
DEFAULT_TABLE_PREFIX,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easy-cms/drizzle",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Shared Drizzle ORM layer for Easy CMS database adapters",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
"drizzle-orm": "0.45.3"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@easy-cms/core": "^0.
|
|
26
|
+
"@easy-cms/core": "^0.9.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@easy-cms/core": "^0.
|
|
29
|
+
"@easy-cms/core": "^0.9.0"
|
|
30
30
|
},
|
|
31
31
|
"publishConfig": {
|
|
32
32
|
"access": "public"
|