import { MongoClient, type Db } from "mongodb"; const uri = process.env.MONGODB_URI ?? "mongodb://localhost:27017"; const dbName = process.env.MONGODB_DB ?? "knur"; declare global { var _mongoClientPromise: Promise | undefined; } function getClientPromise(): Promise { if (!global._mongoClientPromise) { const client = new MongoClient(uri); global._mongoClientPromise = client.connect(); } return global._mongoClientPromise; } export async function getDb(): Promise { const client = await getClientPromise(); return client.db(dbName); }