Hi,
I am editing a script :
AddEventHandler('es:playerLoaded', function(source)
TriggerEvent('es:getPlayerFromId', source, function(user)
local query = MySQL:executeQuery("SELECT * FROM users WHERE identifier = '@id'", {['@id'] = user.identifier} )
local result = MySQL:getResults(query, {'job'}, "identifier")
local jobId = result[1].job
local queryJob = MySQL:executeQuery("SELECT * FROM jobs WHERE job_id = '@id'", {['@id'] = jobId} )
result = MySQL:getResults(queryJob, {'job_name'}, "job_id")
local jobName = result[1].job_name
TriggerClientEvent("jobssystem:updateJob", source, jobName)
end)
end)
I would like to know if I can refactor this code by deleting the first SQL query with an object properties access (such as user.job
(where job is the name of a table in the DBMS).
Obviously I tried and it doesn’t work like that. I just wanted to know if there is a magic method to do this.
I know it’s possible in other languages.
Thank you
EDIT : I know I could do an INNER JOIN to refactor but that’s not the goal of my question