Переработаны роутеры приложения
Переписано APi WebSocket для работы с новыми роутерами
This commit is contained in:
21
ws/config/db.js
Normal file
21
ws/config/db.js
Normal file
@@ -0,0 +1,21 @@
|
||||
const sqlite3 = require("sqlite3");
|
||||
const path = require("path");
|
||||
require("dotenv").config();
|
||||
|
||||
const dbPath = process.env.DATABASE_PATH || path.join(__dirname, ".."); // если в .env относительный путь
|
||||
const fileName = process.env.DATABASE_FILE || "database.sqlite";
|
||||
|
||||
const fullPath = path.isAbsolute(dbPath) ? path.join(dbPath, fileName) : path.join(dbPath, fileName);
|
||||
|
||||
const db = new sqlite3.Database(fullPath, (err) => {
|
||||
if (err) {
|
||||
console.error("❌ Failed to open sqlite database:", err);
|
||||
} else {
|
||||
console.log("✅ SQLite DB opened at", fullPath);
|
||||
}
|
||||
});
|
||||
|
||||
// optional: enable foreign keys
|
||||
db.exec("PRAGMA foreign_keys = ON;");
|
||||
|
||||
module.exports = db;
|
||||
Reference in New Issue
Block a user