import { DataConnection } from './DataConnection'; import { DataSet } from './DataSet'; import { DataSource } from './DataSource'; import { DataTable } from './DataTable'; import { ConditionGroup, DeleteQuery, InsertQuery, Query, QueryTable, SelectQuery, UpdateQuery } from './query'; export declare abstract class DB { private static get _sources(); private static get _activeSourceName(); private static set _activeSourceName(value); static register(source: DataSource): void; static register(sourceName: string, source: DataSource): void; static setActiveSource(sourceName: string): void; static source(sourceName: string): DataSource; /** * Reads environment variables and registers the corresponding data sources. * Called automatically the first time a source is needed if none have been * registered manually. * * Supported variables: * * Default source: * DB_URL connection string (takes priority over DB_DRIVER and friends) * DB_DRIVER sqlite | postgres | mysql (required if DB_URL is not set) * DB_FILE path to SQLite file (sqlite only, default: :memory:) * DB_HOST database host (postgres / mysql) * DB_PORT database port (postgres / mysql) * DB_NAME database name (postgres / mysql) * DB_USERNAME login username (postgres / mysql) * DB_PASSWORD login password (postgres / mysql) * DB_DEBUG enable debug mode (true/false, 1/0, yes/no, on/off) * DB_READONLY readonly mode (true/false, 1/0, yes/no, on/off) * * Named source (replace with the desired source name in upper-case): * DB__URL, DB__DRIVER, DB__HOST, DB__PORT, * DB__NAME, DB__USERNAME, DB__PASSWORD, DB__FILE, * DB__DEBUG, DB__READONLY * * Connection string examples: * DB_URL=sqlite://:memory: * DB_URL=sqlite:///path/to/file.db * DB_URL=postgres://admin:secret@localhost:5432/mydb * DB_URL=mysql://admin:secret@localhost:3306/mydb * * Individual variable examples: * DB_DRIVER=postgres DB_HOST=localhost DB_NAME=app DB_USERNAME=user DB_PASSWORD=pass * DB_REPORTING_DRIVER=sqlite DB_REPORTING_FILE=./reporting.db */ private static configure; /** * Builds a DataSource from a connection string URL. * * Supported formats: * sqlite://:memory: * sqlite:///absolute/path/to/file.db * sqlite://relative/path.db * postgres://user:pass@host:5432/dbname * postgresql://user:pass@host:5432/dbname * mysql://user:pass@host:3306/dbname * * @param url The connection string. * @param get Optional getter for extra env keys (DEBUG, READONLY, …). */ private static _buildSourceFromUrl; private static _buildSourceFromEnv; private static _parseEnvBoolean; private static _buildDriverSource; private static _ensureConfigured; static table(tableName: string): DataTable; static conditionGroup(): ConditionGroup; static selectQuery(table?: QueryTable): SelectQuery; static updateQuery(table?: QueryTable): UpdateQuery; static deleteQuery(table?: QueryTable): DeleteQuery; static insertQuery(table?: QueryTable): InsertQuery; static connection(): Promise; static withConnection(callback: (connection: DataConnection) => Promise): Promise; static query(sql: string, bindings?: Array): Promise>; static query(query: Query): Promise>; static execute(sql: string, bindings?: Array): Promise; static execute(query: Query): Promise; static beginTransaction(): Promise; static commitTransaction(): Promise; static rollbackTransaction(): Promise; static executeTransaction(callback: (connection: DataConnection) => Promise): Promise; /** * Runs `callback` inside a database transaction on the active source. Entity * and query operations performed within the callback share a single connection * and are committed atomically; a thrown error rolls everything back and is * re-thrown. See `DataSource.transaction`. */ static transaction(callback: (connection: DataConnection) => Promise): Promise; static getActiveSource(): DataSource; private static get _activeSource(); }