Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

859 B
Raw Blame
/**
 * ui_prefs table repo (UI preferences): free-form JSON storage.
 */
import { Component, Use } from "@adelie/core/kernel";
import type { Db } from "../../hmr/capabilities.js";
import type { UiPrefsStore } from "../../mechanisms/settings.js";

@Component()
export class UiPrefsRepo implements UiPrefsStore {
  @Use() private readonly db!: Db;

  /** Returns the raw JSON string; null if never set. */
  get(userId: string): string | null {
    const r = this.db.prepare("SELECT prefs_json FROM ui_prefs WHERE user_id = ?").get(userId);
    return r ? (r.prefs_json as string) : null;
  }

  set(userId: string, prefsJson: string): void {
    this.db
      .prepare(
        `INSERT INTO ui_prefs (user_id, prefs_json) VALUES (?, ?)
         ON CONFLICT(user_id) DO UPDATE SET prefs_json = excluded.prefs_json`,
      )
      .run(userId, prefsJson);
  }
}