abac9dfe6c
- Add source code from apps/api - Add packages/db and packages/types workspace dependencies - Add GitHub Actions CI workflow (lint, typecheck, test, docker) - Generate pnpm-lock.yaml - Add .gitignore Co-Authored-By: Paperclip <noreply@paperclip.ing>
21 lines
666 B
TypeScript
21 lines
666 B
TypeScript
import { drizzle } from "drizzle-orm/postgres-js";
|
|
import postgres from "postgres";
|
|
import * as schema from "./schema.js";
|
|
|
|
export * from "./schema.js";
|
|
export { encryptSecret, decryptSecret } from "./crypto.js";
|
|
export { and, asc, desc, eq, exists, gte, gt, ilike, inArray, isNull, lt, lte, ne, or, sql } from "drizzle-orm";
|
|
|
|
let _db: ReturnType<typeof drizzle> | null = null;
|
|
|
|
export function getDb() {
|
|
if (_db) return _db;
|
|
const url = process.env.DATABASE_URL;
|
|
if (!url) throw new Error("DATABASE_URL is not set");
|
|
const client = postgres(url, { max: 10 });
|
|
_db = drizzle(client, { schema });
|
|
return _db;
|
|
}
|
|
|
|
export type Db = ReturnType<typeof getDb>;
|