feat: add sqlite db

This commit is contained in:
sai80082 committed 2026-03-23 10:46:46 +05:30
1 parent 39769391ea
commit 8b8d220b13
8 files changed
+64 -1

No files matched your search

+20
View File
@@ -0,0 +1,20 @@
import { createClient } from "@libsql/client";
import { drizzle } from "drizzle-orm/libsql";
import { migrate } from "drizzle-orm/libsql/migrator";
import path from "path";
import * as schema from "./schema";
const DB_PATH =
process.env.APP_DB_PATH || path.join(process.cwd(), "data", "app.db");
const client = createClient({ url: `file:${DB_PATH}` });
export const appDb = drizzle(client, { schema });
// Run pending migrations automatically on startup.
// migrate() is idempotent — safe to call on every boot.
export async function runMigrations() {
await migrate(appDb, {
migrationsFolder: path.join(process.cwd(), "src", "db", "migrations"),
});
}
+5
View File
@@ -0,0 +1,5 @@
{
"version": "5",
"dialect": "sqlite",
"entries": []
}
+1
View File
@@ -0,0 +1 @@
export * from "./settings.schema";
+9
View File
@@ -0,0 +1,9 @@
import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core";
export const settings = sqliteTable("settings", {
key: text("key").primaryKey(),
value: text("value").notNull(),
updatedAt: integer("updated_at", { mode: "timestamp" }).$onUpdate(
() => new Date()
),
});