chore: Update Discord link

Also add note about named placeholders being deprecated.
This commit is contained in:
Linden committed 2022-02-14 22:29:33 +11:00
1 parent 86e51e79ef
commit 8874adc877
1 file changed
+19 -19
+19 -19
View File
@@ -1,14 +1,15 @@
<h1 align='center'><a href='https://overextended.github.io/oxmysql/'>Documentation</a></h2> <h1 align='center'><a href='https://overextended.github.io/oxmysql/'>Documentation</a></h2>
### Introduction ### 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. 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. 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 ### Features
- Support for URI connection strings and semicolon separated values - Support for URI connection strings and semicolon separated values
- Asynchronous queries utilising mysql2/promises connection pool - Asynchronous queries utilising mysql2/promises connection pool
- Javascript async_retval exports supports promises across resources and runtimes - 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 - Support mysql-async syntax while providing newer (more accurate) names
### Usage ### Usage
```lua ```lua
-- Lua -- Lua
MySQL.query('SELECT * from users WHERE identifier = ?', {identifier}), function(result) MySQL.query('SELECT * from users WHERE identifier = ?', {identifier}), function(result)
@@ -30,38 +32,36 @@ CreateThread(function()
-- same as MySQL.Sync.fetchAll -- same as MySQL.Sync.fetchAll
end) end)
``` ```
```js ```js
// JS // JS
exports.oxmysql.query('SELECT * from users WHERE identifier = ?', [identifier], (result) => { exports.oxmysql.query('SELECT * from users WHERE identifier = ?', [identifier], (result) => {
// callback response // callback response
}) })(async () => {
(async() => { const result = await exports.oxmysql.query_async('SELECT * from users WHERE identifier = ?', [identifier]);
const result = await exports.oxmysql.query_async('SELECT * from users WHERE identifier = ?', [identifier]) // await a promise to resolve
// await a promise to resolve })();
})()
exports.oxmysql.query_async('SELECT * from users WHERE identifier = ?', [identifier]).then((result) => { 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. For more information regarding the use of queries, refer to the documentation linked above.
### Placeholders ### Placeholders
This allows queries to be properly prepared and escaped; the following lines are equivalent. 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}
"SELECT group FROM users WHERE identifier = :identifier", {identifier = identifier} "SELECT group FROM users WHERE identifier = :identifier", {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.
<br><br><br><br><br> <br><br><br><br><br>
<hr> <hr>
<p align='center'><a href='https://discord.io/overextended'>Discord</a></p> <p align='center'><a href='https://discord.gg/overextended'>Discord</a></p>
<hr> <hr>