I have been trying to do a simple query and return the results with node-mysql
however I had several problems. Originally I wrote it where there was no promise, but if I tried to access user after just doing a query if returned undefined
The solution I came up with is the following, is this a good way of doing it? I need to wait until the results come back so I can then send a signal to the frontend to say the player is loaded and can play. Do I need to create a new promise for each query? I have a few tables I need to get data from (That can't be done with joins)
class Player {
constructor(user_id, socket, connection) {
this.socket = socket;
this.connection = connection;
this.loadUser(user_id)
.then(() => {
console.log("loaded user", this.user);
});
}
async loadUser(user_id) {
let _self = this;
return new Promise((resolve, reject) => {
_self.connection.query(`SELECT * FROM users WHERE id = ${user_id}`, (err, res) => {
this.user = res[0];
resolve()
});
})
}
}
```
node-mysql
that the package @node-mysql/mysql? \$\endgroup\$