From 5321a62529cb50903421d4b4b3cdec7efb10d1c3 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Sun, 18 Jun 2023 19:49:22 +1000 Subject: [PATCH] add rawExecute --- pages/oxmysql/Functions/insert.mdx | 3 +- pages/oxmysql/Functions/prepare.mdx | 5 +- pages/oxmysql/Functions/query.mdx | 3 +- pages/oxmysql/Functions/rawExecute.mdx | 73 +++++++++++++++++++++++++ pages/oxmysql/Functions/scalar.mdx | 3 +- pages/oxmysql/Functions/single.mdx | 2 +- pages/oxmysql/Functions/transaction.mdx | 2 +- pages/oxmysql/Functions/update.mdx | 3 +- 8 files changed, 81 insertions(+), 13 deletions(-) create mode 100644 pages/oxmysql/Functions/rawExecute.mdx diff --git a/pages/oxmysql/Functions/insert.mdx b/pages/oxmysql/Functions/insert.mdx index d1afd0eb..c3250655 100644 --- a/pages/oxmysql/Functions/insert.mdx +++ b/pages/oxmysql/Functions/insert.mdx @@ -1,6 +1,5 @@ --- -keywords: ['execute', 'insert'] -title: Insert +title: insert --- import { Tab, Tabs } from 'nextra-theme-docs'; diff --git a/pages/oxmysql/Functions/prepare.mdx b/pages/oxmysql/Functions/prepare.mdx index 001998cd..4673fe46 100644 --- a/pages/oxmysql/Functions/prepare.mdx +++ b/pages/oxmysql/Functions/prepare.mdx @@ -1,17 +1,16 @@ --- -title: Prepare +title: prepare --- import { Tab, Tabs } from 'nextra-theme-docs'; -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 -When using SELECT, the return value will match `query`, `single`, or `scalar` depending on the number of columns and rows selected. +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 diff --git a/pages/oxmysql/Functions/query.mdx b/pages/oxmysql/Functions/query.mdx index f0260a4f..bc9177b5 100644 --- a/pages/oxmysql/Functions/query.mdx +++ b/pages/oxmysql/Functions/query.mdx @@ -1,6 +1,5 @@ --- -keywords: ['fetchAll', 'execute'] -title: Query +title: query --- import { Tab, Tabs } from 'nextra-theme-docs'; diff --git a/pages/oxmysql/Functions/rawExecute.mdx b/pages/oxmysql/Functions/rawExecute.mdx new file mode 100644 index 00000000..f0236718 --- /dev/null +++ b/pages/oxmysql/Functions/rawExecute.mdx @@ -0,0 +1,73 @@ +import { Tab, Tabs } from 'nextra-theme-docs'; + +rawExecute 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 [prepare](../prepare), the SELECT statement will always return an array of rows. +When using SELECT, the return value will match `query`, `single`, or `scalar` depending on the number of columns and rows selected. + +## Promise + + + + + ```lua + local response = MySQL.rawExecute.await('SELECT `firstname`, `lastname` FROM `users` WHERE `identifier` = ?', { + identifier + }) + + + print(json.encode(response, { indent = true, sort_keys = true })) + ``` + + + + + ```js + const response = await MySQL.rawExecute('SELECT `firstname`, `lastname` FROM `users` WHERE `identifier` = ?', [ + identifier + ]) + + console.log(JSON.stringify(response)) + ``` + + + + +**Aliases** + +- `exports.oxmysql.rawExecute_async` + +## Callback + + + + + ```lua + MySQL.rawExecute('SELECT `firstname`, `lastname` FROM `users` WHERE `identifier` = ?', { + identifier + }, function(response) + print(json.encode(response, { indent = true, sort_keys = true })) + end) + ``` + + + + + ```js + MySQL.rawExecute('SELECT `firstname`, `lastname` FROM `users` WHERE `identifier` = ?', [ + identifier + ], (response) => { + console.log(JSON.stringify(response)) + }) + ``` + + + + +**Aliases** + +- `exports.oxmysql.rawExecute` diff --git a/pages/oxmysql/Functions/scalar.mdx b/pages/oxmysql/Functions/scalar.mdx index 324f0ddf..f589b907 100644 --- a/pages/oxmysql/Functions/scalar.mdx +++ b/pages/oxmysql/Functions/scalar.mdx @@ -1,6 +1,5 @@ --- -keywords: ['scalar', 'fetchScalar'] -title: Scalar +title: scalar --- import { Tab, Tabs } from 'nextra-theme-docs'; diff --git a/pages/oxmysql/Functions/single.mdx b/pages/oxmysql/Functions/single.mdx index de1af26a..d6912694 100644 --- a/pages/oxmysql/Functions/single.mdx +++ b/pages/oxmysql/Functions/single.mdx @@ -1,5 +1,5 @@ --- -title: Single +title: single --- import { Tab, Tabs } from 'nextra-theme-docs'; diff --git a/pages/oxmysql/Functions/transaction.mdx b/pages/oxmysql/Functions/transaction.mdx index 3a503826..d3e45570 100644 --- a/pages/oxmysql/Functions/transaction.mdx +++ b/pages/oxmysql/Functions/transaction.mdx @@ -1,5 +1,5 @@ --- -title: Transaction +title: transaction --- import { Tab, Tabs } from 'nextra-theme-docs'; diff --git a/pages/oxmysql/Functions/update.mdx b/pages/oxmysql/Functions/update.mdx index 1314e1d7..5ef005dc 100644 --- a/pages/oxmysql/Functions/update.mdx +++ b/pages/oxmysql/Functions/update.mdx @@ -1,6 +1,5 @@ --- -keywords: ['execute'] -title: Update +title: update --- import { Tab, Tabs } from 'nextra-theme-docs';