18 lines
486 B
TypeScript
18 lines
486 B
TypeScript
import { drizzle } from "drizzle-orm/postgres-js";
|
|
import postgres from "postgres";
|
|
import { env } from "../lib/env.ts";
|
|
import * as schema from "./schema/index.ts";
|
|
|
|
const url = new URL(env.DATABASE_URL);
|
|
const socketHost = url.searchParams.get("host");
|
|
|
|
const client = postgres({
|
|
host: socketHost ?? url.hostname,
|
|
port: Number(url.port) || 5432,
|
|
database: url.pathname.slice(1),
|
|
username: url.username,
|
|
password: url.password,
|
|
});
|
|
|
|
export const db = drizzle(client, { schema });
|