types / mysql2

Typings for https://github.com/sidorares/node-mysql2
ISC License
41 stars 23 forks source link

Returning a value from the callback function #56

Closed Satalicious closed 1 year ago

Satalicious commented 1 year ago
export const validateCredentials = async (user: User): Promise<boolean> => {
    let result;
    connection.query('SELECT password from users WHERE email = ? AND password = ?', [user.email, user.password], (err: QueryError, rows: RowDataPacket[]) => {
        console.log(rows[0][user.password]); //this is the users password
        result = rows[0][user.password];
    });
    console.log(result) // result is always undefined 
    return result != undefined;

};

the provided email and password are correct and rows[0][user.password] is holding a value. now i want to return this value outside the callback function, how do i do that?