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AU,GAAG,yBAAyB,CAAC,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC;QAC5F,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC;QAErD,iGAAiG;QACjG,uBAAuB,CAAC,YAAY,CAAC,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,UAAA,QAAQ,IAAI,OAAA,QAAQ,CAAC,SAAS,KAAK,MAAM,EAA7B,CAA6B,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IAC9H,CAAC;IAEL,iBAAC;AAAD,CAldA,AAkdC,IAAA","file":"Connection.js","sourcesContent":["import {Driver} from \"../driver/Driver\";\nimport {Repository} from \"../repository/Repository\";\nimport {EntitySubscriberInterface} from \"../subscriber/EntitySubscriberInterface\";\nimport {ObjectType} from \"../common/ObjectType\";\nimport {EntityManager} from \"../entity-manager/EntityManager\";\nimport {DefaultNamingStrategy} from \"../naming-strategy/DefaultNamingStrategy\";\nimport {CannotExecuteNotConnectedError} from \"../error/CannotExecuteNotConnectedError\";\nimport {CannotConnectAlreadyConnectedError} from \"../error/CannotConnectAlreadyConnectedError\";\nimport {TreeRepository} from \"../repository/TreeRepository\";\nimport {NamingStrategyInterface} from \"../naming-strategy/NamingStrategyInterface\";\nimport {EntityMetadata} from \"../metadata/EntityMetadata\";\nimport {Logger} from \"../logger/Logger\";\nimport {EntityMetadataNotFoundError} from \"../error/EntityMetadataNotFoundError\";\nimport {MigrationInterface} from \"../migration/MigrationInterface\";\nimport {MigrationExecutor} from \"../migration/MigrationExecutor\";\nimport {Migration} from \"../migration/Migration\";\nimport {MongoRepository} from \"../repository/MongoRepository\";\nimport {MongoDriver} from \"../driver/mongodb/MongoDriver\";\nimport {MongoEntityManager} from \"../entity-manager/MongoEntityManager\";\nimport {EntityMetadataValidator} from \"../metadata-builder/EntityMetadataValidator\";\nimport {ConnectionOptions} from \"./ConnectionOptions\";\nimport {QueryRunnerProviderAlreadyReleasedError} from \"../error/QueryRunnerProviderAlreadyReleasedError\";\nimport {EntityManagerFactory} from \"../entity-manager/EntityManagerFactory\";\nimport {DriverFactory} from \"../driver/DriverFactory\";\nimport {ConnectionMetadataBuilder} from \"./ConnectionMetadataBuilder\";\nimport {QueryRunner} from \"../query-runner/QueryRunner\";\nimport {SelectQueryBuilder} from \"../query-builder/SelectQueryBuilder\";\nimport {LoggerFactory} from \"../logger/LoggerFactory\";\nimport {QueryResultCacheFactory} from \"../cache/QueryResultCacheFactory\";\nimport {QueryResultCache} from \"../cache/QueryResultCache\";\nimport {SqljsEntityManager} from \"../entity-manager/SqljsEntityManager\";\nimport {RelationLoader} from \"../query-builder/RelationLoader\";\nimport {RelationIdLoader} from \"../query-builder/RelationIdLoader\";\nimport {EntitySchema} from \"../\";\nimport {SqlServerDriver} from \"../driver/sqlserver/SqlServerDriver\";\nimport {MysqlDriver} from \"../driver/mysql/MysqlDriver\";\nimport {ObjectUtils} from \"../util/ObjectUtils\";\nimport {PromiseUtils} from \"../\";\nimport {IsolationLevel} from \"../driver/types/IsolationLevel\";\n\n/**\n * Connection is a single database ORM connection to a specific database.\n * Its not required to be a database connection, depend on database type it can create connection pool.\n * You can have multiple connections to multiple databases in your application.\n */\nexport class Connection {\n\n // -------------------------------------------------------------------------\n // Public Readonly Properties\n // -------------------------------------------------------------------------\n\n /**\n * Connection name.\n */\n readonly name: string;\n\n /**\n * Connection options.\n */\n readonly options: ConnectionOptions;\n\n /**\n * Indicates if connection is initialized or not.\n */\n readonly isConnected: boolean;\n\n /**\n * Database driver used by this connection.\n */\n readonly driver: Driver;\n\n /**\n * EntityManager of this connection.\n */\n readonly manager: EntityManager;\n\n /**\n * Naming strategy used in the connection.\n */\n readonly namingStrategy: NamingStrategyInterface;\n\n /**\n * Logger used to log orm events.\n */\n readonly logger: Logger;\n\n /**\n * Migration instances that are registered for this connection.\n */\n readonly migrations: MigrationInterface[] = [];\n\n /**\n * Entity subscriber instances that are registered for this connection.\n */\n readonly subscribers: EntitySubscriberInterface<any>[] = [];\n\n /**\n * All entity metadatas that are registered for this connection.\n */\n readonly entityMetadatas: EntityMetadata[] = [];\n\n /**\n * Used to work with query result cache.\n */\n readonly queryResultCache?: QueryResultCache;\n\n /**\n * Used to load relations and work with lazy relations.\n */\n readonly relationLoader: RelationLoader;\n\n /**\n * Used to load relation ids of specific entity relations.\n */\n readonly relationIdLoader: RelationIdLoader;\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(options: ConnectionOptions) {\n this.name = options.name || \"default\";\n this.options = options;\n this.logger = new LoggerFactory().create(this.options.logger, this.options.logging);\n this.driver = new DriverFactory().create(this);\n this.manager = this.createEntityManager();\n this.namingStrategy = options.namingStrategy || new DefaultNamingStrategy();\n this.queryResultCache = options.cache ? new QueryResultCacheFactory(this).create() : undefined;\n this.relationLoader = new RelationLoader(this);\n this.relationIdLoader = new RelationIdLoader(this);\n this.isConnected = false;\n }\n\n // -------------------------------------------------------------------------\n // Public Accessors\n // -------------------------------------------------------------------------\n\n /**\n * Gets the mongodb entity manager that allows to perform mongodb-specific repository operations\n * with any entity in this connection.\n *\n * Available only in mongodb connections.\n */\n get mongoManager(): MongoEntityManager {\n if (!(this.manager instanceof MongoEntityManager))\n throw new Error(`MongoEntityManager is only available for MongoDB databases.`);\n\n return this.manager as MongoEntityManager;\n }\n\n /**\n * Gets a sql.js specific Entity Manager that allows to perform special load and save operations\n *\n * Available only in connection with the sqljs driver.\n */\n get sqljsManager(): SqljsEntityManager {\n if (!(this.manager instanceof SqljsEntityManager))\n throw new Error(`SqljsEntityManager is only available for Sqljs databases.`);\n\n return this.manager as SqljsEntityManager;\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Performs connection to the database.\n * This method should be called once on application bootstrap.\n * This method not necessarily creates database connection (depend on database type),\n * but it also can setup a connection pool with database to use.\n */\n async connect(): Promise<this> {\n if (this.isConnected)\n throw new CannotConnectAlreadyConnectedError(this.name);\n\n // connect to the database via its driver\n await this.driver.connect();\n\n // connect to the cache-specific database if cache is enabled\n if (this.queryResultCache)\n await this.queryResultCache.connect();\n\n // set connected status for the current connection\n ObjectUtils.assign(this, { isConnected: true });\n\n try {\n\n // build all metadatas registered in the current connection\n this.buildMetadatas();\n\n await this.driver.afterConnect();\n\n // if option is set - drop schema once connection is done\n if (this.options.dropSchema)\n await this.dropDatabase();\n\n // if option is set - automatically synchronize a schema\n if (this.options.synchronize)\n await this.synchronize();\n\n // if option is set - automatically synchronize a schema\n if (this.options.migrationsRun)\n await this.runMigrations();\n\n } catch (error) {\n\n // if for some reason build metadata fail (for example validation error during entity metadata check)\n // connection needs to be closed\n await this.close();\n throw error;\n }\n\n return this;\n }\n\n /**\n * Closes connection with the database.\n * Once connection is closed, you cannot use repositories or perform any operations except opening connection again.\n */\n async close(): Promise<void> {\n if (!this.isConnected)\n throw new CannotExecuteNotConnectedError(this.name);\n\n await this.driver.disconnect();\n\n // disconnect from the cache-specific database if cache was enabled\n if (this.queryResultCache)\n await this.queryResultCache.disconnect();\n\n ObjectUtils.assign(this, { isConnected: false });\n }\n\n /**\n * Creates database schema for all entities registered in this connection.\n * Can be used only after connection to the database is established.\n *\n * @param dropBeforeSync If set to true then it drops the database with all its tables and data\n */\n async synchronize(dropBeforeSync: boolean = false): Promise<void> {\n\n if (!this.isConnected)\n throw new CannotExecuteNotConnectedError(this.name);\n\n if (dropBeforeSync)\n await this.dropDatabase();\n\n const schemaBuilder = this.driver.createSchemaBuilder();\n await schemaBuilder.build();\n }\n\n /**\n * Drops the database and all its data.\n * Be careful with this method on production since this method will erase all your database tables and their data.\n * Can be used only after connection to the database is established.\n */\n // TODO rename\n async dropDatabase(): Promise<void> {\n const queryRunner = await this.createQueryRunner(\"master\");\n try {\n if (this.driver instanceof SqlServerDriver || this.driver instanceof MysqlDriver) {\n const databases: string[] = this.driver.database ? [this.driver.database] : [];\n this.entityMetadatas.forEach(metadata => {\n if (metadata.database && databases.indexOf(metadata.database) === -1)\n databases.push(metadata.database);\n });\n await PromiseUtils.runInSequence(databases, database => queryRunner.clearDatabase(database));\n } else {\n await queryRunner.clearDatabase();\n }\n } finally {\n await queryRunner.release();\n }\n }\n\n /**\n * Runs all pending migrations.\n * Can be used only after connection to the database is established.\n */\n async runMigrations(options?: { transaction?: boolean }): Promise<Migration[]> {\n if (!this.isConnected)\n throw new CannotExecuteNotConnectedError(this.name);\n\n const migrationExecutor = new MigrationExecutor(this);\n if (options && options.transaction === false) {\n migrationExecutor.transaction = false;\n }\n const successMigrations = await migrationExecutor.executePendingMigrations();\n return successMigrations;\n }\n\n /**\n * Reverts last executed migration.\n * Can be used only after connection to the database is established.\n */\n async undoLastMigration(options?: { transaction?: boolean }): Promise<void> {\n\n if (!this.isConnected)\n throw new CannotExecuteNotConnectedError(this.name);\n\n const migrationExecutor = new MigrationExecutor(this);\n if (options && options.transaction === false) {\n migrationExecutor.transaction = false;\n }\n await migrationExecutor.undoLastMigration();\n }\n\n /**\n * Checks if entity metadata exist for the given entity class, target name or table name.\n */\n hasMetadata(target: Function|EntitySchema<any>|string): boolean {\n return !!this.findMetadata(target);\n }\n\n /**\n * Gets entity metadata for the given entity class or schema name.\n */\n getMetadata(target: Function|EntitySchema<any>|string): EntityMetadata {\n const metadata = this.findMetadata(target);\n if (!metadata)\n throw new EntityMetadataNotFoundError(target);\n\n return metadata;\n }\n\n /**\n * Gets repository for the given entity.\n */\n getRepository<Entity>(target: ObjectType<Entity>|EntitySchema<Entity>|string): Repository<Entity> {\n return this.manager.getRepository(target);\n }\n\n /**\n * Gets tree repository for the given entity class or name.\n * Only tree-type entities can have a TreeRepository, like ones decorated with @Tree decorator.\n */\n getTreeRepository<Entity>(target: ObjectType<Entity>|EntitySchema<Entity>|string): TreeRepository<Entity> {\n return this.manager.getTreeRepository(target);\n }\n\n /**\n * Gets mongodb-specific repository for the given entity class or name.\n * Works only if connection is mongodb-specific.\n */\n getMongoRepository<Entity>(target: ObjectType<Entity>|EntitySchema<Entity>|string): MongoRepository<Entity> {\n if (!(this.driver instanceof MongoDriver))\n throw new Error(`You can use getMongoRepository only for MongoDB connections.`);\n\n return this.manager.getRepository(target) as any;\n }\n\n /**\n * Gets custom entity repository marked with @EntityRepository decorator.\n */\n getCustomRepository<T>(customRepository: ObjectType<T>): T {\n return this.manager.getCustomRepository(customRepository);\n }\n\n /**\n * Wraps given function execution (and all operations made there) into a transaction.\n * All database operations must be executed using provided entity manager.\n */\n async transaction<T>(runInTransaction: (entityManager: EntityManager) => Promise<T>): Promise<T>;\n async transaction<T>(isolationLevel: IsolationLevel, runInTransaction: (entityManager: EntityManager) => Promise<T>): Promise<T>;\n async transaction<T>(\n isolationOrRunInTransaction: IsolationLevel | ((entityManager: EntityManager) => Promise<T>),\n runInTransactionParam?: (entityManager: EntityManager) => Promise<T>\n ): Promise<any> {\n return this.manager.transaction(\n isolationOrRunInTransaction as any,\n runInTransactionParam as any\n );\n }\n\n /**\n * Executes raw SQL query and returns raw database results.\n */\n async query(query: string, parameters?: any[], queryRunner?: QueryRunner): Promise<any> {\n if (this instanceof MongoEntityManager)\n throw new Error(`Queries aren't supported by MongoDB.`);\n\n if (queryRunner && queryRunner.isReleased)\n throw new QueryRunnerProviderAlreadyReleasedError();\n\n const usedQueryRunner = queryRunner || this.createQueryRunner(\"master\");\n\n try {\n return await usedQueryRunner.query(query, parameters); // await is needed here because we are using finally\n\n } finally {\n if (!queryRunner)\n await usedQueryRunner.release();\n }\n }\n\n /**\n * Creates a new query builder that can be used to build a sql query.\n */\n createQueryBuilder<Entity>(entityClass: ObjectType<Entity>|EntitySchema<Entity>|Function|string, alias: string, queryRunner?: QueryRunner): SelectQueryBuilder<Entity>;\n\n /**\n * Creates a new query builder that can be used to build a sql query.\n */\n createQueryBuilder(queryRunner?: QueryRunner): SelectQueryBuilder<any>;\n\n /**\n * Creates a new query builder that can be used to build a sql query.\n */\n createQueryBuilder<Entity>(entityOrRunner?: ObjectType<Entity>|EntitySchema<Entity>|Function|string|QueryRunner, alias?: string, queryRunner?: QueryRunner): SelectQueryBuilder<Entity> {\n if (this instanceof MongoEntityManager)\n throw new Error(`Query Builder is not supported by MongoDB.`);\n\n if (alias) {\n const metadata = this.getMetadata(entityOrRunner as Function|EntitySchema<Entity>|string);\n return new SelectQueryBuilder(this, queryRunner)\n .select(alias)\n .from(metadata.target, alias);\n\n } else {\n return new SelectQueryBuilder(this, entityOrRunner as QueryRunner|undefined);\n }\n }\n\n /**\n * Creates a query runner used for perform queries on a single database connection.\n * Using query runners you can control your queries to execute using single database connection and\n * manually control your database transaction.\n *\n * Mode is used in replication mode and indicates whatever you want to connect\n * to master database or any of slave databases.\n * If you perform writes you must use master database,\n * if you perform reads you can use slave databases.\n */\n createQueryRunner(mode: \"master\"|\"slave\" = \"master\"): QueryRunner {\n const queryRunner = this.driver.createQueryRunner(mode);\n const manager = this.createEntityManager(queryRunner);\n Object.assign(queryRunner, { manager: manager });\n return queryRunner;\n }\n\n /**\n * Gets entity metadata of the junction table (many-to-many table).\n */\n getManyToManyMetadata(entityTarget: Function|string, relationPropertyPath: string) {\n const relationMetadata = this.getMetadata(entityTarget).findRelationWithPropertyPath(relationPropertyPath);\n if (!relationMetadata)\n throw new Error(`Relation \"${relationPropertyPath}\" was not found in ${entityTarget} entity.`);\n if (!relationMetadata.isManyToMany)\n throw new Error(`Relation \"${entityTarget}#${relationPropertyPath}\" does not have a many-to-many relationship.` +\n `You can use this method only on many-to-many relations.`);\n\n return relationMetadata.junctionEntityMetadata;\n }\n\n /**\n * Creates an Entity Manager for the current connection with the help of the EntityManagerFactory.\n */\n createEntityManager(queryRunner?: QueryRunner): EntityManager {\n return new EntityManagerFactory().create(this, queryRunner);\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Finds exist entity metadata by the given entity class, target name or table name.\n */\n protected findMetadata(target: Function|EntitySchema<any>|string): EntityMetadata|undefined {\n return this.entityMetadatas.find(metadata => {\n if (metadata.target === target)\n return true;\n if (target instanceof EntitySchema) {\n return metadata.name === target.options.name;\n }\n if (typeof target === \"string\") {\n if (target.indexOf(\".\") !== -1) {\n return metadata.tablePath === target;\n } else {\n return metadata.name === target || metadata.tableName === target;\n }\n }\n\n return false;\n });\n }\n\n /**\n * Builds metadatas for all registered classes inside this connection.\n */\n protected buildMetadatas(): void {\n\n const connectionMetadataBuilder = new ConnectionMetadataBuilder(this);\n const entityMetadataValidator = new EntityMetadataValidator();\n\n // create subscribers instances if they are not disallowed from high-level (for example they can disallowed from migrations run process)\n const subscribers = connectionMetadataBuilder.buildSubscribers(this.options.subscribers || []);\n ObjectUtils.assign(this, { subscribers: subscribers });\n\n // build entity metadatas\n const entityMetadatas = connectionMetadataBuilder.buildEntityMetadatas(this.options.entities || []);\n ObjectUtils.assign(this, { entityMetadatas: entityMetadatas });\n\n // create migration instances\n const migrations = connectionMetadataBuilder.buildMigrations(this.options.migrations || []);\n ObjectUtils.assign(this, { migrations: migrations });\n\n // validate all created entity metadatas to make sure user created entities are valid and correct\n entityMetadataValidator.validateMany(this.entityMetadatas.filter(metadata => metadata.tableType !== \"view\"), this.driver);\n }\n\n}\n"],"sourceRoot":".."}
|