Skip to content

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 callback optional 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 callback optional 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 loaded

nut.db.convertDataType (value, noEscape)
nut.db.convertDataType

Converts Lua data types to SQL format

Parameters:

vararg value Value to convert

boolean noEscape optional Whether to skip escaping

Returns:

string SQL-formatted value

nut.db.insertTable (value, callback, dbTable)
nut.db.insertTable

Inserts data into a table

Parameters:

table value Key-value pairs to insert

function 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 update

function 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 or table 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 results

nut.db.upsert (value, dbTable)
nut.db.upsert

Upserts (insert or update) data

Parameters:

table value Key-value pairs

string dbTable optional Table name (default "characters")

Returns:

promise Promise resolving to query results

nut.db.delete (dbTable, condition)
nut.db.delete

Deletes data from a table

Parameters:

string dbTable optional Table name (default "character")

string condition optional WHERE condition

Returns:

promise Promise resolving to query results

nut.db.prepare (key, query, types)
nut.db.prepare

Prepares a SQL statement

Parameters:

string key Unique identifier

string query SQL query with ? placeholders

table types Parameter types (MYSQLOO_ constants)

Usage:

    nut.db.prepare("itemData", "UPDATE nut_items SET _data = ? WHERE _itemID = ?", {MYSQLOO_STRING, MYSQLOO_INTEGER})
    

nut.db.preparedCall (key, callback, ...)
nut.db.preparedCall

Executes a prepared statement

Parameters:

string key Prepared statement identifier

function callback optional Query callback

vararg ... Parameters for the statement