Get return of a query from backend #15066
-
I'm trying to recover the result of sql query of backend, to server through getServerSideProps, but the result is just undefined. The object returns mounted like this {name:'name',id:'id'} Here's my code. I think is scope problem, but i don't find solution. export async function getServerSideProps(context) {
const sql = "select id, username from users";
await query(con,sql, function(result){
return {
Full code: https://github.com/domjesus/learning-next-js/ Thanks for help. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You are running into how JavaScript's closures work. When What does the code for |
Beta Was this translation helpful? Give feedback.
You are running into how JavaScript's closures work. When
function(result){}
is called, it is in a different scope than youremployees
variable.What does the code for
query()
look like?