Answer the question
In order to leave comments, you need to log in
How to hang a promise on sqlite methods and is a promise needed?
I think it's easier to give an example of the code and its current result, and a description of the desired result.
'use strict';
class Database {
constructor() {
this._sqlite3 = require('sqlite3').verbose();
this._conn = new this._sqlite3.Database(__dirname + '/database.sqlite');
}
findOne(sql, params) {
let self = this;
return self._conn.get(sql, params, function (err, row) {
if(err) throw err;
console.log(row);
return row;
})
}
'use strict';
class User extends Database {
constructor() {
super();
}
getWorker() {
let sql = 'select u.*, w.password from users u, workers w where u.id = w.user_id and u.type_id = ?';
return super.findOne(sql, [1]);
}
}
let user = new User();
console.log(user.getWorker()); // Приходит объект Database, хотя ожидаю Object просто
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question