diff --git a/execute.md b/execute.md index e65388c..3caee4e 100644 --- a/execute.md +++ b/execute.md @@ -4,11 +4,17 @@ Execute a query and returns an array of all results. This is synonymous with the ### Usage ```lua exports.oxmysql:execute(query, {}, function(result) - print(result[1]['column1'], result[1]['column2'], result[2]['column1'], result[2]['column2']) + print(result[1].column1, result[2].column1) end) -print('I will be printed before query result') -``` -```lua + local result = exports.oxmysql:executeSync(query, {}) -print(result[1]['column1'], result[1]['column2'], result[2]['column1'], result[2]['column2']) +print(result[1].column1, result[2].column1) +``` +```js +exports.oxmysql.execute(query, {}, (result) => { + console.log(result[1].column1, result[2].column1) +}) + +const result = await exports.oxmysql.executeSync(query, {}) +console.log(result[1].column1, result[2].column1) ``` diff --git a/index.md b/index.md index a0ce78e..f074c5e 100644 --- a/index.md +++ b/index.md @@ -2,22 +2,26 @@ ## Introduction -oxmysql is a database wrapper for FiveM utilising [node-mysql2](https://github.com/sidorares/node-mysql2) offering improved performance and security. +oxmysql is a database wrapper for FiveM utilising [node-mysql2](https://github.com/sidorares/node-mysql2) offering improved performance and security. ### Query cache -Every executed query is being prepared and stored into cache for faster performance using prepared statements. These statements are also being sanitized from vulnerable SQL injection +Every executed query is being prepared and stored into cache for faster performance when using prepared statements. These statements are also being sanitized from vulnerable SQL injection. + +The following syntaxes are all supported. ```lua 'SELECT * FROM `users` WHERE `identifier` = ? AND `group` = ?', { playerIdentifier, playerGroup } +'SELECT * FROM `users` WHERE ?? = ? AND ?? = ?', {'identifier', playerIdentifier, 'group', playerGroup} +'SELECT * FROM `users` WHERE identifier = :identifier', {identifier=playerIdentifier} +'SELECT * FROM `users` WHERE identifier = @identifier', {['@identifier']=playerIdentifier} ``` ### Installation * Download `oxmysql.zip` from https://github.com/overextended/oxmysql/releases/latest -* Put `oxmysql` in the `resources` folder -* Configure in `server.cfg` -* Put `ensure oxmysql` before your resources +* Extract `oxmysql` to your resources folder +* Add `ensure oxmysql` before your resources in `server.cfg` ### Configuration diff --git a/insert.md b/insert.md index 6c2a200..df4a17d 100644 --- a/insert.md +++ b/insert.md @@ -1,14 +1,20 @@ # Insert -Execute a query and returns the AUTO_INCREMENT id, if it is defined. +Execute a query and returns the AUTO_INCREMENT id, if valid. ### Usage ```lua exports.oxmysql:insert(query, {}, function(insertId) print('Inserted new row with id '..insertId) end) -print('I will be printed before query result') -``` -```lua + local insertId = exports.oxmysql:insertSync(query, {}) print('Inserted new row with id '..insertId) ``` +```js +exports.oxmysql.insert(query, {}, (insertId) => { + console.log(`Inserted new row with id ${insertId}`) +}) + +const insertId = await exports.oxmysql.insertSync(query, {}) +console.log(`Inserted new row with id ${insertId}`) +``` diff --git a/scalar.md b/scalar.md index a7d1c05..4e5dd2d 100644 --- a/scalar.md +++ b/scalar.md @@ -6,9 +6,15 @@ Execute a query and return the result of the first row and column. exports.oxmysql:scalar(query, {}, function(result) print(result) end) -print('I will be printed before query result') -``` -```lua + local result = exports.oxmysql:scalarSync(query, {}) print(result) ``` +```js +exports.oxmysql.scalar(query, {}, (result) => { + console.log(result) +}) + +const result = await exports.oxmysql.scalarSync(query, {}) +console.log(result) +``` diff --git a/single.md b/single.md index de1dd98..d059316 100644 --- a/single.md +++ b/single.md @@ -4,11 +4,17 @@ Execute a query and return the results of the first row. ### Usage ```lua exports.oxmysql:single(query, {}, function(result) - print(result['column']) + print(result.column1, result.column2) end) -print('I will be printed before query result') -``` -```lua + local result = exports.oxmysql:singleSync(query, {}) -print(result['column']) +print(result.column1, result.column2) +``` +```js +exports.oxmysql.single(query, {}, (result) => { + console.log(result.column1, result.column2) +}) + +const result = await exports.oxmysql.singleSync(query, {}) +console.log(result.column1, result.column2) ``` diff --git a/update.md b/update.md index 2714a8a..81c7538 100644 --- a/update.md +++ b/update.md @@ -1,14 +1,20 @@ # Update -Execute a query and returns the number of affected rows. +Execute a query and returns the number of affected rows when updating rows. ### Usage ```lua exports.oxmysql:update(query, {}, function(affectedRows) print('Updated '..affectedRows..' rows') end) -print('I will be printed before query result') -``` -```lua + local affectedRows = exports.oxmysql:updateSync(query, {}) print('Updated '..affectedRows..' rows') ``` +```js +exports.oxmysql.update(query, {}, (affectedRows) => { + console.log(`Updated ${affectedRows} rows`) +}) + +const affectedRows = await exports.oxmysql.updateSync(query, {}) +console.log(`Updated ${affectedRows} rows`) +```