diff --git a/lib/MySQL.lua b/lib/MySQL.lua index c84ed9d..d0581aa 100644 --- a/lib/MySQL.lua +++ b/lib/MySQL.lua @@ -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 @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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