import { DataSource, DataSourceOptions, EntityTarget, LoggerOptions, ObjectLiteral, QueryBuilder, QueryRunner, ReplicationMode, Repository, SelectQueryBuilder } from 'typeorm'; import { SelectQueryParams } from './types/common'; import { Logger } from './types/logger'; export type queryBuilderHandler = (novaDataSource: NovaDataSource, queryRunner?: QueryRunner) => Promise; export interface NovaDataSourceConfig { /** * Database username. */ username: string; /** * Database password. */ password: string; /** * Database host. */ host?: string; /** * Database host port. */ port?: number; /** * Database name to connect to. */ database?: string; /** * Object with ssl parameters or a string containing name of ssl profile. */ ssl?: { rejectUnauthorized?: boolean; }; /** * Logging options. */ logging?: LoggerOptions; /** * Replication configuration. */ replicationMode?: ReplicationMode; /** * Cache configuration. */ cache?: DataSourceOptions['cache']; } interface SafeQuery3Options { tag?: string; replicationMode?: ReplicationMode; } export type SafeQuery3Callback = (queryBuilder: (q: QueryBuilder) => any) => Promise; export declare class NovaDataSource { protected readonly dataSource: DataSource; protected readonly logger: Logger; constructor(config: NovaDataSourceConfig, logger: Logger, replicaConfig?: NovaDataSourceConfig); /** * Performs connection to the database. */ connect(): Promise; /** * Wrap whatever cache provider TypeORM materialized (Redis, our LRU, or any * future provider) with `InstrumentedQueryResultCache` so every consumer gets * hit-rate / latency / payload-size metrics with zero callsite changes. Idempotent. */ private wrapQueryResultCache; /** * If the active cache is instrumented, emit its summary log and reset stats. * Safe to call at any time; no-op when the cache isn't instrumented. * Intended for per-Lambda-invocation middleware hooks. */ flushCacheSummary(): void; /** * Closes connection with the database. * Once connection is closed, you cannot use repositories or perform any operations except opening connection again. */ disconnect(): Promise; /** * Gets repository for the given entity. */ getRepository(target: EntityTarget): Repository; /** * Executes raw SQL query and returns raw database results. * * Reads (SELECT/SHOW/DESCRIBE/EXPLAIN/WITH) route to the read replica by default. * Writes (INSERT/UPDATE/DELETE/REPLACE/TRUNCATE/DDL) always go to primary. * Pass `{ usePrimary: true }` for reads that need read-your-write consistency. */ query(query: string, parameters?: any[], opts?: { usePrimary?: boolean; }): Promise; /** * Creates a new query builder that can be used to build a SQL query. */ createQueryBuilder(entityClass: EntityTarget, alias: string): Promise>; /** * Creates a query runner used for perform queries on a single database connection. * Using query runners you can control your queries to execute using single database connection and * manually control your database transaction. * * Mode is used in replication mode and indicates whatever you want to connect * to master database or any of slave databases. * If you perform writes you must use master database, * if you perform reads you can use slave databases. */ createQueryRunner(mode?: ReplicationMode): QueryRunner; createQueryRunnerFromParams(params: SelectQueryParams): QueryRunner; safeQuery(queryBuilderHandler: queryBuilderHandler, tag?: string, queryRunner?: QueryRunner): Promise; safeQuery2(queryBuilderHandler: queryBuilderHandler, tag?: string, queryRunner?: QueryRunner): Promise; safeQuery3(target: EntityTarget, alias: string, callback: (q: QueryBuilder) => Promise, { replicationMode, tag }?: SafeQuery3Options): Promise; syncSchema(dropBeforeSync?: boolean): Promise; clearCache(): Promise; invalidateCacheKey(key: string): Promise; } export {};