import { Logger, LogLevel } from '../../common/services/logger.service'; import { Connection, Driver } from 'typeorm'; import { QueryRunner } from 'typeorm/query-runner/QueryRunner'; import { AbstractService } from '../../common/services/service'; export declare type TypeormLogLevel = "log" | "info" | "warn" | "error"; export interface DatabaseLogFunction { (level: LogLevel, ...messages: any[]): void; } /** * Core database service for connecting to the SQL db */ export declare class Database extends AbstractService { private static connections; /** * Logger instance for the class, initialized with `database` source */ private logger; /** * Promise that the database has initialised. */ private initialized; constructor(loggerBase: Logger); /** * Connects to the database and stores reference to the connection instance * @returns {Promise} */ initialize(): Promise; /** * Connect to the database, returning promised of connection instance. * Static method so calls can be made outside of dependency injection context for example * pre-bootstrap * @param name * @param logFunction * @returns {Promise} */ static connect(name?: string, logFunction?: DatabaseLogFunction): Promise; static clearConnections(): void; /** * Retrieve connection instance * @returns {Promise} */ getConnection(name?: string): Promise; /** * Execute a raw query * @param sql * @returns {Promise} */ query(sql: string): Promise; /** * Get current driver from connection for direct database interaction * @returns {Promise} */ getDriver(connectionName?: string): Promise; /** * Get current query runner from current driver for direct database interaction * @returns {Promise} */ getQueryRunner(connectionName?: string): Promise; /** * ES6 template string tagger to create prepared statements * * Example: * ```typescript * return this.database.query(Database.prepare`INSERT * INTO books * (name, author, isbn, category, recommended_age, pages, price) * VALUES (${name}, ${author}, ${isbn}, ${category}, ${recommendedAge}, ${pages}, ${price}) * `); * ``` * This will generate a prepared statement with all the safety features that come with that * @see https://www.npmjs.com/package/sql-template-strings * @param args * @returns {any} */ static prepare(...args: any[]): any; }