Skip to content

Commit 1892c9e

Browse files
committed
Fix: lazy DB connection to allow build without DATABASE_URL
1 parent a865903 commit 1892c9e

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

.claude/settings.local.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
"Bash(pnpm install)",
55
"Bash(npm install:*)",
66
"Bash(git add:*)",
7-
"Bash(git commit:*)"
7+
"Bash(git commit:*)",
8+
"Bash(pnpm run build:*)",
9+
"Bash(npm run build:*)",
10+
"Bash(export PATH=\"$HOME/.local/share/pnpm:$PATH\")"
811
]
912
}
1013
}

src/db/index.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
import { DATABASE_URL, DATABASE_AUTH_TOKEN } from '@/config';
22
import { drizzle } from 'drizzle-orm/libsql';
3-
import * as schema from "./schema";
3+
import type { LibSQLDatabase } from 'drizzle-orm/libsql';
4+
import * as schema from "./schema";
45

5-
export const db = drizzle({
6-
connection: {
7-
url: DATABASE_URL,
8-
authToken: DATABASE_AUTH_TOKEN,
9-
},
10-
schema
6+
// Lazy initialization to avoid connection during build time
7+
let _db: LibSQLDatabase<typeof schema> | null = null;
8+
9+
export const db = new Proxy({} as LibSQLDatabase<typeof schema>, {
10+
get(_target, prop) {
11+
if (!_db) {
12+
_db = drizzle({
13+
connection: {
14+
url: DATABASE_URL,
15+
authToken: DATABASE_AUTH_TOKEN,
16+
},
17+
schema
18+
});
19+
}
20+
return Reflect.get(_db, prop);
21+
}
1122
});

0 commit comments

Comments
 (0)