UNPKG

lakutata

Version:

An IoC-based universal application framework.

185 lines (182 loc) 6.77 kB
import '../vendor/TypeDef.2.js'; import { C as Component } from '../vendor/TypeDef.3.js'; import { D as DataSourceOptions, a as DataSource, b as Driver, E as EntityManager, N as NamingStrategyInterface, c as EntitySubscriberInterface, d as EntityMetadata, e as EntityTarget, Q as QueryResultCache, M as Migration, O as ObjectLiteral, R as Repository, T as TreeRepository, f as MongoRepository, I as IsolationLevel, g as QueryRunner, S as SelectQueryBuilder, h as ReplicationMode } from '../vendor/TypeDef.4.js'; import '../vendor/TypeDef.5.js'; import 'fs'; import 'tls'; import 'net'; import 'dns'; import 'events'; import 'stream'; /** * Build database connection options * @param options * @constructor */ declare const BuildDatabaseOptions: (options: DataSourceOptions) => { class: typeof Database; options: DataSourceOptions; }; /** * Database component */ declare class Database extends Component { #private; /** * Connection options */ protected readonly options: DataSourceOptions; /** * Datasource instance * @protected */ protected get datasource(): DataSource; /** * Connection driver */ get driver(): Driver; /** * EntityManager of this connection. */ get manager(): EntityManager; /** * Set naming strategy used in the connection. * @param instance */ set namingStrategy(instance: NamingStrategyInterface); /** * Get naming strategy used in the connection. */ get namingStrategy(): NamingStrategyInterface; /** * Entity subscriber instances that are registered for this connection. */ get subscribers(): EntitySubscriberInterface<any>[]; /** * All entity metadatas that are registered for this connection. */ get entityMetadatas(): EntityMetadata[]; /** * All entity metadatas that are registered for this connection. * This is a copy of #.entityMetadatas property -> used for more performant searches. */ get entityMetadatasMap(): Map<EntityTarget<any>, EntityMetadata>; /** * Used to work with query result cache. */ get queryResultCache(): QueryResultCache | undefined; /** * Initializer * @protected */ protected init(): Promise<void>; /** * Destroyer * @protected */ protected destroy(): Promise<void>; /** * Creates database schema for all entities registered in this connection. * Can be used only after connection to the database is established. * * @param dropBeforeSync If set to true then it drops the database with all its tables and data */ synchronize(dropBeforeSync?: boolean): Promise<void>; /** * Runs all pending migrations. * Can be used only after connection to the database is established. * @param options */ runMigrations(options?: { transaction?: 'all' | 'none' | 'each'; fake?: boolean; }): Promise<Migration[]>; /** * Reverts last executed migration. * Can be used only after connection to the database is established. * @param options */ undoLastMigration(options?: { transaction?: 'all' | 'none' | 'each'; fake?: boolean; }): Promise<void>; /** * Lists all migrations and whether they have been run. * Returns true if there are pending migrations */ showMigrations(): Promise<boolean>; /** * Checks if entity metadata exist for the given entity class, target name or table name. * @param target */ hasMetadata(target: EntityTarget<any>): boolean; /** * Gets entity metadata for the given entity class or schema name. * @param target */ getMetadata(target: EntityTarget<any>): EntityMetadata; /** * Gets repository for the given entity. * @param target */ getRepository<Entity extends ObjectLiteral>(target: EntityTarget<Entity>): Repository<Entity>; /** * Gets tree repository for the given entity class or name. * Only tree-type entities can have a TreeRepository, like ones decorated with @Tree decorator. * @param target */ getTreeRepository<Entity extends ObjectLiteral>(target: EntityTarget<Entity>): TreeRepository<Entity>; /** * Gets mongodb-specific repository for the given entity class or name. * Works only if connection is mongodb-specific. * @param target */ getMongoRepository<Entity extends ObjectLiteral>(target: EntityTarget<Entity>): MongoRepository<Entity>; /** * Wraps given function execution (and all operations made there) into a transaction. * All database operations must be executed using provided entity manager. * @param runInTransaction */ transaction<T>(runInTransaction: (entityManager: EntityManager) => Promise<T>): Promise<T>; transaction<T>(isolationLevel: IsolationLevel, runInTransaction: (entityManager: EntityManager) => Promise<T>): Promise<T>; /** * Executes raw SQL query and returns raw database results. * @param query * @param parameters * @param queryRunner */ query<T = any>(query: string, parameters?: any[], queryRunner?: QueryRunner): Promise<T>; /** * Creates a new query builder that can be used to build a SQL query. * @param entityClass * @param alias * @param queryRunner */ createQueryBuilder<Entity extends ObjectLiteral>(entityClass: EntityTarget<Entity>, alias: string, queryRunner?: QueryRunner): SelectQueryBuilder<Entity>; createQueryBuilder(queryRunner?: QueryRunner): SelectQueryBuilder<any>; /** * 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. * * @param mode */ createQueryRunner(mode?: ReplicationMode): QueryRunner; /** * Gets entity metadata of the junction table (many-to-many table). * @param entityTarget * @param relationPropertyPath */ getManyToManyMetadata(entityTarget: EntityTarget<any>, relationPropertyPath: string): EntityMetadata | undefined; /** * Creates an Entity Manager for the current connection with the help of the EntityManagerFactory. * @param queryRunner */ createEntityManager(queryRunner?: QueryRunner): EntityManager; } export { BuildDatabaseOptions, Database };