From 8874adc877785659f8ca86b76b6951ef792623ff Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Mon, 14 Feb 2022 22:29:33 +1100 Subject: [PATCH] chore: Update Discord link Also add note about named placeholders being deprecated. --- README.md | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 013b3f1..3c5f9e0 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,15 @@

Documentation

- ### Introduction -Oxmysql is an alternative to the unmaintained mysql-async/ghmattimysql resources, utilising [node-mysql2](https://github.com/sidorares/node-mysql2) rather than [mysqljs](https://github.com/mysqljs/mysql). + +Oxmysql is an alternative to the unmaintained mysql-async/ghmattimysql resources, utilising [node-mysql2](https://github.com/sidorares/node-mysql2) rather than [mysqljs](https://github.com/mysqljs/mysql). 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](https://github.com/overextended/oxmysql/issues/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 @@ -18,6 +19,7 @@ Refer to [issue #77](https://github.com/overextended/oxmysql/issues/77) for info - Support mysql-async syntax while providing newer (more accurate) names ### Usage + ```lua -- Lua MySQL.query('SELECT * from users WHERE identifier = ?', {identifier}), function(result) @@ -30,38 +32,36 @@ CreateThread(function() -- same as MySQL.Sync.fetchAll end) ``` + ```js // 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 -})() + // 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 -}) + // 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} +"SELECT group FROM users WHERE identifier = :identifier", {identifier = identifier} "SELECT group FROM users WHERE identifier = @identifier", {['@identifier'] = identifier} -``` -You can also use the following syntax when you are uncertain about the column to select. ``` -"SELECT ?? FROM users WHERE identifier = ?", {column, identifier} -instead of using -"SELECT "..column.." FROM users WHERE identifier = ?", {identifier} -``` +Named placeholders are deprecated and should be avoided as much as possible.




+
-

Discord

+

Discord