Преглед изворни кода

Ajout methode création db + export

Loquicom пре 5 година
родитељ
комит
c4a2a14b78
1 измењених фајлова са 15 додато и 2 уклоњено
  1. 15 2
      node/src/db.js

+ 15 - 2
node/src/db.js

@@ -1,5 +1,6 @@
 const fs = require('fs');
 const sqlite = require('sqlite3');
+const sql = require('./sql');
 
 // Indique si un fichier existe
 function fileExist(path) {
@@ -29,7 +30,16 @@ function Db() {
 Db.prototype.DB_PATH = './data/loquicompta.db';
 
 Db.prototype.createDb = function() {
-    
+    try {
+        this.db.run(sql.createUserTable);
+        this.db.run(sql.createFileTable);
+        this.db.run(sql.createUserFileTable);
+    } catch(err) {
+        if(global.verbose) {
+            console.error(err);
+        }
+        throw new Error('Error during initialization');
+    }
 }
 
 Db.prototype.getUser = function(username) {
@@ -58,4 +68,7 @@ Db.prototype.addFile = function(username, filename, data) {
 
 Db.prototype.updateFile = function(username, filename, data) {
 
-}
+}
+
+// Export
+module.exports = new Db();