Browse Source

Début class gestion db

Loquicom 5 năm trước cách đây
mục cha
commit
15ed06d537
2 tập tin đã thay đổi với 64 bổ sung2 xóa
  1. 3 1
      node/.gitignore
  2. 61 1
      node/src/db.js

+ 3 - 1
node/.gitignore

@@ -1 +1,3 @@
-/node_modules
+/node_modules
+/data/loquicompta.db
+/data/files

+ 61 - 1
node/src/db.js

@@ -1 +1,61 @@
-const sqlite = require('sqlite3');
+const fs = require('fs');
+const sqlite = require('sqlite3');
+
+// Indique si un fichier existe
+function fileExist(path) {
+    try {
+        return fs.existsSync(path);
+    } catch (err) {
+        return false;
+    }
+}
+
+// Class Db
+function Db() {
+    // Active ou non le mode verbeux
+    if(global.verbose){
+        sqlite.verbose();
+    }
+    // Connection à la base
+    const exist = fileExist(this.DB_PATH);
+    console.log('exist',exist);
+    this.db = new sqlite.Database(this.DB_PATH);
+    // Création si besoins de la base
+    if(!exist) {
+        this.createDb();
+    }
+};
+
+Db.prototype.DB_PATH = './data/loquicompta.db';
+
+Db.prototype.createDb = function() {
+    
+}
+
+Db.prototype.getUser = function(username) {
+
+}
+
+Db.prototype.addUser = function(username, passwordhash) {
+
+}
+
+Db.prototype.listFile = function(username) {
+
+}
+
+Db.prototype.fileExist = function(username, filename) {
+
+}
+
+Db.prototype.getFile = function(username, filename) {
+
+}
+
+Db.prototype.addFile = function(username, filename, data) {
+
+}
+
+Db.prototype.updateFile = function(username, filename, data) {
+
+}