CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
Blame · Line-by-line history
index.ts
Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.
| fc1817a | 1 | import { neon } from "@neondatabase/serverless"; |
| 2 | import { drizzle, type NeonHttpDatabase } from "drizzle-orm/neon-http"; | |
| 3 | import * as schema from "./schema"; | |
| 4 | import { config } from "../lib/config"; | |
| 5 | ||
| 6 | let _db: NeonHttpDatabase<typeof schema> | null = null; | |
| 7 | ||
| 8 | export function getDb(): NeonHttpDatabase<typeof schema> { | |
| 9 | if (!_db) { | |
| 10 | if (!config.databaseUrl) { | |
| 11 | throw new Error( | |
| 12 | "DATABASE_URL is not set. Set it in your environment or .env file." | |
| 13 | ); | |
| 14 | } | |
| 15 | const sql = neon(config.databaseUrl); | |
| 16 | _db = drizzle(sql, { schema }); | |
| 17 | } | |
| 18 | return _db; | |
| 19 | } | |
| 20 | ||
| 21 | // Re-export as `db` for convenience — will throw on access without DATABASE_URL | |
| 22 | export const db = new Proxy({} as NeonHttpDatabase<typeof schema>, { | |
| 23 | get(_target, prop, receiver) { | |
| 24 | return Reflect.get(getDb(), prop, receiver); | |
| 25 | }, | |
| 26 | }); |