mardi 23 février 2016

Node.js SQLite 3 Return Promise

I am somewhat new to node.js and I figured out how to use it with SQLite but I would like to make wrapper functions so I don't have to have SQL statements all over my code. This code prints out the result of the query:

 Users.find_by_id = function(id){
  db.all("SELECT * from users WHERE id=" + id, function(err, row){
    console.log(row);
  });
};

I know that node.js is asynchronous so I can't return the values themselves but I was wondering if it was possible to return a promise with the values in question.

Aucun commentaire:

Enregistrer un commentaire