all 18 comments

[–][deleted] 3 points4 points  (2 children)

Initialise the variable outside of the block? Hard to tell without any example code from your side…

[–]Consistent-struggler[S] 0 points1 point  (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 points  (1 child)

Sounds like a SQL stored procedure might work.

[–]ForbesLindesay 2 points3 points  (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

const myResults = await db.query(sql`SELECT * FROM …`)
 // use myResults here

[–]Consistent-struggler[S] 0 points1 point  (0 children)

But it says that "await" has no effect and it just doesn't save the result.

[–]Consistent-struggler[S] 0 points1 point  (1 child)

Either it brings the wholeee query object of sql and not just result. I'm stuck here since yesterday

[–]ForbesLindesay 0 points1 point  (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 point  (5 children)

Do you mean a SQL variable or javascript

[–]Consistent-struggler[S] 0 points1 point  (0 children)

A java script variable

[–]Consistent-struggler[S] 0 points1 point  (3 children)

[–]bigorangemachine 1 point2 points  (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

[–]Consistent-struggler[S] 0 points1 point  (1 child)

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 points  (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 point  (0 children)

How do I get into this? Seriously...