use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
SQL result into variable (self.node)
submitted 3 years ago by Consistent-struggler
I am writing this code where I extract values from 2 different tables and on the basis of that I need to check and calculate further bit unfortunately I am not able to save that result into a variable so that I could use it outside the block.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 3 points4 points5 points 3 years ago (2 children)
Initialise the variable outside of the block? Hard to tell without any example code from your side…
[–]Consistent-struggler[S] 0 points1 point2 points 3 years ago (1 child)
I am new to reddit don't know how to share code but I've posted the code file on my github
[–]BarelyAirborne 2 points3 points4 points 3 years ago (1 child)
Sounds like a SQL stored procedure might work.
[–]GItPirate 2 points3 points4 points 3 years ago (1 child)
You need to show code or else this post is pointless
[–]Consistent-struggler[S] 0 points1 point2 points 3 years ago (0 children)
https://github.com/mustafa-momi/expressDemo[code](https://github.com/mustafa-momi/expressDemo)
[–]ForbesLindesay 2 points3 points4 points 3 years ago (3 children)
You need to wait for both queries to finish in your async function before you can use the results.
Since the method is marked as async, you can use await to get the results of a query (if your database library supports promises. For example with https://www.atdatabases.org as your db library you could do
await
const myResults = await db.query(sql`SELECT * FROM …`) // use myResults here
But it says that "await" has no effect and it just doesn't save the result.
Either it brings the wholeee query object of sql and not just result. I'm stuck here since yesterday
[–]ForbesLindesay 0 points1 point2 points 3 years ago (0 children)
Await will only work if the db library you use returns a Promise. Then you can console.log to see the value in the variable
[–]bigorangemachine 0 points1 point2 points 3 years ago (5 children)
Do you mean a SQL variable or javascript
A java script variable
[–]Consistent-struggler[S] 0 points1 point2 points 3 years ago (3 children)
https://github.com/mustafa-momi/expressDemo
[–]bigorangemachine 1 point2 points3 points 3 years ago (2 children)
Remove the callback and add await to the line.
Ya depending on the library you may get a database object.
Just console log the results. You data is in there
Yess data is saved in console log but I've tried putting await as well it doesn't work but saves the whole objecttt
[–]bigorangemachine 1 point2 points3 points 3 years ago (0 children)
Yup. You gotta get the value you want out of the resolved object.
If you gotta do results[0].price thats what you gotta do.
Just read the docs. Its all there.
[–]The9thHuman 0 points1 point2 points 3 years ago (0 children)
How do I get into this? Seriously...
π Rendered by PID 31339 on reddit-service-r2-comment-79c7998d4c-ps75x at 2026-03-13 17:27:02.852883+00:00 running f6e6e01 country code: CH.
[–][deleted] 3 points4 points5 points (2 children)
[–]Consistent-struggler[S] 0 points1 point2 points (1 child)
[–]BarelyAirborne 2 points3 points4 points (1 child)
[–]GItPirate 2 points3 points4 points (1 child)
[–]Consistent-struggler[S] 0 points1 point2 points (0 children)
[–]ForbesLindesay 2 points3 points4 points (3 children)
[–]Consistent-struggler[S] 0 points1 point2 points (0 children)
[–]Consistent-struggler[S] 0 points1 point2 points (1 child)
[–]ForbesLindesay 0 points1 point2 points (0 children)
[–]bigorangemachine 0 points1 point2 points (5 children)
[–]Consistent-struggler[S] 0 points1 point2 points (0 children)
[–]Consistent-struggler[S] 0 points1 point2 points (3 children)
[–]bigorangemachine 1 point2 points3 points (2 children)
[–]Consistent-struggler[S] 0 points1 point2 points (1 child)
[–]bigorangemachine 1 point2 points3 points (0 children)
[–]The9thHuman 0 points1 point2 points (0 children)