mirror of
https://github.com/jnsahaj/tweakcn.git
synced 2026-08-28 23:02:07 +08:00
d67e460673
Pages that don't use the database will now work without the env var set. DB-dependent features will show a clear error only when accessed. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
20 lines
583 B
TypeScript
20 lines
583 B
TypeScript
import { drizzle, type NeonHttpDatabase } from "drizzle-orm/neon-http";
|
|
import { neon } from "@neondatabase/serverless";
|
|
|
|
let _db: NeonHttpDatabase | null = null;
|
|
|
|
export const db = new Proxy({} as NeonHttpDatabase, {
|
|
get(_target, prop) {
|
|
if (!_db) {
|
|
if (!process.env.DATABASE_URL) {
|
|
throw new Error(
|
|
"DATABASE_URL is not set. Database features are disabled in local development without a database."
|
|
);
|
|
}
|
|
const sql = neon(process.env.DATABASE_URL);
|
|
_db = drizzle({ client: sql });
|
|
}
|
|
return (_db as any)[prop];
|
|
},
|
|
});
|