Skip to content

Commit

Permalink
feat(lib): Setup support for lua docs
Browse files Browse the repository at this point in the history
  • Loading branch information
thelindat authored Oct 15, 2021
1 parent 31959be commit b781f0c
Showing 1 changed file with 64 additions and 17 deletions.
81 changes: 64 additions & 17 deletions lib/MySQL.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,66 @@ local function safeArgs(query, parameters, cb)
end

MySQL = {
-- @retval Result is sent as an argument to the callback function
--- Result is returned to a callback function, without interupting the execution of code
Async = {
-- @retval Number of affected rows
---@param query string
---@param parameters? table|function
---@param cb? function
---@return integer result
---returns number of rows updated by the executed query
execute = function(query, parameters, cb)
Ox:update(safeArgs(query, parameters, cb))
end,

-- @retval Fetch all query results
---@param query string
---@param parameters? table|function
---@param cb? function
---@return table result
---returns array of matching rows or result data
fetchAll = function(query, parameters, cb)
Ox:execute(safeArgs(query, parameters, cb))
end,

-- @retval Returns a single result from a column
---@param query string
---@param parameters? table|function
---@param cb? function
---@return integer|string
---returns value of the first column of a single row
fetchScalar = function(query, parameters, cb)
Ox:scalar(safeArgs(query, parameters, cb))
end,

-- @retval Returns the first row
---@param query string
---@param parameters? table|function
---@param cb? function
---@return table result
---returns table containing key value pairs
fetchSingle = function(query, parameters, cb)
Ox:single(safeArgs(query, parameters, cb))
end,

-- @retval Returns the id of the newly inserted row
---@param query string
---@param parameters? table|function
---@param cb? function
---@return table result
---returns the last inserted id
insert = function(query, parameters, cb)
Ox:insert(safeArgs(query, parameters, cb))
end,

-- @retval Returns true/false when the given queries are executed
---@param query string
---@param parameters? table|function
---@param cb? function
---@return boolean result
---returns true when the transaction has succeeded
transaction = function(query, parameters, cb)
Ox:transaction(safeArgs(query, parameters, cb))
end,

-- @retval Returns an integer for referencing a query string
---@param query string
---@param cb? function
---@return integer result
---returns the id used to reference a stored query string
store = function(query, cb)
assert(type(query) == 'string', 'The SQL Query must be a string')
local store = #Store+1
Expand All @@ -61,9 +88,12 @@ MySQL = {
end,
},

-- @retval Result is returned to a variable
--- Result is assigned in-line to a variable, causing the current thread to await the result
Sync = {
-- @retval Number of affected rows
---@param query string
---@param parameters? table|function
---@return integer result
---returns number of rows updated by the executed query
execute = function(query, parameters)
query, parameters = safeArgs(query, parameters)
local promise = promise.new()
Expand All @@ -73,7 +103,10 @@ MySQL = {
return Citizen.Await(promise)
end,

-- @retval Fetch all query results
---@param query string
---@param parameters? table|function
---@return table result
---returns array of matching rows or result data
fetchAll = function(query, parameters)
query, parameters = safeArgs(query, parameters)
local promise = promise.new()
Expand All @@ -83,7 +116,10 @@ MySQL = {
return Citizen.Await(promise)
end,

-- @retval Returns a single result from a column
---@param query string
---@param parameters? table|function
---@return integer|string
---returns value of the first column of a single row
fetchScalar = function(query, parameters)
query, parameters = safeArgs(query, parameters)
local promise = promise.new()
Expand All @@ -93,7 +129,10 @@ MySQL = {
return Citizen.Await(promise)
end,

-- @retval Returns the first row
---@param query string
---@param parameters? table|function
---@return table result
---returns table containing key value pairs
fetchSingle = function(query, parameters)
query, parameters = safeArgs(query, parameters)
local promise = promise.new()
Expand All @@ -103,7 +142,10 @@ MySQL = {
return Citizen.Await(promise)
end,

-- @retval Returns the id of the newly inserted row
---@param query string
---@param parameters? table|function
---@return table result
---returns the last inserted id
insert = function(query, parameters)
query, parameters = safeArgs(query, parameters)
local promise = promise.new()
Expand All @@ -113,7 +155,10 @@ MySQL = {
return Citizen.Await(promise)
end,

-- @retval Returns true/false when the given queries are executed
---@param query string
---@param parameters? table|function
---@return boolean result
---returns true when the transaction has succeeded
transaction = function(query, parameters)
query, parameters = safeArgs(query, parameters)
local promise = promise.new()
Expand All @@ -123,8 +168,10 @@ MySQL = {
return Citizen.Await(promise)
end,

-- @retval Returns an integer for referencing a query string
store = function(query, parameters)
---@param query string
---@return integer result
---returns the id used to reference a stored query string
store = function(query)
assert(type(query) == 'string', 'The SQL Query must be a string')
local store = #Store+1
Store[store] = query
Expand Down

0 comments on commit b781f0c

Please sign in to comment.