ework-web 0.10.22 → 0.10.23
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/package.json +1 -1
- package/src/db.ts +31 -11
package/package.json
CHANGED
package/src/db.ts
CHANGED
|
@@ -375,7 +375,8 @@ class MysqlDriver implements AsyncDatabase {
|
|
|
375
375
|
try {
|
|
376
376
|
await pool.query(stmt);
|
|
377
377
|
} catch (e) {
|
|
378
|
-
|
|
378
|
+
const errno = (e as { errno?: number }).errno;
|
|
379
|
+
if (errno === 1061 || errno === 30000) continue;
|
|
379
380
|
throw e;
|
|
380
381
|
}
|
|
381
382
|
}
|
|
@@ -456,10 +457,17 @@ export function getDB(): AsyncDatabase {
|
|
|
456
457
|
export async function getConfigAll(): Promise<Record<string, string>> {
|
|
457
458
|
try {
|
|
458
459
|
const driver = getDB();
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
460
|
+
try {
|
|
461
|
+
const rows = await driver.all<{ akey: string; value: string }>("SELECT akey, value FROM {{config}}");
|
|
462
|
+
const out: Record<string, string> = {};
|
|
463
|
+
for (const r of rows) out[r.akey] = r.value;
|
|
464
|
+
return out;
|
|
465
|
+
} catch {
|
|
466
|
+
const rows = await driver.all<{ key: string; value: string }>("SELECT key, value FROM {{config}}");
|
|
467
|
+
const out: Record<string, string> = {};
|
|
468
|
+
for (const r of rows) out[r.key] = r.value;
|
|
469
|
+
return out;
|
|
470
|
+
}
|
|
463
471
|
} catch {
|
|
464
472
|
return {};
|
|
465
473
|
}
|
|
@@ -467,13 +475,25 @@ export async function getConfigAll(): Promise<Record<string, string>> {
|
|
|
467
475
|
|
|
468
476
|
export async function setConfig(key: string, value: string): Promise<void> {
|
|
469
477
|
const now = new Date().toISOString();
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
"
|
|
473
|
-
|
|
474
|
-
|
|
478
|
+
try {
|
|
479
|
+
await getDB().run(
|
|
480
|
+
"INSERT INTO {{config}} (akey, value, updated_at) VALUES (?, ?, ?) " +
|
|
481
|
+
"ON CONFLICT(akey) DO UPDATE SET value = excluded.value, updated_at = excluded.updated_at",
|
|
482
|
+
[key, value, now]
|
|
483
|
+
);
|
|
484
|
+
} catch {
|
|
485
|
+
await getDB().run(
|
|
486
|
+
"INSERT INTO {{config}} (key, value, updated_at) VALUES (?, ?, ?) " +
|
|
487
|
+
"ON CONFLICT(key) DO UPDATE SET value = excluded.value, updated_at = excluded.updated_at",
|
|
488
|
+
[key, value, now]
|
|
489
|
+
);
|
|
490
|
+
}
|
|
475
491
|
}
|
|
476
492
|
|
|
477
493
|
export async function deleteConfig(key: string): Promise<void> {
|
|
478
|
-
|
|
494
|
+
try {
|
|
495
|
+
await getDB().run("DELETE FROM {{config}} WHERE akey = ?", [key]);
|
|
496
|
+
} catch {
|
|
497
|
+
await getDB().run("DELETE FROM {{config}} WHERE key = ?", [key]);
|
|
498
|
+
}
|
|
479
499
|
}
|