preciazo/db-datos/db.js

16 lines
473 B
JavaScript
Raw Normal View History

// @ts-check
import Database from "better-sqlite3";
import { drizzle } from "drizzle-orm/better-sqlite3";
2023-12-30 00:49:32 +00:00
import { DB_PATH } from "./drizzle.config.js";
import * as schema from "./schema.js";
2024-01-24 23:13:20 +00:00
import { migrateDb } from "./migrate.js";
2023-12-30 00:49:32 +00:00
2024-01-24 23:13:20 +00:00
/** @type {null | import("drizzle-orm/better-sqlite3").BetterSQLite3Database<schema>} */
let db = null;
export function getDb() {
const sqlite = new Database(DB_PATH);
db = drizzle(sqlite, { schema });
migrateDb(db);
return db;
}