Kaynağa Gözat

Ajout methode pour recupérer le chemin vers la bdd

Arthur Brandao 5 yıl önce
ebeveyn
işleme
c512f4b4d4
2 değiştirilmiş dosya ile 9 ekleme ve 5 silme
  1. 1 1
      node/main.js
  2. 8 4
      node/src/db.js

+ 1 - 1
node/main.js

@@ -8,7 +8,7 @@ process.on('SIGINT', function () {
 
 // 1er Lancement
 const fs = require('fs');
-const first = !fs.existsSync(require('./src/db').getDb().DB_PATH);
+const first = !fs.existsSync(require('./src/db').getPath());
 
 // Chargement fichier config
 const config = require('./src/config');

+ 8 - 4
node/src/db.js

@@ -3,6 +3,8 @@ const sqlite = require('sqlite3');
 const crypto = require('crypto');
 const sql = require('./sql');
 
+const DB_PATH = './data/sss.db';
+
 let instance = null;
 
 // Indique si un fichier existe
@@ -21,16 +23,14 @@ function Db() {
         sqlite.verbose();
     }
     // Connection à la base
-    const exist = fileExist(this.DB_PATH);
-    this.db = new sqlite.Database(this.DB_PATH);
+    const exist = fileExist(DB_PATH);
+    this.db = new sqlite.Database(DB_PATH);
     // Création si besoins de la base
     if (!exist) {
         this.createDb();
     }
 }
 
-Db.prototype.DB_PATH = './data/sss.db';
-
 Db.prototype.createDb = function () {
     this._execute(sql.createUserTable);
     this._execute(sql.createFileTable);
@@ -292,3 +292,7 @@ module.exports.getDb = function () {
     }
     return instance;
 };
+
+module.exports.getPath = function () {
+    return DB_PATH;
+};