Announcement
Collapse
No announcement yet.
Making SQL calls is boring...
Collapse
X
-
Also why the heck does : mariadb_get_assoc(index) returns all value as string?
Leave a comment:
-
Hi,
one thing comes to mind if you want to just rearrange the code : have you tried defining whitelistCheck(player) directly inline with the arguments of the query? It would look something like :
Code:[FONT=courier new]query("SELECT * FROM users WHERE steam = ?", {steamId}, [/FONT][INDENT][FONT=courier new]function (player) [/FONT][/INDENT][INDENT=2][FONT=courier new]local rows = mariadb_get_row_count() if (rows) then [/FONT][/INDENT][INDENT=3][FONT=courier new]local isWhitelisted = mariadb_get_value_name(1, "is_whitelisted"); if (not(isWhitelisted)) then [/FONT][/INDENT][INDENT=4][FONT=courier new]return KickPlayer(player, "Tu n'es pas whitelisté.") [/FONT][/INDENT][INDENT=3][FONT=courier new]end [/FONT][/INDENT][INDENT=2][FONT=courier new]end -- Should I prepare another query here [/FONT][/INDENT][INDENT] [FONT=courier new]end,[/FONT][/INDENT] [FONT=courier new]player)[/FONT]
Happy coding.Last edited by Bewick; 12-24-2019, 03:29 PM.
Leave a comment:
-
Making SQL calls is boring...
Hi,
I read the docs about MariaDB and actually, I found the sql calls very boring (I'm used to async/await that Js provide).
To explain my thoughts, let's explore a minimal example of a package that making some SQL calls in order to check if a user if whitelisted and banned:
Code:function authentificationCheck(player) local steamId = GetPlayerSteamId(player) -- whitelist check if enable if the config if (config("whitelist")) then query("SELECT * FROM users WHERE steam = ?", {steamId}, whitelistCheck, player) end -- ban check: so Should I prepare another query here end function whitelistCheck(player) local rows = mariadb_get_row_count() if (rows) then local isWhitelisted = mariadb_get_value_name(1, "is_whitelisted"); if (not(isWhitelisted)) then return KickPlayer(player, "Tu n'es pas whitelisté.") end end -- Should I prepare another query here end -- that both would be treated here? function banCheck(player) end AddEvent("OnPlayerSteamAuth", authentificationCheck)
I'm used to FiveM, we had promise and coroutine and so.
If anyone have a good workaround or an idea on how to improve this readability, please, let me know
Izio.Tags: None
Leave a comment: