Skip to content

Commit

Permalink
refactor(prepare): Rename prepared export to prepare
Browse files Browse the repository at this point in the history
  • Loading branch information
thelindat committed Oct 23, 2021
1 parent 2a8f4b1 commit ca8cef4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ global.exports('transaction', (queries, parameters, cb, resource = GetInvokingRe
});
});

global.exports('prepared', (query, parameters, cb, resource = GetInvokingResource()) => {
global.exports('prepare', (query, parameters, cb, resource = GetInvokingResource()) => {
preparedStatement(query, parameters, resource).then((result) =>
safeCallback(cb || parameters, result, resource, query))
});

if (!GetResourceMetadata(GetCurrentResourceName(), 'server_script', 1)) {
global.exports('preparedSync', async (query, parameters) => {
global.exports('prepareSync', async (query, parameters) => {
const result = await preparedStatement(query, parameters, GetInvokingResource());
return result;
});
Expand Down
31 changes: 22 additions & 9 deletions wrapper.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---@param query string
---@param parameters? table|function
---@param parameters? table
---@return integer result
---returns number of rows updated by the executed query
---returns array of matching rows or result data
exports('executeSync', function(query, parameters)
local p = promise.new()
exports['oxmysql']:execute(query, parameters, function(result)
Expand All @@ -10,9 +10,8 @@ exports('executeSync', function(query, parameters)
return Citizen.Await(p)
end)

---@deprecated true
---@param query string
---@param parameters? table|function
---@param parameters? table
---@return table result
---returns array of matching rows or result data
exports('fetchSync', function(query, parameters)
Expand All @@ -24,7 +23,7 @@ exports('fetchSync', function(query, parameters)
end)

---@param query string
---@param parameters? table|function
---@param parameters? table
---@return table result
---returns table containing key value pairs
exports('singleSync', function(query, parameters)
Expand All @@ -36,7 +35,7 @@ exports('singleSync', function(query, parameters)
end)

---@param query string
---@param parameters? table|function
---@param parameters? table
---@return integer|string
---returns value of the first column of a single row
exports('scalarSync', function(query, parameters)
Expand All @@ -48,7 +47,7 @@ exports('scalarSync', function(query, parameters)
end)

---@param query string
---@param parameters? table|function
---@param parameters? table
---@return table result
---returns the last inserted id
exports('insertSync', function(query, parameters)
Expand All @@ -60,7 +59,7 @@ exports('insertSync', function(query, parameters)
end)

---@param query string
---@param parameters? table|function
---@param parameters? table
---@return integer result
---returns number of rows updated by the executed query
exports('updateSync', function(query, parameters)
Expand All @@ -72,7 +71,7 @@ exports('updateSync', function(query, parameters)
end)

---@param queries table
---@param parameters? table|function
---@param parameters? table
---@return boolean result
---returns true when the transaction has succeeded
exports('transactionSync', function(queries, parameters)
Expand All @@ -81,4 +80,18 @@ exports('transactionSync', function(queries, parameters)
p:resolve(result)
end, GetInvokingResource())
return Citizen.Await(p)
end)

---@param query string
---@param parameters table
---@return any result
---supports SELECT, INSERT, UPDATE, and DELETE
---
---return value is based on the number of results and the type of query used
exports('prepareSync', function(query, parameters)
local p = promise.new()
exports['oxmysql']:prepare(query, parameters, function(result)
p:resolve(result)
end, GetInvokingResource())
return Citizen.Await(p)
end)

0 comments on commit ca8cef4

Please sign in to comment.