Is this a bad pattern to do? I wanna call my local postgre while developing and use neon in prod.

import { drizzle as drizzleNeon } from "drizzle-orm/neon-http";
import { drizzle as drizzlePostgres } from "drizzle-orm/postgres-js";

import { neon } from "@neondatabase/serverless";
import { config } from "dotenv";
import postgres from "postgres";
import { isProd } from "@/lib/utils";
config({ path: ".env" });

// Dev
const queryClient = postgres(process.env.DEV_DATABASE_URL!);
// Prod
const sql = neon(process.env.PROD_DATABASE_URL!);

export const db = isProd() ? drizzleNeon(sql) : drizzlePostgres(queryClient);
import { drizzle as drizzleNeon } from "drizzle-orm/neon-http";
import { drizzle as drizzlePostgres } from "drizzle-orm/postgres-js";

import { neon } from "@neondatabase/serverless";
import { config } from "dotenv";
import postgres from "postgres";
import { isProd } from "@/lib/utils";
config({ path: ".env" });

// Dev
const queryClient = postgres(process.env.DEV_DATABASE_URL!);
// Prod
const sql = neon(process.env.PROD_DATABASE_URL!);

export const db = isProd() ? drizzleNeon(sql) : drizzlePostgres(queryClient);
Has anyone tried something like this?
3 Replies
regex
regexOP6mo ago
or this doesn't make sense?
Budi
Budi2mo ago
Curious about the same. Have you figured out how to get this to work?
oke
oke2mo ago
I think this is no problem This might even be better to avoid any potential side effect of initiating a client without using
let db;
if (!isProd()) {
const queryClient = postgres(process.env.DEV_DATABASE_URL!);
db = drizzlePostgres(queryClient);
} else {
const sql = neon(process.env.PROD_DATABASE_URL!);
db = drizzleNeon(sql)
}


export db;
let db;
if (!isProd()) {
const queryClient = postgres(process.env.DEV_DATABASE_URL!);
db = drizzlePostgres(queryClient);
} else {
const sql = neon(process.env.PROD_DATABASE_URL!);
db = drizzleNeon(sql)
}


export db;
Want results from more Discord servers?
Add your server