mirror of
https://github.com/darksaid98/overextended.github.io.git
synced 2026-12-03 22:20:54 +00:00
finish moving ox_mysql docs
This commit is contained in:
1 parent
7f636ad7e7
commit
b912eec843
6 files changed
+153
-149
No files matched your search
@@ -3,7 +3,7 @@ title: insert
|
|||||||
---
|
---
|
||||||
Inserts a new entry into the database and returns the insert id for the row, if valid.
|
Inserts a new entry into the database and returns the insert id for the row, if valid.
|
||||||
|
|
||||||
:::tip Example
|
:::info Example
|
||||||
Lua
|
Lua
|
||||||
|
|
||||||
**Callback**
|
**Callback**
|
||||||
@@ -23,19 +23,19 @@ local id = MySQL.insert.await('INSERT INTO users (identifier, firstname, lastnam
|
|||||||
print(id)
|
print(id)
|
||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
=== JavaScript"
|
JavaScript
|
||||||
**Callback**
|
|
||||||
```js
|
**Callback**
|
||||||
exports.oxmysql.insert('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ', [playerIdentifier,
|
```js
|
||||||
firstName, lastName], function(id) {
|
exports.oxmysql.insert('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ', [playerIdentifier, firstName, lastName], function(id) {
|
||||||
console.log(id)
|
console.log(id)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
**Promise**
|
**Promise**
|
||||||
```js
|
```js
|
||||||
(async () => {
|
(async () => {
|
||||||
const id = exports.oxmysql.insert_async('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ',
|
const id = exports.oxmysql.insert_async('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ',
|
||||||
[playerIdentifier, firstName, lastName]) {
|
[playerIdentifier, firstName, lastName]) {
|
||||||
console.log(id)
|
console.log(id)
|
||||||
})()
|
})()
|
||||||
```
|
```
|
||||||
@@ -10,61 +10,61 @@ Prepare can be used to execute frequently called queries faster and accepts mult
|
|||||||
|
|
||||||
When using SELECT, the return value will match `fetchAll, fetchSingle, or fetchScalar` depending on the number of columns and rows selected.
|
When using SELECT, the return value will match `fetchAll, fetchSingle, or fetchScalar` depending on the number of columns and rows selected.
|
||||||
|
|
||||||
!!! info "Example"
|
:::info Example
|
||||||
=== "Lua"
|
Lua
|
||||||
|
|
||||||
**Callback**
|
**Callback**
|
||||||
```lua
|
```lua
|
||||||
-- Alias: exports.oxmysql:prepare
|
-- Alias: exports.oxmysql:prepare
|
||||||
-- Alias: MySQL.Async.prepare
|
-- Alias: MySQL.Async.prepare
|
||||||
|
|
||||||
MySQL.prepare('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, function(result)
|
MySQL.prepare('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, function(result)
|
||||||
if result then
|
if result then
|
||||||
for _, v in pairs(result) do
|
for _, v in pairs(result) do
|
||||||
print(v.identifier, v.firstname, v.lastname)
|
print(v.identifier, v.firstname, v.lastname)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
**Promise**
|
**Promise**
|
||||||
```lua
|
```lua
|
||||||
-- Alias: exports.oxmysql:prepare_async
|
-- Alias: exports.oxmysql:prepare_async
|
||||||
-- Alias: MySQL.Sync.prepare
|
-- Alias: MySQL.Sync.prepare
|
||||||
|
|
||||||
|
CreateThread(function()
|
||||||
CreateThread(function()
|
|
||||||
local result = MySQL.prepare.await('SELECT * FROM users WHERE identifier = ?', {playerIdentifier})
|
local result = MySQL.prepare.await('SELECT * FROM users WHERE identifier = ?', {playerIdentifier})
|
||||||
if result then
|
if result then
|
||||||
for _, v in pairs(result) do
|
for _, v in pairs(result) do
|
||||||
print(v.identifier, v.firstname, v.lastname)
|
print(v.identifier, v.firstname, v.lastname)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
|
|
||||||
=== "JavaScript"
|
JavaScript
|
||||||
|
|
||||||
**Callback**
|
**Callback**
|
||||||
```js
|
```js
|
||||||
exports.oxmysql.prepare('SELECT * FROM users WHERE identifier = ?', [playerIdentifier], function(result) {
|
exports.oxmysql.prepare('SELECT * FROM users WHERE identifier = ?', [playerIdentifier], function(result) {
|
||||||
if (result) {
|
if (result) {
|
||||||
result.forEach((v) => {
|
result.forEach((v) => {
|
||||||
console.log(v.identifier, v.firstname, v.lastname)
|
console.log(v.identifier, v.firstname, v.lastname)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
**Promise**
|
**Promise**
|
||||||
```js
|
```js
|
||||||
(async () => {
|
(async () => {
|
||||||
const result = await exports.oxmysql.prepare_async('SELECT * FROM users WHERE identifier = ?', [playerIdentifier]) {
|
const result = await exports.oxmysql.prepare_async('SELECT * FROM users WHERE identifier = ?', [playerIdentifier]) {
|
||||||
if (result) {
|
if (result) {
|
||||||
result.forEach((v) => {
|
result.forEach((v) => {
|
||||||
console.log(v.identifier, v.firstname, v.lastname)
|
console.log(v.identifier, v.firstname, v.lastname)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})()
|
})()
|
||||||
```
|
```
|
||||||
|
:::
|
||||||
|
|
||||||
As mentioned above, you can utilise an array of parameters for a transaction-like query without the rollback; reducing the number of exports being performed reduces strain on the server. Included below is some examples of using prepare in ESX Legacy.
|
As mentioned above, you can utilise an array of parameters for a transaction-like query without the rollback; reducing the number of exports being performed reduces strain on the server. Included below is some examples of using prepare in ESX Legacy.
|
||||||
|
|
||||||
|
|||||||
+28
-27
@@ -4,57 +4,58 @@ title: query
|
|||||||
Generic function that can be utilised for any query.
|
Generic function that can be utilised for any query.
|
||||||
When selecting data it will return all matching rows and columns, otherwise it will return field data such as insertid, affectedRows, etc.
|
When selecting data it will return all matching rows and columns, otherwise it will return field data such as insertid, affectedRows, etc.
|
||||||
|
|
||||||
!!! info "Example"
|
:::info Example
|
||||||
=== "Lua"
|
Lua
|
||||||
|
|
||||||
**Callback**
|
**Callback**
|
||||||
```lua
|
```lua
|
||||||
-- Alias: exports.oxmysql:query
|
-- Alias: exports.oxmysql:query
|
||||||
-- Alias: MySQL.Async.query
|
-- Alias: MySQL.Async.query
|
||||||
|
|
||||||
MySQL.query('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, function(result)
|
MySQL.query('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, function(result)
|
||||||
if result then
|
if result then
|
||||||
for _, v in pairs(result) do
|
for _, v in pairs(result) do
|
||||||
print(v.identifier, v.firstname, v.lastname)
|
print(v.identifier, v.firstname, v.lastname)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
**Promise**
|
**Promise**
|
||||||
```lua
|
```lua
|
||||||
-- Alias: exports.oxmysql:query
|
-- Alias: exports.oxmysql:query
|
||||||
-- Alias: MySQL.Sync.query
|
-- Alias: MySQL.Sync.query
|
||||||
|
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
local result = MySQL.query.await('SELECT * FROM users WHERE identifier = ?', {playerIdentifier})
|
local result = MySQL.query.await('SELECT * FROM users WHERE identifier = ?', {playerIdentifier})
|
||||||
if result then
|
if result then
|
||||||
for _, v in pairs(result) do
|
for _, v in pairs(result) do
|
||||||
print(v.identifier, v.firstname, v.lastname)
|
print(v.identifier, v.firstname, v.lastname)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
|
|
||||||
=== "JavaScript"
|
JavaScript
|
||||||
|
|
||||||
**Callback**
|
**Callback**
|
||||||
```js
|
```js
|
||||||
exports.oxmysql.query('SELECT * FROM users WHERE identifier = ?', [playerIdentifier], function(result) {
|
exports.oxmysql.query('SELECT * FROM users WHERE identifier = ?', [playerIdentifier], function(result) {
|
||||||
if (result) {
|
if (result) {
|
||||||
result.forEach((v) => {
|
result.forEach((v) => {
|
||||||
console.log(v.identifier, v.firstname, v.lastname)
|
console.log(v.identifier, v.firstname, v.lastname)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
**Promise**
|
**Promise**
|
||||||
```js
|
```js
|
||||||
(async () => {
|
(async () => {
|
||||||
const result = await exports.oxmysql.query_async('SELECT * FROM users WHERE identifier = ?', [playerIdentifier]) {
|
const result = await exports.oxmysql.query_async('SELECT * FROM users WHERE identifier = ?', [playerIdentifier]) {
|
||||||
if (result) {
|
if (result) {
|
||||||
result.forEach((v) => {
|
result.forEach((v) => {
|
||||||
console.log(v.identifier, v.firstname, v.lastname)
|
console.log(v.identifier, v.firstname, v.lastname)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})()
|
})()
|
||||||
```
|
```
|
||||||
|
:::
|
||||||
@@ -3,41 +3,42 @@ title: scalar
|
|||||||
---
|
---
|
||||||
Returns the first column for a single row.
|
Returns the first column for a single row.
|
||||||
|
|
||||||
!!! info "Example"
|
:::info Example
|
||||||
=== "Lua"
|
Lua
|
||||||
|
|
||||||
**Callback**
|
**Callback**
|
||||||
```lua
|
```lua
|
||||||
-- Alias: exports.oxmysql:scalar
|
-- Alias: exports.oxmysql:scalar
|
||||||
-- Alias: MySQL.Async.fetchScalar
|
-- Alias: MySQL.Async.fetchScalar
|
||||||
|
|
||||||
MySQL.scalar('SELECT firstname FROM users WHERE identifier = ?', {playerIdentifier}, function(firstname)
|
MySQL.scalar('SELECT firstname FROM users WHERE identifier = ?', {playerIdentifier}, function(firstname)
|
||||||
print(firstname)
|
print(firstname)
|
||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
**Promise**
|
**Promise**
|
||||||
```lua
|
```lua
|
||||||
-- Alias: exports.oxmysql:scalar_async
|
-- Alias: exports.oxmysql:scalar_async
|
||||||
-- Alias: MySQL.Sync.fetchScalar
|
-- Alias: MySQL.Sync.fetchScalar
|
||||||
|
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
local firstname = MySQL.scalar.await('SELECT firstname FROM users WHERE identifier = ?', {playerIdentifier})
|
local firstname = MySQL.scalar.await('SELECT firstname FROM users WHERE identifier = ?', {playerIdentifier})
|
||||||
print(firstname)
|
print(firstname)
|
||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
|
|
||||||
=== "JavaScript"
|
JavaScript
|
||||||
|
|
||||||
**Callback**
|
**Callback**
|
||||||
```js
|
```js
|
||||||
exports.oxmysql.scalar('SELECT firstname FROM users WHERE identifier = ?', [playerIdentifier], function(firstname) {
|
exports.oxmysql.scalar('SELECT firstname FROM users WHERE identifier = ?', [playerIdentifier], function(firstname) {
|
||||||
console.log(firstname)
|
console.log(firstname)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
**Promise**
|
**Promise**
|
||||||
```js
|
```js
|
||||||
(async () => {
|
(async () => {
|
||||||
const firstname = await exports.oxmysql.scalar_async('SELECT firstname FROM users WHERE identifier = ?', [playerIdentifier]) {
|
const firstname = await exports.oxmysql.scalar_async('SELECT firstname FROM users WHERE identifier = ?', [playerIdentifier]) {
|
||||||
console.log(firstname)
|
console.log(firstname)
|
||||||
})()
|
})()
|
||||||
```
|
```
|
||||||
|
:::
|
||||||
@@ -3,47 +3,48 @@ title: single
|
|||||||
---
|
---
|
||||||
Returns the columns for a single row.
|
Returns the columns for a single row.
|
||||||
|
|
||||||
!!! info "Example"
|
:::info Example
|
||||||
=== "Lua"
|
Lua
|
||||||
|
|
||||||
**Callback**
|
**Callback**
|
||||||
```lua
|
```lua
|
||||||
-- Alias: exports.oxmysql:single
|
-- Alias: exports.oxmysql:single
|
||||||
-- Alias: MySQL.Async.fetchSingle
|
-- Alias: MySQL.Async.fetchSingle
|
||||||
|
|
||||||
MySQL.single('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, function(result)
|
MySQL.single('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, function(result)
|
||||||
if result then
|
if result then
|
||||||
print(result.identifier, result.firstname, result.lastname)
|
print(result.identifier, result.firstname, result.lastname)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
**Promise**
|
**Promise**
|
||||||
```lua
|
```lua
|
||||||
-- Alias: exports.oxmysql:single_async
|
-- Alias: exports.oxmysql:single_async
|
||||||
-- Alias: MySQL.Sync.fetchSingle
|
-- Alias: MySQL.Sync.fetchSingle
|
||||||
|
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
local result = MySQL.single.await('SELECT * FROM users WHERE identifier = ?', {playerIdentifier})
|
local result = MySQL.single.await('SELECT * FROM users WHERE identifier = ?', {playerIdentifier})
|
||||||
if result then
|
if result then
|
||||||
print(result.identifier, result.firstname, result.lastname)
|
print(result.identifier, result.firstname, result.lastname)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
|
|
||||||
=== "JavaScript"
|
JavaScript
|
||||||
|
|
||||||
**Callback**
|
**Callback**
|
||||||
```js
|
```js
|
||||||
exports.oxmysql.single('SELECT * FROM users WHERE identifier = ?', [playerIdentifier], function(result) {
|
exports.oxmysql.single('SELECT * FROM users WHERE identifier = ?', [playerIdentifier], function(result) {
|
||||||
if (result)
|
if (result)
|
||||||
console.log(result.identifier, result.firstname, result.lastname)
|
console.log(result.identifier, result.firstname, result.lastname)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
**Promise**
|
**Promise**
|
||||||
```js
|
```js
|
||||||
setImmediate(async () => {
|
setImmediate(async () => {
|
||||||
const result = await exports.oxmysql.single_async('SELECT * FROM users WHERE identifier = ?', [playerIdentifier]) {
|
const result = await exports.oxmysql.single_async('SELECT * FROM users WHERE identifier = ?', [playerIdentifier]) {
|
||||||
if (result)
|
if (result)
|
||||||
console.log(result.identifier, result.firstname, result.lastname)
|
console.log(result.identifier, result.firstname, result.lastname)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
:::
|
||||||
@@ -3,47 +3,48 @@ title: update
|
|||||||
---
|
---
|
||||||
Returns the number of affected rows by the query.
|
Returns the number of affected rows by the query.
|
||||||
|
|
||||||
!!! info "Example"
|
:::info Example
|
||||||
=== "Lua"
|
Lua
|
||||||
|
|
||||||
**Callback**
|
**Callback**
|
||||||
```lua
|
```lua
|
||||||
-- Alias: exports.oxmysql:update
|
-- Alias: exports.oxmysql:update
|
||||||
-- Alias: MySQL.Async.update
|
-- Alias: MySQL.Async.update
|
||||||
|
|
||||||
MySQL.Async.update('UPDATE users SET firstname = ? WHERE identifier = ? ', {newName, playerIdentifier}, function(affectedRows)
|
MySQL.Async.update('UPDATE users SET firstname = ? WHERE identifier = ? ', {newName, playerIdentifier}, function(affectedRows)
|
||||||
if affectedRows then
|
if affectedRows then
|
||||||
print(affectedRows)
|
print(affectedRows)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
**Promise**
|
**Promise**
|
||||||
```lua
|
```lua
|
||||||
-- Alias: exports.oxmysql:update_async
|
-- Alias: exports.oxmysql:update_async
|
||||||
-- Alias: MySQL.update
|
-- Alias: MySQL.update
|
||||||
|
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
local affectedRows = MySQL.update.await('UPDATE users SET firstname = ? WHERE identifier = ? ', {newName, playerIdentifier})
|
local affectedRows = MySQL.update.await('UPDATE users SET firstname = ? WHERE identifier = ? ', {newName, playerIdentifier})
|
||||||
if affectedRows then
|
if affectedRows then
|
||||||
print(affectedRows)
|
print(affectedRows)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
|
|
||||||
=== "JavaScript"
|
JavaScript
|
||||||
|
|
||||||
**Callback**
|
**Callback**
|
||||||
```js
|
```js
|
||||||
exports.oxmysql.update('UPDATE users SET firstname = ? WHERE identifier = ? ', [newName, playerIdentifier], function(affectedRows) {
|
exports.oxmysql.update('UPDATE users SET firstname = ? WHERE identifier = ? ', [newName, playerIdentifier], function(affectedRows) {
|
||||||
if (affectedRows)
|
if (affectedRows)
|
||||||
console.log(affectedRows)
|
console.log(affectedRows)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
**Promise**
|
**Promise**
|
||||||
```js
|
```js
|
||||||
setImmediate(async () => {
|
setImmediate(async () => {
|
||||||
const id = exports.oxmysql.update_async('UPDATE users SET firstname = ? WHERE identifier = ? ', [newName, playerIdentifier]) {
|
const id = exports.oxmysql.update_async('UPDATE users SET firstname = ? WHERE identifier = ? ', [newName, playerIdentifier]) {
|
||||||
if (affectedRows)
|
if (affectedRows)
|
||||||
console.log(affectedRows)
|
console.log(affectedRows)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
:::
|
||||||
Reference in new issue
Block a user