Good evening. I have a need, for example, to return information about whether the user is blocked, obtained from the database, to the main code. I created a class called Db:
export class Db {
constructor() {
this.database = database;
}
private async databaseGet(sql: string, params: any[], callback: Function) {
database.all(sql, params, async (err: Error | null, row: any) => {
await callback(row)
})
}
async checkUserban(userId: number): Promise<boolean | any> {
let res
async function resultFunc(rows: object) {
console.log(rows)
res = rows
}
await this.databaseGet('SELECT id FROM bans WHERE user_id = ?', [userId], resultFunc)
console.log(res)
}
}
Next, I need to analyze the rows from the database, and if there is a user with this id in the table, return tyrue, if not, return false. The problem is that I will receive the response from the database later than the code in the class function is executed, therefore, it will not be possible to receive the response from the database to process it. How to implement this?
Nothing came to mind
Vanchugov Artemy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.