UNPKG

@kwaeri/database-driver

Version:

The @kwaeri/database-driver component of the @kwaer/node-kit application platform.

116 lines (115 loc) 3.15 kB
/** * SPDX-PackageName: kwaeri/database-driver * SPDX-PackageVersion: 0.6.0 * SPDX-FileCopyrightText: © 2014 - 2022 Richard Winters <kirvedx@gmail.com> and contributors * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR MIT */ /** * @typedef { Object } HostConnectionBit * @property { string } host */ export type HostConnectionBit = { host: string; }; /** * @typedef { Object } DatabaseConnectionBit * @property { string } database */ export type DatabaseConnectionBit = { database: string; }; /** * @typedef { Object } UserConnectionBit * @property { string } user */ export type UserConnectionBit = { user: string; }; /** * @typedef { Object } PasswordConnectionBit * @property { string } password */ export type PasswordConnectionBit = { password: string; }; /** * @typedef { Object } PortConnectionBit * @property { number|string } port */ export type PortConnectionBit = { port?: number | string; }; /** * @typedef { Object } TypeConnectionBit * @property { string } type */ export type TypeConnectionBit = { type?: string; }; /** * @typedef { Object } DriverConnectionBits * @property { HostConnectionBit } host * @property { DatabaseConnectionBit } database * @property { UserConnectionBit } user * @property { PasswordConnectionBit } password * @property { PortConnectionBit } port * @property { TypeConnectionBit } type */ export type DriverConnectionBits = HostConnectionBit & DatabaseConnectionBit & UserConnectionBit & PasswordConnectionBit & PortConnectionBit & TypeConnectionBit; /** * @typedef { Object } QueryResult * @property { Object|Array<any> } rows * @property { Object|Array<any> } fields */ export type QueryResult = { rows: object | Array<any>; fields: object | Array<any>; }; /** * The Database Driver interface */ export interface BaseDatabaseDriver { type: string; connection: DriverConnectionBits; get getType(): string; get getConnection(): DriverConnectionBits; query<T extends QueryResult>(queryString: string): Promise<T>; } /** * The Base Driver to inherit from for ensuring any platform * requirements are met */ export declare abstract class DatabaseDriver implements BaseDatabaseDriver { /** * @var { string } type */ type: string; /** * @var {@link DriverConnectionBits} connection */ connection: DriverConnectionBits; /** * Class constructor */ constructor(config: DriverConnectionBits); /** * Getter for the driver type * * @returns { string } The string type. */ get getType(): string; /** * Getter for the connection details * * @returns { DriverConnectionBits } A {@link DriverConnectionBits} object. */ get getConnection(): DriverConnectionBits; /** * The query method is a required async generic method which must be reimplemented by derived classes. * * @param { string } queryString The query string to be executed * * @return { Promise<T> } Returns a {@link QueryResult} */ abstract query<T extends QueryResult>(queryString: string): Promise<T>; }