init
This commit is contained in:
19
lib/db/index.ts
Normal file
19
lib/db/index.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { drizzle } from "drizzle-orm/mysql2";
|
||||
import mysql from "mysql2/promise";
|
||||
import * as schema from "./schema";
|
||||
|
||||
const globalForDb = globalThis as unknown as {
|
||||
connection: mysql.Pool | undefined;
|
||||
};
|
||||
|
||||
const connection =
|
||||
globalForDb.connection ??
|
||||
mysql.createPool({
|
||||
uri: process.env.DATABASE_URL!,
|
||||
waitForConnections: true,
|
||||
connectionLimit: 10,
|
||||
});
|
||||
|
||||
if (process.env.NODE_ENV !== "production") globalForDb.connection = connection;
|
||||
|
||||
export const db = drizzle(connection, { schema, mode: "default" });
|
||||
Reference in New Issue
Block a user