gadl/database.ts
2023-11-19 02:25:32 +09:00

18 lines
455 B
TypeScript

import fs from "node:fs/promises";
import sqlite3 from "sqlite3";
import { Database, open } from "sqlite";
export { Database };
export async function createDatabase(file: string): Promise<Database> {
const db = await open({
filename: file,
driver: sqlite3.cached.Database,
});
const migrationsPath = new URL("./migrations", import.meta.url).pathname;
await fs.chmod(file, 0o600);
await db.migrate({ migrationsPath });
return db;
}