UNPKG

lakutata

Version:

An IoC-based universal application framework.

225 lines (221 loc) 7.88 kB
import { DataSourceOptions, DataSource } from './TypeDef.internal.33.js'; import { Driver } from './TypeDef.internal.45.js'; import { EntityManager } from './TypeDef.internal.35.js'; import { NamingStrategyInterface } from './TypeDef.internal.43.js'; import { EntitySubscriberInterface } from './TypeDef.internal.46.js'; import { EntityMetadata } from './TypeDef.internal.47.js'; import { MixedList, EntityTarget, ObjectLiteral } from './TypeDef.internal.36.js'; import { Migration } from './TypeDef.internal.48.js'; import { Repository, TreeRepository, MongoRepository } from './TypeDef.internal.37.js'; import { QueryRunner } from './TypeDef.internal.40.js'; import { SelectQueryBuilder } from './TypeDef.internal.38.js'; import { IsolationLevel, ReplicationMode } from './TypeDef.internal.44.js'; import { QueryResultCache } from './TypeDef.internal.39.js'; import { Provider } from './TypeDef.internal.96.js'; import './TypeDef.internal.30.js'; import { EntitySchema } from './TypeDef.internal.41.js'; /** * Build database provider connection options * @param options * @constructor */ declare const BuildDatabaseOptions: (options: DataSourceOptions) => { class: typeof Database; options: DataSourceOptions; }; /** * Database component */ declare class Database extends Provider { #private; static databaseSymbol: symbol; /** * Connection options */ protected readonly options: DataSourceOptions; /** * Database entities * @protected */ protected readonly entities: MixedList<Function | string | EntitySchema>; /** * 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; } declare class PasswordHash extends Provider { #private; /** * Salt rounds */ readonly saltRounds: number; /** * Salt getter */ get salt(): string; /** * Initializer * @protected */ protected init(): Promise<void>; /** * Generate password hash * @param password */ hash(password: string): Promise<string>; /** * Validate password hash * @param password * @param hash */ validate(password: string, hash: string): Promise<boolean>; } export { BuildDatabaseOptions, Database, PasswordHash };