I’m trying to write code that will be executed if an SQLite query won’t return results. However, the async nature of Node.js makes this difficult. I don’t know if I can write code inside the callback function, because when I test with inputs that will cause empty results, nothing happens.
I’m doing
db.each("SELECT pid, collection , photo FROM photos WHERE collection = '"+collection_id+"' AND pid = '"+photo_id+"' ", function(err, row) {
console.log("PHOTO FOUND");
//code inside the callback function
});
//code I want
Specifically, I want to render something general, in case the user requests something that is not in the db
What should I do?
This is from the API documentation for the package you appear to be using (emphasis mine):
So, it would seem your code should look like this: