website/src/lib/server/db.ts

14 lines
302 B
TypeScript
Raw Normal View History

2023-01-07 00:53:14 +05:30
import { env } from "$env/dynamic/private";
import { building } from "$app/environment";
2023-01-10 19:43:53 +05:30
import { MongoClient } from "mongodb";
import type { Db } from "mongodb";
2023-01-07 00:53:14 +05:30
2023-01-10 19:43:53 +05:30
export let db: Db;
2023-01-07 00:53:14 +05:30
if (!building) {
2023-01-10 19:43:53 +05:30
const client = new MongoClient(env.DB_URL);
2023-01-07 00:53:14 +05:30
2023-01-10 19:43:53 +05:30
await client.connect();
db = client.db("website");
2023-01-07 00:53:14 +05:30
}