Eluna icon indicating copy to clipboard operation
Eluna copied to clipboard

[Suggestion] Implement asynchronous DB queries

Open anzz1 opened this issue 3 years ago • 0 comments

Currently Eluna has only DBQuery and DBExecute which of Execute is pushed to the core's database worker thread pool and does not block, but also does not return results. If you want to make a database query, it is always synchronous and hence always blocking.

If something like this would be implemented in Eluna Engine

callbackfunc_tbl ={}
function Eluna.ASyncQueryResultsReturned(results, id)
    callbackfunc_tbl[id](results)
    callbackfunc_tbl[id] = nil
end
function Eluna.CharDBASyncQuery(queryString, callbackFunc)
    ... push the query and id of the query to the core database worker thread ...
    callbackfunc_tbl[id] = callbackFunc
end

Something like this could be used then in scripts:

local function resultsCallback(results)
    if results then
        repeat
            local entry, name = results:GetUInt32(0), results:GetString(1)
            print(entry, name)
        until not results:NextRow()
    else
        print("db fetch failed")
    end
end


local function whatever()
    CharDBASyncQuery("SELECT entry, name FROM creature_template LIMIT 10", resultsCallback)
    -- continue execution as normal, resultsCallback will be called later when results arrive
end

Such thing is probably implemented in all the supported cores (?) because doing synchronous queries for everything and blocking execution is not viable. I know that at least AzerothCore and TrinityCore does have this ASyncQuery method DatabaseWorkerPool.cpp#L225 , it just needs to be implemented in Eluna.

anzz1 avatar Jan 06 '22 18:01 anzz1