All files dao.js

73.33% Statements 11/15
50% Branches 2/4
100% Functions 4/4
73.33% Lines 11/15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 291x     1x       10x 10x 10x       10x 10x 10x 10x       10x 10x              
module.exports = class Dao {
  constructor(pool) {
    // Dependency Injection
    this.pool = pool;
  }
 
  query(sql, params, callback) {
    this.pool.getConnection((err, connection) => {
      console.log("dao: connected to database");
      Iif (err) {
        console.log("dao: error connecting");
        callback(500, { error: "feil ved ved oppkobling" });
      } else {
        console.log("dao: running sql: " + sql);
        connection.query(sql, params, (err, rows) => {
          connection.release();
          Iif (err) {
            console.log(err);
            callback(500, { error: "error querying" });
          } else {
            console.log("dao: returning rows");
            callback(200, rows);
          }
        });
      }
    });
  }
};