Home Manual Reference Source Test API Healthcheck
public class | source

MariaDBHelper

MariaDB Helper for easy access to a configured MySQL Connection, with consistent methods for simple interactions and larger transactions.

This class can also be instantiated pointing elsewhere with a different MariaDBConfig passed to the constructor

Constructor Summary

Public Constructor
public

constructor(): PoolApi

MariaDB Pool API

Member Summary

Public Members
public

dbPool: *

Method Summary

Public Methods
public

async fetch(query: string): Promise

Fetch all rows given a query string and values that can qualify the query

public

async fetchOne(query: string): Promise

Fetch the (first) row that matches a string

public

async getStatus(): String | boolean

Return the status of the database server (should be called on an instance with a pool, not connection)

public

async insert(table: String, object: Object): Promise<MariaDBInsertResponse>

Insert an Object into a specific table

public

async insertMultiple(table: string, objects: Array<Object>): Promise

Insert multiple objects into the table

public

query(query: string, values: Array<any>): Promise

Execute a simple query on the entire database

public

Shuts down the mariadb connections

Public Constructors

public constructor(): PoolApi source

MariaDB Pool API

Public Members

public dbPool: * source

Public Methods

public async fetch(query: string): Promise source

Fetch all rows given a query string and values that can qualify the query

Params:

NameTypeAttributeDescription
query string

Query string to pass to mariadb

Return:

Promise

Return array of values

public async fetchOne(query: string): Promise source

Fetch the (first) row that matches a string

Params:

NameTypeAttributeDescription
query string

Query string to pass to mariadb

Return:

Promise

Returns a single value

public async getStatus(): String | boolean source

Return the status of the database server (should be called on an instance with a pool, not connection)

Return:

String | boolean

Either the current time, returned from database, or false if unable to connect

public async insert(table: String, object: Object): Promise<MariaDBInsertResponse> source

Insert an Object into a specific table

Params:

NameTypeAttributeDescription
table String

Name of table to insert object into

object Object

Mapping from column names to values to insert into DB Table

Return:

Promise<MariaDBInsertResponse>

Response from MariaDB

public async insertMultiple(table: string, objects: Array<Object>): Promise source

Insert multiple objects into the table

Params:

NameTypeAttributeDescription
table string

to insert into

objects Array<Object>

Array of objects to insert

Return:

Promise

Response from MariaDB

public query(query: string, values: Array<any>): Promise source

Execute a simple query on the entire database

Params:

NameTypeAttributeDescription
query string

Query string to be passed to DB for response see https://mariadb.com/kb/en/library/data-manipulation/ for reference

values Array<any>

Array of values to inject into the query string, matching the number of placeholders given

Return:

Promise

Returns the response from the query

public shutdown(callback: Function): undefined source

Shuts down the mariadb connections

Params:

NameTypeAttributeDescription
callback Function

callback function to call after shutting down db connections

Return:

undefined

no return