Synchronously fetch data from the DB

I dont use mysql-async and would advise making the switch to OxMySQL.

but in your example you can do something like

MySQL.ready(function()
    local p = promise.new()
    MySQL.Async.fetchAll("SELECT * FROM mytable WHERE id = @id", { ["@id"] = id }, function(result)
        p:resolve(result)
    end)
    local result = Citizen.Await(p)
    if result[1] then
        print("sucess")
        local username = result[1].username
        print("username", username)
    else
        print("no user found")
    end
end)
1 Like