Class DB

Database Handling Class. The DB class handles top level abstraction, implementing features which tmysql doesn't provide natively, wrapping a single connection.

Class Overview

Tables

DB.cache Table for storing queries not processed whilst the DB is down.
DB.cb_times Table for storing the callback process time.
DB.cfg Table for storing the db settings.

Fields

DB.debugging Field to store the current DB debug setting.
DB.Connection Internal tmysql DB Connection
DB.__index Lookup table.

Methods

DB:Connect() Initialize the internal database object.
DB:IsConnected() Check if the database is connected.
DB:ReconnectIfDown() Reconnect the DB if its down.
DB:Escape(str) Escape a string using the DB's inbuilt methods.
DB:Cache(query, cb) Add a query and callback to the cache.
DB:CallbackTime(time) Add a callback time.
DB:Run(query[, cb]) Run a query on the DB with optional callback.
DB:FRun(query, ...) Run a query with formatted data.
DB:New(cfg) Create a new DB instance.

Metamethods

DB:__call() Alias of DB:New

Tables

DB.cache
Table for storing queries not processed whilst the DB is down.
DB.cb_times
Table for storing the callback process time.
DB.cfg
Table for storing the db settings.

Fields

DB.debugging
Field to store the current DB debug setting.
DB.Connection
Internal tmysql DB Connection
DB.__index
Lookup table.

Methods

DB:Connect()
Initialize the internal database object.
DB:IsConnected()
Check if the database is connected.

Returns:

    bool If the DB is connected.
DB:ReconnectIfDown()
Reconnect the DB if its down.
DB:Escape(str)
Escape a string using the DB's inbuilt methods.

Parameters:

  • str string The input string.

Returns:

    string The escaped string.
DB:Cache(query, cb)
Add a query and callback to the cache.

Parameters:

  • query string The cached query.
  • cb func The cached callback func.
DB:CallbackTime(time)
Add a callback time.

Parameters:

  • time number Time taken to run the callback.
DB:Run(query[, cb])
Run a query on the DB with optional callback.

Parameters:

  • query string SQL query to run.
  • cb func Callback function. Takes one argument, last ID for insert queries and retrieved data for others. (optional)
DB:FRun(query, ...)
Run a query with formatted data. If final argument is a function, assumed to be callback function.

Parameters:

  • query string The unformatted query to run.
  • ... Formatter arguments.
DB:New(cfg)
Create a new DB instance.

Parameters:

Returns:

    DB

Metamethods

DB:__call()
Alias of DB:New

See also: