mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-03 14:38:50 +00:00
Update README.md
This commit is contained in:
1 parent
e67557992e
commit
571691c2f5
1 file changed
+17
-57
@@ -1,67 +1,27 @@
|
|||||||
<h1 align='center'><a href='https://overextended.github.io/docs/oxmysql/'>Documentation</a></h2>
|
# oxmysql
|
||||||
|
|
||||||
### Introduction
|
A FiveM resource to communicate with a MySQL database using [node-mysql2](https://github.com/sidorares/node-mysql2).
|
||||||
|
|
||||||
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).
|
## 📚 Documentation
|
||||||
|
|
||||||
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.
|
https://overextended.github.io/docs/oxmysql/
|
||||||
|
|
||||||
Refer to [issue #77](https://github.com/overextended/oxmysql/issues/77) for information on replacing your queries from older versions of oxmysql or ghmattimysql.
|
## 💾 Download
|
||||||
|
|
||||||
### Features
|
https://github.com/overextended/oxmysql/releases/latest/download/oxmysql.zip
|
||||||
|
|
||||||
- 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
|
## ✨ Features
|
||||||
|
|
||||||
```lua
|
- Support for mysql-async and ghmattimysql syntax.
|
||||||
-- Lua
|
- Promises / async query handling allowing for non-blocking and awaitable responses.
|
||||||
MySQL.query('SELECT * from users WHERE identifier = ?', {identifier}, function(result)
|
- Improved performance and stability compared to other options.
|
||||||
-- callback response
|
- Support for named and unnamed placeholders, improving performance and security.
|
||||||
-- same as MySQL.Async.fetchAll
|
- Support for URI connection strings and semicolon separated values.
|
||||||
end)
|
- Improved parameter checking and error handling.
|
||||||
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
|
## npm
|
||||||
// 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.
|
https://www.npmjs.com/package/@overextended/oxmysql
|
||||||
|
|
||||||
### 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.
|
|
||||||
|
|
||||||
<br><br><br><br><br>
|
|
||||||
|
|
||||||
<hr>
|
|
||||||
<p align='center'><a href='https://discord.gg/mEM6eYdXPm'>Discord</a></p>
|
|
||||||
<hr>
|
|
||||||
Reference in new issue
Block a user