Sqlite .all() function returns an undefined promise. How can I use the result further?

I am just starting to work with JS and SQLite. And could not find any help for my specific question. I want to keep a return to use it as a foreign key in a second table. This is my function: What do I have to do so that promise does not stay undefined outside of the function? Rest of the code: My other function just creat some strings and I run a few times db.run(…) to add some tables. Answer To put it more plainly, your getIdByName function never returns anything. You need to return the value you get

UnhandledPromiseRejectionWarning : error handling in an async callback function

I have an async callback function, which throws an error if some condition isn’t met. but I get the below error (node:77284) UnhandledPromiseRejectionWarning: Error: Not Found UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). My Code : What is the proper way to throw an error from the callback function? Answer In looking at code examples for .runTransaction(), it looks like it returns a promise and will propagate a promise rejections from its callback (that’s a bit of

Two promises with a single then for either one of them

I have a function that takes an input, according to that input it will either call one of two functions (both return a promise) I want then to call the same .then() after whatever of them happened. I found Promise.any() but that doesn’t quite do what I want. For curious minds : I am working on a react-native app and want to either open the camera or the gallery then handle the photo in a then(). How can I do that? Answer

why is async-await much slower than promises when running them together

I found out that running async-await can be much slower in some scenarios. IMO, the console.log in usingPromises should print similar results to the one in usingAwait. But in reality, I get: Total (promises): 0.25 ms Total (await): 2.065 ms Also, after the page load, if I click on ‘usingPromises’ or ‘usingAwait’ button I get similar results for each of them. (both are fast when running alone) Total (promises): 0.060000000026775524 ms Total (await): 0.08999999999650754 ms But if I click on the ‘both’ button, the ‘await’ version is ~3-4 times slower than the promises version. I have a real application running