mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor(server): split logic in to packages
This commit is contained in:
28
packages/builders/src/db/index.ts
Normal file
28
packages/builders/src/db/index.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { type PostgresJsDatabase, drizzle } from "drizzle-orm/postgres-js";
|
||||
import postgres from "postgres";
|
||||
// import { sc } from "@dokploy/schema";
|
||||
import * as schema from "./schema";
|
||||
// schema
|
||||
// import * as schema from "@dokploy/schema";
|
||||
|
||||
// type Schema = typeof schema;
|
||||
|
||||
// type Schema = typeof schema;
|
||||
declare global {
|
||||
// eslint-disable-next-line no-var -- only var works here
|
||||
var db: PostgresJsDatabase<typeof schema> | undefined;
|
||||
}
|
||||
|
||||
export let db: PostgresJsDatabase<typeof schema>;
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
db = drizzle(postgres(process.env.DATABASE_URL || ""), {
|
||||
schema,
|
||||
});
|
||||
} else {
|
||||
if (!global.db)
|
||||
global.db = drizzle(postgres(process.env.DATABASE_URL || ""), {
|
||||
schema,
|
||||
});
|
||||
|
||||
db = global.db;
|
||||
}
|
||||
Reference in New Issue
Block a user