mirror of
https://github.com/darksaid98/overextended.github.io.git
synced 2026-12-02 22:22:46 +00:00
rewrite oxmysql docs
This commit is contained in:
1 parent
864a1b3858
commit
3298244c9a
17 files changed
+630
-520
No files matched your search
@@ -1,60 +1,78 @@
|
||||
# Prepare
|
||||
---
|
||||
title: Prepare
|
||||
---
|
||||
|
||||
The only function that provides true [prepared statements](https://github.com/sidorares/node-mysql2#using-prepared-statements), granting native protection and query planning by MySQL.
|
||||
import Tabs from '@theme/Tabs';
|
||||
import TabItem from '@theme/TabItem';
|
||||
|
||||
The only function that provides true prepared statements, granting native protection and query planning by MySQL.
|
||||
Prepare can be used to execute frequently called queries faster and accepts multiple sets of parameters to be used with a single query.
|
||||
|
||||
- Date will not return the datestring commonly used in FiveM
|
||||
- TINYINT 1 and BIT will not return a boolean
|
||||
- You can only use `?` value placeholders, `??` column placeholders and named placeholders will throw an error
|
||||
- You can only use ? value placeholders, ?? column placeholders and named placeholders will throw an error
|
||||
|
||||
When using SELECT, the return value will match `query, single, or scalar` depending on the number of columns and rows selected.
|
||||
When using SELECT, the return value will match `query`, `single`, or `scalar` depending on the number of columns and rows selected.
|
||||
|
||||
## Lua
|
||||
## Promise
|
||||
|
||||
### Callback
|
||||
<Tabs>
|
||||
<TabItem value="1" label="Lua">
|
||||
|
||||
```lua
|
||||
-- alias: exports.oxmysql:prepare
|
||||
local response = MySQL.prepare.await('SELECT `firstname`, `lastname` FROM `users` WHERE `identifier` = ?', {
|
||||
identifier
|
||||
})
|
||||
|
||||
MySQL.prepare('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, function(result)
|
||||
if result then
|
||||
print(json.encode(result, {indent=true}))
|
||||
end
|
||||
|
||||
print(json.encode(response, { indent = true, sort_keys = true }))
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
<TabItem value="2" label="JS">
|
||||
|
||||
```js
|
||||
const response = await MySQL.prepare('SELECT `firstname`, `lastname` FROM `users` WHERE `identifier` = ?', [
|
||||
identifier
|
||||
])
|
||||
|
||||
console.log(JSON.stringify(response))
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
**Aliases**
|
||||
|
||||
- `exports.oxmysql.prepare_async`
|
||||
|
||||
## Callback
|
||||
|
||||
<Tabs>
|
||||
<TabItem value="1" label="Lua">
|
||||
|
||||
```lua
|
||||
MySQL.prepare('SELECT `firstname`, `lastname` FROM `users` WHERE `identifier` = ?', {
|
||||
identifier
|
||||
}, function(response)
|
||||
print(json.encode(response, { indent = true, sort_keys = true }))
|
||||
end)
|
||||
```
|
||||
|
||||
### Promise
|
||||
|
||||
```lua
|
||||
-- alias: exports.oxmysql:prepare_async
|
||||
|
||||
local result = MySQL.prepare.await('SELECT * FROM users WHERE identifier = ?', {playerIdentifier})
|
||||
if result then
|
||||
print(json.encode(result, {indent=true}))
|
||||
end
|
||||
```
|
||||
|
||||
## JavaScript
|
||||
|
||||
### Callback
|
||||
</TabItem>
|
||||
<TabItem value="2" label="JS">
|
||||
|
||||
```js
|
||||
// alias: exports.oxmysql.prepare
|
||||
|
||||
MySQL.prepare('SELECT * FROM users WHERE identifier = ?', [playerIdentifier], (result) => {
|
||||
if (result) {
|
||||
console.log(result.identifier, result.firstname, result.lastname)
|
||||
}
|
||||
MySQL.prepare('SELECT `firstname`, `lastname` FROM `users` WHERE `identifier` = ?', [
|
||||
identifier
|
||||
], (response) => {
|
||||
console.log(JSON.stringify(response))
|
||||
})
|
||||
```
|
||||
|
||||
### Promise
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
```js
|
||||
// alias: exports.oxmysql.prepare_async
|
||||
**Aliases**
|
||||
|
||||
const result = await MySQL.prepare_async('SELECT * FROM users WHERE identifier = ?', [playerIdentifier])
|
||||
if (result) {
|
||||
console.log(result.identifier, result.firstname, result.lastname)
|
||||
}
|
||||
```
|
||||
- `exports.oxmysql.prepare`
|
||||
Reference in new issue
Block a user