update syntax and include aliases

This commit is contained in:
Linden committed 2021-12-24 03:43:03 +11:00
1 parent 6cf83ac4d1
commit e6da9843ea
8 files changed
+73 -24

No files matched your search

+1 -1
View File
@@ -2,4 +2,4 @@
title: Index
---
todo: include some information about proper formatting, placeholders, bad practices, etc.
todo - include some information about proper formatting, placeholders, bad practices, etc.
+11 -3
View File
@@ -5,24 +5,32 @@ Inserts a new entry into the database and returns the insert id for the row, if
!!! info "Example"
=== "Lua"
**Callback**
```lua
MySQL.Async.insert('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ', {playerIdentifier, firstName, lastName}, function(id)
-- Alias: exports.oxmysql:insert
-- Alias: MySQL.Async.insert
MySQL.insert('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ', {playerIdentifier, firstName, lastName}, function(id)
print(id)
end)
```
**Promise**
```lua
-- Alias: exports.oxmysql:insert_async
-- Alias: MySQL.Sync.insert
CreateThread(function()
local id = MySQL.Sync.insert('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ', {playerIdentifier, firstName, lastName})
local id = MySQL.insert.await('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ', {playerIdentifier, firstName, lastName})
print(id)
end)
```
=== "JavaScript"
**Callback**
```js
exports.oxmysql.insert_callback('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ', [playerIdentifier, firstName, lastName], function(id) {
exports.oxmysql.insert('INSERT INTO users (identifier, firstname, lastname) VALUES (?, ?, ?) ', [playerIdentifier, firstName, lastName], function(id) {
console.log(id)
})
```
+13 -4
View File
@@ -12,9 +12,13 @@ When using SELECT, the return value will match `fetchAll, fetchSingle, or fetchS
!!! info "Example"
=== "Lua"
**Callback**
```lua
MySQL.Async.prepare('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, function(result)
-- Alias: exports.oxmysql:prepare
-- Alias: MySQL.Async.prepare
MySQL.prepare('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, function(result)
if result then
for _, v in pairs(result) do
print(v.identifier, v.firstname, v.lastname)
@@ -24,8 +28,12 @@ When using SELECT, the return value will match `fetchAll, fetchSingle, or fetchS
```
**Promise**
```lua
-- Alias: exports.oxmysql:prepare_async
-- Alias: MySQL.Sync.prepare
CreateThread(function()
local result = MySQL.Sync.prepare('SELECT * FROM users WHERE identifier = ?', {playerIdentifier})
local result = MySQL.prepare.await('SELECT * FROM users WHERE identifier = ?', {playerIdentifier})
if result then
for _, v in pairs(result) do
print(v.identifier, v.firstname, v.lastname)
@@ -35,9 +43,10 @@ When using SELECT, the return value will match `fetchAll, fetchSingle, or fetchS
```
=== "JavaScript"
**Callback**
```js
exports.oxmysql.execute_callback('SELECT * FROM users WHERE identifier = ?', [playerIdentifier], function(result) {
exports.oxmysql.prepare('SELECT * FROM users WHERE identifier = ?', [playerIdentifier], function(result) {
if (result) {
result.forEach((v) => {
console.log(v.identifier, v.firstname, v.lastname)
@@ -48,7 +57,7 @@ When using SELECT, the return value will match `fetchAll, fetchSingle, or fetchS
**Promise**
```js
(async () => {
const result = await exports.oxmysql.execute_async('SELECT * FROM users WHERE identifier = ?', [playerIdentifier]) {
const result = await exports.oxmysql.prepare_async('SELECT * FROM users WHERE identifier = ?', [playerIdentifier]) {
if (result) {
result.forEach((v) => {
console.log(v.identifier, v.firstname, v.lastname)
+12 -4
View File
@@ -1,14 +1,18 @@
---
title: fetchAll
title: 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.
!!! info "Example"
=== "Lua"
**Callback**
```lua
MySQL.Async.fetchAll('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, function(result)
-- Alias: exports.oxmysql:query
-- Alias: MySQL.Async.query
MySQL.query('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, function(result)
if result then
for _, v in pairs(result) do
print(v.identifier, v.firstname, v.lastname)
@@ -18,8 +22,11 @@ When selecting data it will return all matching rows and columns, otherwise it w
```
**Promise**
```lua
-- Alias: exports.oxmysql:query
-- Alias: MySQL.Sync.query
CreateThread(function()
local result = MySQL.Sync.fetchAll('SELECT * FROM users WHERE identifier = ?', {playerIdentifier})
local result = MySQL.query.await('SELECT * FROM users WHERE identifier = ?', {playerIdentifier})
if result then
for _, v in pairs(result) do
print(v.identifier, v.firstname, v.lastname)
@@ -29,9 +36,10 @@ When selecting data it will return all matching rows and columns, otherwise it w
```
=== "JavaScript"
**Callback**
```js
exports.oxmysql.query_callback('SELECT * FROM users WHERE identifier = ?', [playerIdentifier], function(result) {
exports.oxmysql.query('SELECT * FROM users WHERE identifier = ?', [playerIdentifier], function(result) {
if (result) {
result.forEach((v) => {
console.log(v.identifier, v.firstname, v.lastname)
@@ -1,28 +1,36 @@
---
title: fetchScalar
title: scalar
---
Returns the first column for a single row.
!!! info "Example"
=== "Lua"
**Callback**
```lua
MySQL.Async.fetchScalar('SELECT firstname FROM users WHERE identifier = ?', {playerIdentifier}, function(firstname)
-- Alias: exports.oxmysql:scalar
-- Alias: MySQL.Async.fetchScalar
MySQL.scalar('SELECT firstname FROM users WHERE identifier = ?', {playerIdentifier}, function(firstname)
print(firstname)
end)
```
**Promise**
```lua
-- Alias: exports.oxmysql:scalar_async
-- Alias: MySQL.Sync.fetchScalar
CreateThread(function()
local firstname = MySQL.Async.fetchScalar('SELECT firstname FROM users WHERE identifier = ?', {playerIdentifier})
local firstname = MySQL.scalar.await('SELECT firstname FROM users WHERE identifier = ?', {playerIdentifier})
print(firstname)
end)
```
=== "JavaScript"
**Callback**
```js
exports.oxmysql.scalar_callback('SELECT firstname FROM users WHERE identifier = ?', [playerIdentifier], function(firstname) {
exports.oxmysql.scalar('SELECT firstname FROM users WHERE identifier = ?', [playerIdentifier], function(firstname) {
console.log(firstname)
})
```
@@ -1,13 +1,17 @@
---
title: fetchSingle
title: single
---
Returns the columns for a single row.
!!! info "Example"
=== "Lua"
**Callback**
```lua
MySQL.Async.fetchSingle('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, function(result)
-- Alias: exports.oxmysql:single
-- Alias: MySQL.Async.fetchSingle
MySQL.single('SELECT * FROM users WHERE identifier = ?', {playerIdentifier}, function(result)
if result then
print(result.identifier, result.firstname, result.lastname)
end
@@ -15,8 +19,11 @@ Returns the columns for a single row.
```
**Promise**
```lua
-- Alias: exports.oxmysql:single_async
-- Alias: MySQL.Sync.fetchSingle
CreateThread(function()
local result = MySQL.Sync.fetchSingle('SELECT * FROM users WHERE identifier = ?', {playerIdentifier})
local result = MySQL.single.await('SELECT * FROM users WHERE identifier = ?', {playerIdentifier})
if result then
print(result.identifier, result.firstname, result.lastname)
end
@@ -24,9 +31,10 @@ Returns the columns for a single row.
```
=== "JavaScript"
**Callback**
```js
exports.oxmysql.single_callback('SELECT * FROM users WHERE identifier = ?', [playerIdentifier], function(result) {
exports.oxmysql.single('SELECT * FROM users WHERE identifier = ?', [playerIdentifier], function(result) {
if (result)
console.log(result.identifier, result.firstname, result.lastname)
})
+1 -1
View File
@@ -1,7 +1,7 @@
---
title: transaction
---
todo - update formatting and information
# Transactions
+11 -3
View File
@@ -1,12 +1,16 @@
---
title: execute
title: update
---
Returns the number of affected rows by the query.
!!! info "Example"
=== "Lua"
**Callback**
```lua
-- Alias: exports.oxmysql:update
-- Alias: MySQL.Async.update
MySQL.Async.update('UPDATE users SET firstname = ? WHERE identifier = ? ', {newName, playerIdentifier}, function(affectedRows)
if affectedRows then
print(affectedRows)
@@ -15,8 +19,11 @@ Returns the number of affected rows by the query.
```
**Promise**
```lua
-- Alias: exports.oxmysql:update_async
-- Alias: MySQL.update
CreateThread(function()
local id = MySQL.Sync.update('UPDATE users SET firstname = ? WHERE identifier = ? ', {newName, playerIdentifier})
local id = MySQL.update.await('UPDATE users SET firstname = ? WHERE identifier = ? ', {newName, playerIdentifier})
if affectedRows then
print(affectedRows)
end
@@ -24,9 +31,10 @@ Returns the number of affected rows by the query.
```
=== "JavaScript"
**Callback**
```js
exports.oxmysql.update_callback('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)
console.log(affectedRows)
})