nut.db
Database Module.
Core system for handling all database operations in NutScript.
Functions
nut.db.connect (callback, reconnect)
nut.db.connect
Internal
This is used internally - although you're able to use it you probably shouldn't.
Connects to the database
Parameters:
function callbackoptional
Function to call after connection
boolean
reconnect
optional
Whether this is a reconnection attempt
nut.db.wipeTables (callback)
nut.db.wipeTables
Wipes all NutScript database tables
Parameters:
function callbackoptional
Function to call after wipe
nut.db.loadTables ()
nut.db.loadTables
Internal
This is used internally - although you're able to use it you probably shouldn't.
Loads/creates database tables
nut.db.waitForTablesToLoad ()
nut.db.waitForTablesToLoad
Internal
This is used internally - although you're able to use it you probably shouldn't.
Waits for tables to finish loading
Returns:
promise Promise that resolves when tables are loadednut.db.convertDataType (value, noEscape)
nut.db.convertDataType
Converts Lua data types to SQL format
Parameters:
vararg value Value to convertboolean
noEscape
optional
Whether to skip escaping
Returns:
string SQL-formatted valuenut.db.insertTable (value, callback, dbTable)
nut.db.insertTable
Inserts data into a table
Parameters:
table value Key-value pairs to insertfunction
callback
optional
Query callback
string
dbTable
optional
Table name (default "characters")
nut.db.updateTable (value, callback, dbTable, condition)
nut.db.updateTable
Updates data in a table
Parameters:
table value Key-value pairs to updatefunction
callback
optional
Query callback
string
dbTable
optional
Table name (default "characters")
string
condition
optional
WHERE condition
nut.db.select (fields, dbTable, condition, limit)
nut.db.select
Selects data from a table
Parameters:
vararg fields Fields to select (string ortable of strings
)
string
dbTable
optional
Table name (default "characters")
string
condition
optional
WHERE condition
number
limit
optional
Result limit
Returns:
promise Promise resolving to query resultsnut.db.upsert (value, dbTable)
nut.db.upsert
Upserts (insert or update) data
Parameters:
table value Key-value pairsstring
dbTable
optional
Table name (default "characters")
Returns:
promise Promise resolving to query resultsnut.db.delete (dbTable, condition)
nut.db.delete
Deletes data from a table
Parameters:
string dbTableoptional
Table name (default "character")
string
condition
optional
WHERE condition
Returns:
promise Promise resolving to query resultsnut.db.prepare (key, query, types)
nut.db.prepare
Prepares a SQL statement
Parameters:
string key Unique identifierstring
query
SQL query with ?
placeholders
table types Parameter types (MYSQLOO_ constants)
Usage:
nut.db.preparedCall (key, callback, ...)
nut.db.preparedCall
Executes a prepared statement
Parameters:
string key Prepared statement identifierfunction
callback
optional
Query callback
vararg ... Parameters for the statement