Is this the correct way using Drizzle with Next.js?
Unanswered
Common paper wasp posted this in #help-forum
Common paper waspOP
Im planning to deploy my application on vercel, and I'm not tech savy on edge and stuff so I wonder is this the correct way to connect to db and handle some data?
My
This is how I use
So is this fine for the cold start and all those
My
db.ts
file:import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";
import * as schema from "./schema";
import "dotenv/config";
const getEnvVariable = (name: string) => {
const value = process.env[name];
if (value == null) throw new Error(`Environment variable ${name} not found`);
return value;
};
export const client = postgres(getEnvVariable("DATABASE_URL"));
export const db = drizzle(client, { schema });
This is how I use
db
:import { db } from "@/lib/db";
import { usersTable } from "@/lib/schema";
export const dynamic = "force-dynamic"; // defaults to auto
export async function GET() {
const users = await db.select().from(usersTable);
return Response.json(users);
}
So is this fine for the cold start and all those
serverless edge
jazz?