20 lines
655 B
JavaScript
20 lines
655 B
JavaScript
// Creates tachyon.db (if it doesn't exist) and applies schema.sql.
|
|
// Safe to re-run: every statement uses CREATE TABLE IF NOT EXISTS.
|
|
import Database from 'better-sqlite3';
|
|
import { readFileSync } from 'node:fs';
|
|
import { fileURLToPath } from 'node:url';
|
|
import path from 'node:path';
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
const dbPath = path.join(__dirname, 'tachyon.db');
|
|
const schemaPath = path.join(__dirname, 'schema.sql');
|
|
|
|
const db = new Database(dbPath);
|
|
db.pragma('journal_mode = WAL');
|
|
|
|
const schema = readFileSync(schemaPath, 'utf8');
|
|
db.exec(schema);
|
|
|
|
console.log(`Initialized database at ${dbPath}`);
|
|
db.close();
|