From ff698cd1a150a4a208f82ac4d2276085fce54d9e Mon Sep 17 00:00:00 2001 From: v4ltages Date: Wed, 12 Aug 2026 18:11:49 +0300 Subject: [PATCH] Migrate to proxy, remome syslink --- .github/workflows/build.yml | 5 ----- .nvmrc | 2 +- src/db/drizzle.ts | 25 +++++++++++++++++++++++-- src/{middleware.ts => proxy.ts} | 2 +- 4 files changed, 25 insertions(+), 9 deletions(-) rename src/{middleware.ts => proxy.ts} (94%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index eeabfc4..f6c24b2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,10 +26,5 @@ jobs: - name: Install dependencies run: bun install - - name: Ensure symlink to database before Drizzle migrations - run: | - rm -rf $GITHUB_WORKSPACE/data - ln -s ~/data $GITHUB_WORKSPACE/data - - name: Build project run: bun --bun run build diff --git a/.nvmrc b/.nvmrc index 2bd5a0a..7c974b0 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -22 +24.1.0 diff --git a/src/db/drizzle.ts b/src/db/drizzle.ts index 462bf11..c4f309e 100644 --- a/src/db/drizzle.ts +++ b/src/db/drizzle.ts @@ -2,5 +2,26 @@ import { drizzle } from "drizzle-orm/bun-sqlite"; import { Database } from "bun:sqlite"; import * as schema from "./schema/schema"; -const sqlite = new Database("data/tipilan.db"); -export const db = drizzle(sqlite, { schema }); +let database: any = null; + +function getDatabase() { + if (!database) { + const sqlite = new Database("data/tipilan.db"); + database = drizzle(sqlite, { schema }); + } + + return database; +} + +export const db: any = new Proxy({}, { + get(_target, property, receiver) { + const instance = getDatabase() as unknown as Record; + const value = Reflect.get(instance, property, receiver); + + if (typeof value === "function") { + return value.bind(instance); + } + + return value; + }, +}); diff --git a/src/middleware.ts b/src/proxy.ts similarity index 94% rename from src/middleware.ts rename to src/proxy.ts index 5c44442..d93f4f0 100644 --- a/src/middleware.ts +++ b/src/proxy.ts @@ -4,7 +4,7 @@ import { routing } from "./i18n/routing"; const handleI18nRouting = createMiddleware(routing); -export default function middleware(request: NextRequest) { +export default function proxy(request: NextRequest) { const response = handleI18nRouting(request); const location = response.headers.get("location");