MCPcopy
hub / github.com/cita-777/metapi / upsertSetting

Function upsertSetting

src/server/db/upsertSetting.ts:11–41  ·  view source on GitHub ↗
(key: string, value: unknown, txDb: typeof db = db)

Source from the content-addressed store, hash-verified

9 * dialect, so we branch at runtime.
10 */
11export async function upsertSetting(key: string, value: unknown, txDb: typeof db = db): Promise<void> {
12 const jsonValue = JSON.stringify(value);
13
14 if (runtimeDbDialect === 'mysql') {
15 // MySQL path – try update first, insert if not exists
16 const existing = await txDb.select({ key: schema.settings.key })
17 .from(schema.settings)
18 .where(eq(schema.settings.key, key))
19 .get();
20
21 if (existing) {
22 await txDb.update(schema.settings)
23 .set({ value: jsonValue })
24 .where(eq(schema.settings.key, key))
25 .run();
26 } else {
27 await txDb.insert(schema.settings)
28 .values({ key, value: jsonValue })
29 .run();
30 }
31 } else {
32 // SQLite / PostgreSQL path
33 await (txDb.insert(schema.settings)
34 .values({ key, value: jsonValue }) as any)
35 .onConflictDoUpdate({
36 target: schema.settings.key,
37 set: { value: jsonValue },
38 })
39 .run();
40 }
41}

Callers 11

settingsRoutesFunction · 0.85
checkinRoutesFunction · 0.85
monitorRoutesFunction · 0.85
writeBackupWebdavStateFunction · 0.85
importPreferencesSectionFunction · 0.85
saveBackupWebdavConfigFunction · 0.85
saveUpdateCenterConfigFunction · 0.85
writeSeedMarkerFunction · 0.85

Calls 1

getMethod · 0.65

Tested by

no test coverage detected