From 5b55c8104656d53582d23e2b9244ca81c8afe438 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Fri, 8 Oct 2021 05:47:34 +1100 Subject: [PATCH] chore: Update readme --- README.md | 44 +++++++++++++++++++++++++++++++++++++++----- wrapper.lua | 2 +- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 824ba14..035b5e5 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,41 @@ -

oxmysql

Documentation

+

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). + +There are several incompatibilities in the provided API, meaning we cannot guarantee 100% success when using a "drag-and-drop" mentality. For convenience we have included `@oxmysql/lib/MySQL.lua` to replace mysql-async in your resource manifests. + +For more information regarding the use of queries, refer to the documentation linked above. + +### Features +- Support for URI connection strings and semicolon separated values +- Asynchronous queries utilising mysql2/promises connection pool +- Lua promises in the `wrapper.lua` and `lib/MySQL.lua` files for improved performance when using sync functions +- Javascript async_retval exports when using recent FX Server builds (requires wrapper.lua to be removed) +- 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 + +### Placeholders +This allows queries to be properly prepared and escaped, as well as improve query times for frequently accessed queries. +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} +``` + +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} +``` + + +




+

Discord

- -oxmysql is a middleware for FXServer which utilises [node-mysql2](https://github.com/sidorares/node-mysql2) to communicate with a database and respond with the query results. - -Calling the JS exports will result in async behaviour, or you can use the Lua exports to return a promise and await the response. +
\ No newline at end of file diff --git a/wrapper.lua b/wrapper.lua index cc8b9c6..309f15a 100644 --- a/wrapper.lua +++ b/wrapper.lua @@ -47,7 +47,7 @@ exports('singleSync', function(query, parameters) end) --- --- Execute query and fetch first column of first row +-- Execute query and fetch first column of first row -- -- @param query string -- @param parameters table