Skip to content

Commit

Permalink
feat(lib/lua): add options and 'return_callback_errors'
Browse files Browse the repository at this point in the history
Resolves #237. See issue for more information.
  • Loading branch information
thelindat committed Sep 30, 2024
1 parent bfe660b commit 6adaa0b
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/MySQL.lua
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
local promise = promise
local Await = Citizen.Await
local GetCurrentResourceName = GetCurrentResourceName()
local resourceName = GetCurrentResourceName()
local GetResourceState = GetResourceState

local options = {
return_callback_errors = false
}

for i = 1, GetNumResourceMetadata(resourceName, 'mysql_option') do
local option = GetResourceMetadata(resourceName, 'mysql_option', i - 1)
options[option] = true
end

local function await(fn, query, parameters)
local p = promise.new()

fn(nil, query, parameters, function(result, error)
if error then
return p:reject(error)
end

p:resolve(result)
end, GetCurrentResourceName, true)
end, resourceName, true)

return Await(p)
end

Expand Down Expand Up @@ -60,7 +71,7 @@ local oxmysql = exports.oxmysql
local mysql_method_mt = {
__call = function(self, query, parameters, cb)
query, parameters, cb = safeArgs(query, parameters, cb, self.method == 'transaction')
return oxmysql[self.method](nil, query, parameters, cb, GetCurrentResourceName, false)
return oxmysql[self.method](nil, query, parameters, cb, resourceName, options.return_callback_errors)
end
}

Expand Down

0 comments on commit 6adaa0b

Please sign in to comment.