initial commit
This commit is contained in:
20
db/init_db.js
Normal file
20
db/init_db.js
Normal file
@@ -0,0 +1,20 @@
|
||||
import fs from 'fs';
|
||||
import Database from 'better-sqlite3';
|
||||
|
||||
const dbName = 'strimserve.db';
|
||||
|
||||
// Read the schema file
|
||||
const schema = fs.readFileSync('schema.sql', 'utf8');
|
||||
|
||||
// Create a new database object and initialize it with the schema
|
||||
const db = new Database(dbName);
|
||||
|
||||
try {
|
||||
console.log(`Connected to the ${dbName} database.`);
|
||||
db.exec(schema);
|
||||
console.log('Schema initialized successfully.');
|
||||
} catch (err) {
|
||||
console.error(err.message);
|
||||
} finally {
|
||||
db.close();
|
||||
}
|
||||
Reference in New Issue
Block a user