mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-02 06:28:54 +00:00
Include some js samples
This commit is contained in:
1 parent
7ac73ccdb4
commit
93754a8efc
6 files changed
+60
-26
No files matched your search
+11
-5
@@ -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)
|
||||
```
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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}`)
|
||||
```
|
||||
@@ -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)
|
||||
```
|
||||
@@ -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)
|
||||
```
|
||||
@@ -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`)
|
||||
```
|
||||
Reference in new issue
Block a user