18 lines
624 B
TypeScript
18 lines
624 B
TypeScript
import { createClient } from "@libsql/client";
|
|
import { drizzle } from "drizzle-orm/libsql";
|
|
import * as schema from "@app/models";
|
|
|
|
const url = process.env["TURSO_DATABASE_URL"];
|
|
if (!url) throw new Error("TURSO_DATABASE_URL is required");
|
|
|
|
const clientConfig: { url: string; authToken?: string } = { url };
|
|
const token = process.env["TURSO_AUTH_TOKEN"];
|
|
if (token) clientConfig.authToken = token;
|
|
|
|
const client = createClient(clientConfig);
|
|
|
|
/** Drizzle 客户端单例。模型定义请从 `@app/models` 引入;查询优先走 DAO。 */
|
|
export const db = drizzle(client, { schema });
|
|
|
|
export type Database = typeof db;
|