Download tasks/linkedin/solution/site/implementation/clone/db/index.ts from TIGER-Lab/WebsiteBench: direct link, hf CLI and curl.
- Browser
- Download file 1.16 kB
-
https://huggingface.co/datasets/TIGER-Lab/WebsiteBench/resolve/main/tasks/linkedin/solution/site/implementation/clone/db/index.ts
- Command line
-
hf download hf://datasets/TIGER-Lab/WebsiteBench/tasks/linkedin/solution/site/implementation/clone/db/index.ts
-
curl -L -o index.ts https://huggingface.co/datasets/TIGER-Lab/WebsiteBench/resolve/main/tasks/linkedin/solution/site/implementation/clone/db/index.ts
1.16 kB
| import { drizzle } from "drizzle-orm/d1"; | |
| import { getHttpD1Database } from "./http-d1"; | |
| import { getNodeD1Database } from "./node-d1"; | |
| import * as schema from "./schema"; | |
| const globalForDb = globalThis as typeof globalThis & { | |
| __linkedinTestDb?: D1Database; | |
| }; | |
| /** | |
| * Resolve the clone database synchronously so existing route and library call | |
| * sites retain their current getDb() contract. Production containers use the | |
| * authenticated same-host D1 HTTP proxy; local development/tests use node:sqlite. | |
| */ | |
| export function getDb() { | |
| let binding: D1Database | undefined; | |
| if (process.env.LINKEDIN_TEST_RUNTIME === "1") { | |
| binding = globalForDb.__linkedinTestDb; | |
| } | |
| if (!binding && process.env.LINKEDIN_D1_PROXY_URL) { | |
| binding = getHttpD1Database(process.env.LINKEDIN_D1_PROXY_URL); | |
| } | |
| if (!binding && process.env.LINKEDIN_SQLITE_PATH) { | |
| binding = getNodeD1Database(process.env.LINKEDIN_SQLITE_PATH); | |
| } | |
| if (!binding) { | |
| throw new Error( | |
| "LinkedIn D1 storage is unavailable. Set LINKEDIN_D1_PROXY_URL in production or LINKEDIN_SQLITE_PATH for local development.", | |
| ); | |
| } | |
| return drizzle(binding, { schema }); | |
| } | |