mirror of
https://github.com/Lapikud/tipilan.git
synced 2026-09-22 15:22:59 +00:00
Migrate to proxy, remome syslink
This commit is contained in:
@@ -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<PropertyKey, unknown>;
|
||||
const value = Reflect.get(instance, property, receiver);
|
||||
|
||||
if (typeof value === "function") {
|
||||
return value.bind(instance);
|
||||
}
|
||||
|
||||
return value;
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user