-
Notifications
You must be signed in to change notification settings - Fork 31
/
index.ts
27 lines (22 loc) · 814 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { createClient, type Config } from "@libsql/client";
import { drizzle } from "drizzle-orm/libsql";
import { config } from "../../config";
import * as schema from "./schema";
const { DATABASE_CONNECTION_TYPE } = config.env;
const options = {
local: { url: "file:local.sqlite" },
remote: {
url: config.env.DATABASE_URL,
authToken: config.env.DATABASE_AUTH_TOKEN!,
},
"local-replica": {
url: "file:local.sqlite",
syncUrl: config.env.DATABASE_URL,
authToken: config.env.DATABASE_AUTH_TOKEN!,
},
} satisfies Record<typeof DATABASE_CONNECTION_TYPE, Config>;
export const client = createClient(options[DATABASE_CONNECTION_TYPE]);
if (config.env.DATABASE_CONNECTION_TYPE === "local-replica") {
await client.sync();
}
export const db = drizzle(client, { schema, logger: true });