user5505266
user5505266

Reputation: 603

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.

Upvotes: 0

Views: 2053

Answers (1)

rgvassar
rgvassar

Reputation: 5811

If you want to use promises there are a lot of packages you can use. I like Q. Without promises you can take a callback function as a parameter and call that when you're done, passing the data to the function.

Upvotes: 1

Related Questions