Linden f82fa72643 fix(execute): incorrect execution time for multiple queries
When sending bulk-statements using prepare, the execution time
would always be calculated based on the start of the first query.

This would mistakenly report successive queries as taking longer,
and possibly report slow queries (i.e. when saving all players).
2022-03-27 08:32:39 +11:00
2022-03-21 21:53:48 +01:00
2021-12-24 19:31:46 +11:00
2022-03-25 19:13:25 +11:00
2022-03-02 18:56:32 +01:00
2022-01-04 18:36:52 +01:00

Documentation

Introduction

Oxmysql is an alternative to the unmaintained mysql-async/ghmattimysql resources, utilising node-mysql2 rather than mysqljs.

As of v1.9.0 the preferred method of utilising oxmysql is via lib/MySQL, which can be loaded by adding @oxmysql/lib/MySQL.lua to your resource manifests. This resource should be 100% backwards compatible with mysql-async functionality on top of providing newer export wrappers and functionality.

Refer to issue #77 for information on replacing your queries from older versions of oxmysql or ghmattimysql.

Features

  • Support for URI connection strings and semicolon separated values
  • Asynchronous queries utilising mysql2/promises connection pool
  • Javascript async_retval exports supports promises across resources and runtimes
  • Support for placeholder values (named and unnamed) to improve query speed and increase security against SQL injection
  • Improved error checking when placeholders and parameters do not match
  • Lua promises in lib/MySQL.lua files for improved performance when awaiting a response
  • Support mysql-async syntax while providing newer (more accurate) names

Usage

-- Lua
MySQL.query('SELECT * from users WHERE identifier = ?', {identifier}, function(result)
    -- callback response
    -- same as MySQL.Async.fetchAll
end)
CreateThread(function()
    local result = MySQL.query.await('SELECT * from users WHERE identifier = ?', {identifier})
    -- await a promise to resolve
    -- same as MySQL.Sync.fetchAll
end)
// JS
exports.oxmysql.query('SELECT * from users WHERE identifier = ?', [identifier], (result) => {
  // callback response
})(async () => {
  const result = await exports.oxmysql.query_async('SELECT * from users WHERE identifier = ?', [identifier]);
  // await a promise to resolve
})();
exports.oxmysql.query_async('SELECT * from users WHERE identifier = ?', [identifier]).then((result) => {
  // utilise .then to resolve a promise like a callback
});

For more information regarding the use of queries, refer to the documentation linked above.

Placeholders

This allows queries to be properly prepared and escaped; the following lines are equivalent.

"SELECT group FROM users WHERE identifier = ?", {identifier}
"SELECT group FROM users WHERE identifier = :identifier", {identifier = identifier}
"SELECT group FROM users WHERE identifier = @identifier", {['@identifier'] = identifier}

Named placeholders are deprecated and should be avoided as much as possible.







Discord


S
Description
MySQL resource for FX Server
Readme
2 MiB
0 Stars 1 Watchers 0 Forks
Languages
TypeScript 67.1%
Svelte 22.4%
Lua 5.1%
JavaScript 4.4%
CSS 0.5%
Other 0.5%