Rewritten to use drizzle instead of prisma

commit c0894548dac5133bd89da5b68684443748fa2559
Author: fuomag9 <1580624+fuomag9@users.noreply.github.com>
Date:   Fri Nov 7 18:38:30 2025 +0100

    Update config.ts

commit 5a4f1159d2123ada0f698a10011c24720bf6ea6f
Author: fuomag9 <1580624+fuomag9@users.noreply.github.com>
Date:   Fri Nov 7 15:58:13 2025 +0100

    first drizzle rewrite
This commit is contained in:
fuomag9
2025-11-07 19:26:32 +01:00
parent 20a72008ac
commit 3be4e1bf7d
27 changed files with 3258 additions and 1148 deletions

View File

@@ -1,4 +1,6 @@
import prisma, { nowIso } from "./db";
import db, { nowIso } from "./db";
import { settings } from "./db/schema";
import { eq } from "drizzle-orm";
export type SettingValue<T> = T | null;
@@ -14,8 +16,8 @@ export type GeneralSettings = {
};
export async function getSetting<T>(key: string): Promise<SettingValue<T>> {
const setting = await prisma.setting.findUnique({
where: { key }
const setting = await db.query.settings.findFirst({
where: (table, { eq }) => eq(table.key, key)
});
if (!setting) {
@@ -32,20 +34,22 @@ export async function getSetting<T>(key: string): Promise<SettingValue<T>> {
export async function setSetting<T>(key: string, value: T): Promise<void> {
const payload = JSON.stringify(value);
const now = new Date(nowIso());
const now = nowIso();
await prisma.setting.upsert({
where: { key },
update: {
value: payload,
updatedAt: now
},
create: {
await db
.insert(settings)
.values({
key,
value: payload,
updatedAt: now
}
});
})
.onConflictDoUpdate({
target: settings.key,
set: {
value: payload,
updatedAt: now
}
});
}
export async function getCloudflareSettings(): Promise<CloudflareSettings | null> {