Files
sofa/lib/services/settings.ts
T
jakeandClaude Opus 4.6 d9b408128b Remove unnecessary await/async from sync bun:sqlite db calls
drizzle-orm/bun-sqlite is fully synchronous — all queries return values
directly, not promises. Remove await from all db calls, drop async from
functions that no longer need it, simplify Promise.all patterns that
wrapped sync operations, and fix setSetting() which was missing .run()
(previously masked by await triggering execution via thenable).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 19:04:40 -05:00

33 lines
865 B
TypeScript

import { count, eq } from "drizzle-orm";
import { db } from "@/lib/db/client";
import { appSettings, user } from "@/lib/db/schema";
export function getSetting(key: string): string | null {
const row = db
.select()
.from(appSettings)
.where(eq(appSettings.key, key))
.get();
return row?.value ?? null;
}
export function setSetting(key: string, value: string): void {
db.insert(appSettings)
.values({ key, value })
.onConflictDoUpdate({ target: appSettings.key, set: { value } })
.run();
}
export function getUserCount(): number {
const result = db.select({ count: count() }).from(user).get();
return result?.count ?? 0;
}
export function isRegistrationOpen(): boolean {
const userCount = getUserCount();
if (userCount === 0) return true;
const setting = getSetting("registrationOpen");
return setting === "true";
}