diff --git a/src/lib/db/setting-store.ts b/src/lib/db/setting-store.ts index d73c088cd5..f2f5856999 100644 --- a/src/lib/db/setting-store.ts +++ b/src/lib/db/setting-store.ts @@ -32,10 +32,6 @@ export default class SettingStore implements ISettingStore { }); } - async insertNewRow(name: string, content: any) { - return this.db(TABLE).insert({ name, content }); - } - async exists(name: string): Promise { const result = await this.db.raw( `SELECT EXISTS (SELECT 1 FROM ${TABLE} WHERE name = ?) AS present`, @@ -58,13 +54,12 @@ export default class SettingStore implements ISettingStore { return undefined; } + // Is actually an upsert async insert(name: string, content: any): Promise { - const exists = await this.exists(name); - if (exists) { - await this.updateRow(name, content); - } else { - await this.insertNewRow(name, content); - } + await this.db(TABLE) + .insert({ name, content }) + .onConflict('name') + .merge(); } async delete(name: string): Promise {