mirror of
https://github.com/darksaid98/overextended.github.io.git
synced 2026-12-01 14:38:50 +00:00
* refactor: Add h1 headers to all pages missing it * refactor: missed example h3 * change hooks example heading to bold text --------- Co-authored-by: Luke <[email protected]>
79 lines
1.7 KiB
Plaintext
79 lines
1.7 KiB
Plaintext
---
|
|
title: prepare
|
|
---
|
|
|
|
import { Tab, Tabs } from 'nextra-theme-docs';
|
|
|
|
# Prepare
|
|
|
|
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
|
|
|
|
Unlike [rawExecute](./rawExecute), the SELECT statement will return a column, row, or array of rows depending on the number of columns and rows selected.
|
|
|
|
## Promise
|
|
|
|
<Tabs items={['Lua', 'JS']}>
|
|
<Tab>
|
|
|
|
```lua
|
|
local response = MySQL.prepare.await('SELECT `firstname`, `lastname` FROM `users` WHERE `identifier` = ?', {
|
|
identifier
|
|
})
|
|
|
|
|
|
print(json.encode(response, { indent = true, sort_keys = true }))
|
|
```
|
|
|
|
</Tab>
|
|
<Tab>
|
|
|
|
```js
|
|
const response = await MySQL.prepare('SELECT `firstname`, `lastname` FROM `users` WHERE `identifier` = ?', [
|
|
identifier
|
|
])
|
|
|
|
console.log(JSON.stringify(response))
|
|
```
|
|
|
|
</Tab>
|
|
</Tabs>
|
|
|
|
**Aliases**
|
|
|
|
- `exports.oxmysql.prepare_async`
|
|
|
|
## Callback
|
|
|
|
<Tabs items={['Lua', 'JS']}>
|
|
<Tab>
|
|
|
|
```lua
|
|
MySQL.prepare('SELECT `firstname`, `lastname` FROM `users` WHERE `identifier` = ?', {
|
|
identifier
|
|
}, function(response)
|
|
print(json.encode(response, { indent = true, sort_keys = true }))
|
|
end)
|
|
```
|
|
|
|
</Tab>
|
|
<Tab>
|
|
|
|
```js
|
|
MySQL.prepare('SELECT `firstname`, `lastname` FROM `users` WHERE `identifier` = ?', [
|
|
identifier
|
|
], (response) => {
|
|
console.log(JSON.stringify(response))
|
|
})
|
|
```
|
|
|
|
</Tab>
|
|
</Tabs>
|
|
|
|
**Aliases**
|
|
|
|
- `exports.oxmysql.prepare`
|