preciazo/db-datos/db.js

16 lines
487 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);
2024-02-07 02:44:16 +00:00
db = drizzle(sqlite, { schema, logger: true });
2024-01-24 23:13:20 +00:00
migrateDb(db);
return db;
}