Class: database

backend.database()

new database()

Database connection abstraction. Handles basic SQL get requests as well as auto connection handling and insertion statement building. Utilizes prepared statements for security.
Source:

Members

(static) connectionLimit :number

Max connections at one time. Loaded from backend config file.
Type:
  • number
Source:

(static) database :string

Database name to connect to. Loaded from backend config file
Type:
  • string
Source:

(static) hostname :string

hostname to connect to. Loaded from backend config file
Type:
  • string
Source:

(static) password :string

MariaDB password for account with admin privileges. Loaded from secure ENV variable
Type:
  • string
Source:

(static) username :string

MariaDB username with admin privileges. Loaded from secure ENV variable
Type:
  • string
Source:

Methods

(static) connect() → {object}

Connects to the database. Blocks until complete instead of returning a promise. Future revisions may switch to promise implementation.
Source:
Returns:
Socket connection object to run queries on. Undefined behaviour on connection failure.
Type
object

(static) disconnect() → {object}

Securely disconnections from the database
Source:
Returns:
Disconnect data
Type
object

(static) get(query, data) → {Promise}

Runs a SQL query via a prepared statement and resolves to the results
Parameters:
Name Type Description
query string SQL query to run, with data as '?'
data Array.<any> Array of data to insert
Source:
Returns:
Promise which resolves to the results of the SQL query
Type
Promise

(static) init()

Initializes mariadb pool Loads config options and sets up the DB socket.
Source:

(static) insert(table, tuple, ignore) → {Promise}

Automatically builds an insertion query and runs it
Parameters:
Name Type Description
table string SQL table to insert into
tuple object Tuple contains key value pairs for columns and data
ignore boolean Toggle for 'INSERT IGNORE' mode. Defaults to false
Source:
Returns:
Promise which resolves to the result of the query
Type
Promise