set up vercel db connection
This commit is contained in:
@@ -1,18 +1,24 @@
|
||||
import { drizzle } from "drizzle-orm/postgres-js";
|
||||
import postgres from "postgres";
|
||||
import { drizzle } from "drizzle-orm/neon-serverless";
|
||||
import { Pool, neonConfig } from "@neondatabase/serverless";
|
||||
|
||||
import { env } from "~/env";
|
||||
import * as schema from "./schema";
|
||||
|
||||
/**
|
||||
* Cache the database connection in development. This avoids creating a new connection on every HMR
|
||||
* update.
|
||||
*/
|
||||
const globalForDb = globalThis as unknown as {
|
||||
conn: postgres.Sql | undefined;
|
||||
};
|
||||
if (env.NODE_ENV !== "production") {
|
||||
// Set the WebSocket proxy to work with the local instance
|
||||
neonConfig.wsProxy = (host) => `${host}:5433/v1`;
|
||||
|
||||
const conn = globalForDb.conn ?? postgres(env.DATABASE_URL);
|
||||
if (env.NODE_ENV !== "production") globalForDb.conn = conn;
|
||||
// Disable all authentication and encryption
|
||||
neonConfig.useSecureWebSocket = false;
|
||||
neonConfig.pipelineTLS = false;
|
||||
neonConfig.pipelineConnect = false;
|
||||
}
|
||||
|
||||
export const db = drizzle(conn, { schema });
|
||||
const pool = new Pool({
|
||||
connectionString: env.DATABASE_URL,
|
||||
});
|
||||
|
||||
export const db = drizzle(pool, {
|
||||
schema,
|
||||
logger: true,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user