Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add async queries #113

Merged
merged 2 commits into from
Apr 1, 2023
Merged

feat: add async queries #113

merged 2 commits into from
Apr 1, 2023

Conversation

r-o-b-o-t-o
Copy link
Member

@r-o-b-o-t-o r-o-b-o-t-o commented Apr 1, 2023

Adds async queries for the world, characters and auth databases (WorldDBQueryAsync, CharDBQueryAsync, AuthDBQueryAsync)

local PLAYER_EVENT_ON_COMMAND = 42

local function SyncQueryExample()
	-- Hangs the server for 5 seconds while the query executes because of the SLEEP(5)
	query = CharDBQuery("SELECT guid, account, name, level, SLEEP(5) FROM characters LIMIT 3")
	if not query then
		return
	end

	repeat
		local guid, account, name, level = query:GetUInt32(0), query:GetUInt32(1), query:GetString(2), query:GetUInt8(3)
		print("GUID: " .. tostring(guid) .. ", account: " .. tostring(account) .. ", name: " .. name .. ", level: " .. tostring(level))
	until not query:NextRow()
end

local function AsyncQueryExample()
	-- Doesn't hang the server even with SLEEP(5) because we're using CharDBQueryAsync
	CharDBQueryAsync("SELECT guid, account, name, level, SLEEP(5) FROM characters LIMIT 3", function(query)
		if not query then
			return
		end

		repeat
			local guid, account, name, level = query:GetUInt32(0), query:GetUInt32(1), query:GetString(2), query:GetUInt8(3)
			print("GUID: " .. tostring(guid) .. ", account: " .. tostring(account) .. ", name: " .. name .. ", level: " .. tostring(level))
		until not query:NextRow()
	end)
end

RegisterPlayerEvent(PLAYER_EVENT_ON_COMMAND, function(event, player, command, chathandler)
	if command == "sync" then
		print("Executing sync query...")
		SyncQueryExample()
		return false
	elseif command == "async" then
		print("Executing async query...")
		AsyncQueryExample()
		return false
	end

	return true
end)

@r-o-b-o-t-o r-o-b-o-t-o merged commit fb1f240 into master Apr 1, 2023
@r-o-b-o-t-o r-o-b-o-t-o deleted the feat/async-query branch April 1, 2023 16:33
Tony931023 added a commit to ShadowNet-Cuba/mod-eluna that referenced this pull request Apr 5, 2023
* fix(ci): exclude date.js from doc PR git status (azerothcore#108)

* feat: add async queries (azerothcore#113)

* fix(ci): exclude date.js from doc PR git status

* feat: replace getLevel with GetLevel (azerothcore#115)

* fix: GetItemLink crash (azerothcore#114)

* feat: add Unit:GetAttackers (azerothcore#116)

* feat: add Unit:GetThreatList (azerothcore#117)

---------

Co-authored-by: Axel Cocat <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants