memory service schema added
This commit is contained in:
23
packages/memory-service/src/db/index.js
Normal file
23
packages/memory-service/src/db/index.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const Database = require('better-sqlite3');
|
||||
const schema = require('./schema');
|
||||
const {getEnv } = require('@nexusai/shared');
|
||||
|
||||
let db; // Declare db variable in a scope accessible to all functions
|
||||
|
||||
function getDB() {
|
||||
if (!db) {
|
||||
const path = getEnv('SQLITE_PATH', './data/nexusai.db');
|
||||
db = new Database(path);
|
||||
|
||||
db.pragma('journal_mode = WAL');
|
||||
db.pragma('foreign_keys = ON');
|
||||
|
||||
db.exec(schema);
|
||||
console.log(`Connected to SQLite database at ${path}`);
|
||||
}
|
||||
return db;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getDB
|
||||
};
|
||||
Reference in New Issue
Block a user