All files dao.js

81.25% Statements 13/16
75% Branches 3/4
100% Functions 4/4
81.25% Lines 13/16
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 29 301x     1x       10x 10x 10x         10x 10x 10x 10x 1x 1x   9x 9x              
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");
        console.log(err);
        callback(500, { error: "feil ved ved oppkobling" });
      } else {
        console.log("dao: running sql: " + sql);
        connection.query(sql, params, (err, rows) => {
          connection.release();
          if (err) {
            console.log(err);
            callback(500, { error: "error querying" });
          } else {
            console.log("dao: returning rows");
            callback(200, rows);
          }
        });
      }
    });
  }
};