mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-02 14:38:50 +00:00
Rename directory and fix JS Sync examples
This commit is contained in:
1 parent
2b40fafa7f
commit
9af6205bb7
8 files changed
+3
-3
No files matched your search
@@ -0,0 +1,47 @@
|
||||
---
|
||||
title: Execute
|
||||
---
|
||||
Generic function that can be utilised for any query, synonymous with fetch.
|
||||
When selecting data it will return all matching rows and columns, otherwise it will return field data such as insertid, affectedRows, etc.
|
||||
|
||||
!!! info "Example"
|
||||
=== "Lua"
|
||||
**Async**
|
||||
```lua
|
||||
exports.oxmysql:execute('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, function(result)
|
||||
if result then
|
||||
for _, v in pairs(result) do
|
||||
print(v.identifier, v.firstname, v.lastname)
|
||||
end
|
||||
end
|
||||
end)
|
||||
```
|
||||
**Sync**
|
||||
```lua
|
||||
local result = exports.oxmysql:executeSync('SELECT * FROM users WHERE identifier = ?', {playerIdentifier})
|
||||
if result then
|
||||
for _, v in pairs(result) do
|
||||
print(v.identifier, v.firstname, v.lastname)
|
||||
end
|
||||
end
|
||||
```
|
||||
=== "JavaScript"
|
||||
**Async**
|
||||
```js
|
||||
exports.oxmysql.execute('SELECT * FROM users WHERE identifier = ?', [playerIdentifier], function(result) {
|
||||
if (result) {
|
||||
result.forEach((v) => {
|
||||
console.log(v.identifier, v.firstname, v.lastname)
|
||||
})
|
||||
}
|
||||
})
|
||||
```
|
||||
**Sync**
|
||||
```js
|
||||
const result = await exports.oxmysql.executeSync('SELECT * FROM users WHERE identifier = ?', [playerIdentifier]) {
|
||||
if (result) {
|
||||
result.forEach((v) => {
|
||||
console.log(v.identifier, v.firstname, v.lastname)
|
||||
})
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,3 @@
|
||||
---
|
||||
title: Index
|
||||
---
|
||||
@@ -0,0 +1,36 @@
|
||||
---
|
||||
title: Insert
|
||||
---
|
||||
Inserts a new entry into the database and returns the insert id for the row, if valid.
|
||||
|
||||
!!! info "Example"
|
||||
=== "Lua"
|
||||
**Async**
|
||||
```lua
|
||||
exports.oxmysql:insert('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ', {playerIdentifier, firstName, lastName}, function(id)
|
||||
if id then
|
||||
print(id)
|
||||
end
|
||||
end)
|
||||
```
|
||||
**Sync**
|
||||
```lua
|
||||
local id = exports.oxmysql:insertSync('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ', {playerIdentifier, firstName, lastName})
|
||||
if id then
|
||||
print(id)
|
||||
end
|
||||
```
|
||||
=== "JavaScript"
|
||||
**Async**
|
||||
```js
|
||||
exports.oxmysql.insert('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ', [playerIdentifier, firstName, lastName], function(id) {
|
||||
if (id)
|
||||
console.log(id)
|
||||
})
|
||||
```
|
||||
**Sync**
|
||||
```js
|
||||
const id = exports.oxmysql.insertSync('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ', [playerIdentifier, firstName, lastName]) {
|
||||
if (id)
|
||||
console.log(id)
|
||||
```
|
||||
@@ -0,0 +1 @@
|
||||
TODO
|
||||
@@ -0,0 +1,36 @@
|
||||
---
|
||||
title: Scalar
|
||||
---
|
||||
Returns the first column for a single row.
|
||||
|
||||
!!! info "Example"
|
||||
=== "Lua"
|
||||
**Async**
|
||||
```lua
|
||||
exports.oxmysql:scalar('SELECT firstname FROM users WHERE identifier = ?', {playerIdentifier}, function(result)
|
||||
if result then
|
||||
print(result.firstname)
|
||||
end
|
||||
end)
|
||||
```
|
||||
**Sync**
|
||||
```lua
|
||||
local result = exports.oxmysql:scalarSync('SELECT firstname FROM users WHERE identifier = ?', {playerIdentifier})
|
||||
if result then
|
||||
print(result.firstname)
|
||||
end
|
||||
```
|
||||
=== "JavaScript"
|
||||
**Async**
|
||||
```js
|
||||
exports.oxmysql.scalar('SELECT firstname FROM users WHERE identifier = ?', [playerIdentifier], function(result) {
|
||||
if (result)
|
||||
console.log(result.firstname)
|
||||
})
|
||||
```
|
||||
**Sync**
|
||||
```js
|
||||
const result = await exports.oxmysql.scalarSync('SELECT firstname FROM users WHERE identifier = ?', [playerIdentifier]) {
|
||||
if (result)
|
||||
console.log(result.firstname)
|
||||
```
|
||||
@@ -0,0 +1,36 @@
|
||||
---
|
||||
title: Single
|
||||
---
|
||||
Returns the columns for a single row.
|
||||
|
||||
!!! info "Example"
|
||||
=== "Lua"
|
||||
**Async**
|
||||
```lua
|
||||
exports.oxmysql:single('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, function(result)
|
||||
if result then
|
||||
print(result.identifier, result.firstname, result.lastname)
|
||||
end
|
||||
end)
|
||||
```
|
||||
**Sync**
|
||||
```lua
|
||||
local result = exports.oxmysql:singleSync('SELECT * FROM users WHERE identifier = ?', {playerIdentifier})
|
||||
if result then
|
||||
print(result.identifier, result.firstname, result.lastname)
|
||||
end
|
||||
```
|
||||
=== "JavaScript"
|
||||
**Async**
|
||||
```js
|
||||
exports.oxmysql.single('SELECT * FROM users WHERE identifier = ?', [playerIdentifier], function(result) {
|
||||
if (result)
|
||||
console.log(result.identifier, result.firstname, result.lastname)
|
||||
})
|
||||
```
|
||||
**Sync**
|
||||
```js
|
||||
const result = await exports.oxmysql.singleSync('SELECT * FROM users WHERE identifier = ?', [playerIdentifier]) {
|
||||
if (result)
|
||||
console.log(result.identifier, result.firstname, result.lastname)
|
||||
```
|
||||
@@ -0,0 +1,102 @@
|
||||
TODO: update information and formatting
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Transactions
|
||||
A transaction executes multiple queries and commits them only if all succeed. If one fails, none of the queries are committed. The return value is a `boolean`, which is the result of the transaction.
|
||||
|
||||
## Specific Format
|
||||
When using the `Specific` format you must pass one parameter to the oxmysql export. In this case, the `queries` parameter contains your queries and the SQL variables unique to each query.
|
||||
|
||||
This is useful for transactions where the queries do not share many SQL variables.
|
||||
|
||||
### Usage
|
||||
Lua
|
||||
```lua
|
||||
local queries = {
|
||||
{ query = 'INSERT INTO `test` (id) VALUES (:someid)', values = { ['someid'] = 1 } },
|
||||
{ query = 'INSERT INTO `test` (id) VALUES (:someid)', values = { ['someid'] = 2 } }
|
||||
} -- NOTE, the 'values' tables can be named 'parameters' here for MySQL-Async compatibility.
|
||||
|
||||
-- Async
|
||||
exports.oxmysql:transaction(queries, function(result)
|
||||
print(result)
|
||||
end)
|
||||
|
||||
-- Sync
|
||||
local result = exports.oxmysql:transactionSync(queries)
|
||||
print(result)
|
||||
```
|
||||
|
||||
JavaScript
|
||||
```js
|
||||
const queries = [
|
||||
{ query = 'INSERT INTO `test` (id) VALUES (:someid)', values = { someid = 1 } },
|
||||
{ query = 'INSERT INTO `test` (id) VALUES (:someid)', values = { someid = 2 } }
|
||||
] // NOTE, the 'values' objects can be named 'parameters' here for MySQL-Async compatibility.
|
||||
|
||||
// Async
|
||||
exports.oxmysql.transaction(queries, (result) => {
|
||||
console.log(result)
|
||||
})
|
||||
|
||||
// Sync
|
||||
const result = await exports.oxmysql.transactionSync(queries)
|
||||
console.log(result)
|
||||
```
|
||||
|
||||
### Shared Format
|
||||
When using the `Shared` format you must pass two parameters to the oxmysql export. The `queries` and the `parameters` those queries will use.
|
||||
This is useful if your queries use the same SQL variables.
|
||||
|
||||
Lua
|
||||
```lua
|
||||
local queries = {
|
||||
'INSERT INTO `test` (id, name) VALUES (:someid, :somename)',
|
||||
'SET `name` = :newname IN `test` WHERE `id` = :someid'
|
||||
}
|
||||
|
||||
local parameters = { ['someid'] = 2, ['somename'] = 'John Doe', ['newname'] = 'John Notdoe' }
|
||||
|
||||
-- Async
|
||||
exports.oxmysql:transaction(queries, parameters, function(result)
|
||||
print(result)
|
||||
end)
|
||||
|
||||
-- Sync
|
||||
local result = exports.oxmysql:transactionSync(queries, parameters)
|
||||
print(result)
|
||||
```
|
||||
|
||||
JavaScript
|
||||
```js
|
||||
const queries = [
|
||||
'INSERT INTO `test` (id, name) VALUES (:someid, :somename)',
|
||||
'SET `name` = :newname IN `test` WHERE `id` = :someid'
|
||||
]
|
||||
|
||||
const parameters = { someid = 2, somename = 'John Doe', newname = 'John Notdoe' }
|
||||
|
||||
// Async
|
||||
exports.oxmysql.transaction(queries, parameters, (result) => {
|
||||
console.log(result)
|
||||
})
|
||||
|
||||
// Sync
|
||||
const result = await exports.oxmysql.transactionSync(queries, parameters)
|
||||
console.log(result)
|
||||
```
|
||||
|
||||
## Transaction Isolation Level
|
||||
|
||||
This can be set through the convar `mysql_transaction_isolation_level` which should be an integer ranging from `1-4`. The default convar value set by oxmysql is `2`.
|
||||
|
||||
|
||||
| Convar Value | Result |
|
||||
| -------------- | ------------------ |
|
||||
| 1 | Repeatable Read |
|
||||
| 2 | Read Committed |
|
||||
| 3 | Read Uncommitted |
|
||||
| 4 | Serializable |
|
||||
@@ -0,0 +1,36 @@
|
||||
---
|
||||
title: Update
|
||||
---
|
||||
Updates an entry in the database and returns the number of affected rows.
|
||||
|
||||
!!! info "Example"
|
||||
=== "Lua"
|
||||
**Async**
|
||||
```lua
|
||||
exports.oxmysql:insert('UPDATE users SET firstname = ? WHERE identifier = ? ', {newName, playerIdentifier}, function(affectedRows)
|
||||
if affectedRows then
|
||||
print(affectedRows)
|
||||
end
|
||||
end)
|
||||
```
|
||||
**Sync**
|
||||
```lua
|
||||
local id = exports.oxmysql:insertSync('UPDATE users SET firstname = ? WHERE identifier = ? ', {newName, playerIdentifier})
|
||||
if affectedRows then
|
||||
print(affectedRows)
|
||||
end
|
||||
```
|
||||
=== "JavaScript"
|
||||
**Async**
|
||||
```js
|
||||
exports.oxmysql.insert('UPDATE users SET firstname = ? WHERE identifier = ? ', [newName, playerIdentifier], function(affectedRows) {
|
||||
if (affectedRows)
|
||||
console.log(affectedRows)
|
||||
})
|
||||
```
|
||||
**Sync**
|
||||
```js
|
||||
const id = exports.oxmysql.insertSync('UPDATE users SET firstname = ? WHERE identifier = ? ', [newName, playerIdentifier]) {
|
||||
if (affectedRows)
|
||||
console.log(affectedRows)
|
||||
```
|
||||
Reference in new issue
Block a user