import {MariaDBHelper} from 'Template-HapiRESTServer/src/helpers/mariadb.helper.js'
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 |
Fetch all rows given a query string and values that can qualify the query |
|
public |
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 |
Insert an Object into a specific table |
|
public |
async insertMultiple(table: string, objects: Array<Object>): Promise Insert multiple objects into the table |
|
public |
Execute a simple query on the entire database |
|
public |
Shuts down the mariadb connections |
Public Constructors
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:
Name | Type | Attribute | Description |
query | string | Query string to pass to mariadb |
public async fetchOne(query: string): Promise source
Fetch the (first) row that matches a string
Params:
Name | Type | Attribute | Description |
query | string | Query string to pass to mariadb |
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
public async insertMultiple(table: string, objects: Array<Object>): Promise source
Insert multiple objects into the table
public query(query: string, values: Array<any>): Promise source
Execute a simple query on the entire database
Params:
Name | Type | Attribute | Description |
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 |