typeorm 0.2.42-dev.6523fcc → 0.2.42-dev.8898a71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -0
- package/browser/common/RelationType.d.ts +14 -0
- package/browser/common/RelationType.js +3 -0
- package/browser/common/RelationType.js.map +1 -0
- package/browser/connection/BaseConnectionOptions.d.ts +5 -0
- package/browser/connection/BaseConnectionOptions.js.map +1 -1
- package/browser/connection/Connection.d.ts +5 -1
- package/browser/connection/Connection.js +46 -30
- package/browser/connection/Connection.js.map +1 -1
- package/browser/connection/ConnectionMetadataBuilder.d.ts +3 -3
- package/browser/connection/ConnectionMetadataBuilder.js +54 -22
- package/browser/connection/ConnectionMetadataBuilder.js.map +1 -1
- package/browser/connection/ConnectionOptionsReader.js +33 -28
- package/browser/connection/ConnectionOptionsReader.js.map +1 -1
- package/browser/connection/options-reader/ConnectionOptionsEnvReader.js +1 -0
- package/browser/connection/options-reader/ConnectionOptionsEnvReader.js.map +1 -1
- package/browser/driver/aurora-data-api/AuroraDataApiQueryRunner.js +1 -1
- package/browser/driver/aurora-data-api/AuroraDataApiQueryRunner.js.map +1 -1
- package/browser/driver/better-sqlite3/BetterSqlite3Driver.js +7 -5
- package/browser/driver/better-sqlite3/BetterSqlite3Driver.js.map +1 -1
- package/browser/driver/cockroachdb/CockroachQueryRunner.js +1 -1
- package/browser/driver/cockroachdb/CockroachQueryRunner.js.map +1 -1
- package/browser/driver/mongodb/MongoConnectionOptions.d.ts +1 -1
- package/browser/driver/mongodb/MongoConnectionOptions.js.map +1 -1
- package/browser/driver/mysql/MysqlQueryRunner.js +1 -1
- package/browser/driver/mysql/MysqlQueryRunner.js.map +1 -1
- package/browser/driver/oracle/OracleQueryRunner.js +1 -1
- package/browser/driver/oracle/OracleQueryRunner.js.map +1 -1
- package/browser/driver/postgres/PostgresQueryRunner.js +39 -15
- package/browser/driver/postgres/PostgresQueryRunner.js.map +1 -1
- package/browser/driver/sap/SapQueryRunner.js +1 -1
- package/browser/driver/sap/SapQueryRunner.js.map +1 -1
- package/browser/driver/sqlite/SqliteDriver.js +11 -10
- package/browser/driver/sqlite/SqliteDriver.js.map +1 -1
- package/browser/driver/sqlite-abstract/AbstractSqliteQueryRunner.js +1 -1
- package/browser/driver/sqlite-abstract/AbstractSqliteQueryRunner.js.map +1 -1
- package/browser/entity-manager/EntityManager.js +1 -11
- package/browser/entity-manager/EntityManager.js.map +1 -1
- package/browser/entity-schema/EntitySchemaRelationOptions.d.ts +6 -0
- package/browser/entity-schema/EntitySchemaRelationOptions.js.map +1 -1
- package/browser/entity-schema/EntitySchemaTransformer.js +1 -0
- package/browser/entity-schema/EntitySchemaTransformer.js.map +1 -1
- package/browser/find-options/FindOneOptions.d.ts +6 -0
- package/browser/find-options/FindOneOptions.js.map +1 -1
- package/browser/find-options/FindOptionsUtils.js +4 -0
- package/browser/find-options/FindOptionsUtils.js.map +1 -1
- package/browser/find-options/operator/Like.d.ts +1 -1
- package/browser/find-options/operator/Like.js +1 -1
- package/browser/find-options/operator/Like.js.map +1 -1
- package/browser/find-options/operator/Not.d.ts +1 -1
- package/browser/find-options/operator/Not.js +1 -1
- package/browser/find-options/operator/Not.js.map +1 -1
- package/browser/globals.js +34 -7
- package/browser/globals.js.map +1 -1
- package/browser/index.d.ts +2 -0
- package/browser/index.js +2 -0
- package/browser/index.js.map +1 -1
- package/browser/migration/MigrationExecutor.js +1 -1
- package/browser/migration/MigrationExecutor.js.map +1 -1
- package/browser/query-builder/DeleteQueryBuilder.d.ts +3 -1
- package/browser/query-builder/DeleteQueryBuilder.js +3 -1
- package/browser/query-builder/DeleteQueryBuilder.js.map +1 -1
- package/browser/query-builder/InsertQueryBuilder.js +2 -2
- package/browser/query-builder/InsertQueryBuilder.js.map +1 -1
- package/browser/query-builder/NotBrackets.d.ts +7 -0
- package/browser/query-builder/NotBrackets.js +16 -0
- package/browser/query-builder/NotBrackets.js.map +1 -0
- package/browser/query-builder/QueryBuilder.d.ts +2 -1
- package/browser/query-builder/QueryBuilder.js +2 -1
- package/browser/query-builder/QueryBuilder.js.map +1 -1
- package/browser/query-builder/RelationLoader.js +11 -6
- package/browser/query-builder/RelationLoader.js.map +1 -1
- package/browser/query-builder/SelectQueryBuilder.d.ts +9 -0
- package/browser/query-builder/SelectQueryBuilder.js +27 -20
- package/browser/query-builder/SelectQueryBuilder.js.map +1 -1
- package/browser/query-builder/UpdateQueryBuilder.d.ts +3 -1
- package/browser/query-builder/UpdateQueryBuilder.js +3 -1
- package/browser/query-builder/UpdateQueryBuilder.js.map +1 -1
- package/browser/query-builder/WhereExpressionBuilder.d.ts +3 -1
- package/browser/query-builder/WhereExpressionBuilder.js.map +1 -1
- package/browser/query-runner/BaseQueryRunner.d.ts +2 -2
- package/browser/query-runner/BaseQueryRunner.js +3 -3
- package/browser/query-runner/BaseQueryRunner.js.map +1 -1
- package/browser/repository/TreeRepository.js +1 -1
- package/browser/repository/TreeRepository.js.map +1 -1
- package/browser/schema-builder/RdbmsSchemaBuilder.js +1 -1
- package/browser/schema-builder/RdbmsSchemaBuilder.js.map +1 -1
- package/browser/util/DirectoryExportedClassesLoader.d.ts +1 -1
- package/browser/util/DirectoryExportedClassesLoader.js +55 -31
- package/browser/util/DirectoryExportedClassesLoader.js.map +1 -1
- package/browser/util/ImportUtils.d.ts +1 -0
- package/browser/util/ImportUtils.js +90 -0
- package/browser/util/ImportUtils.js.map +1 -0
- package/browser/util/RandomGenerator.d.ts +0 -4
- package/browser/util/RandomGenerator.js +0 -9
- package/browser/util/RandomGenerator.js.map +1 -1
- package/commands/CommandUtils.d.ts +4 -0
- package/commands/CommandUtils.js +10 -0
- package/commands/CommandUtils.js.map +1 -1
- package/commands/InitCommand.d.ts +9 -7
- package/commands/InitCommand.js +72 -43
- package/commands/InitCommand.js.map +1 -1
- package/commands/MigrationCreateCommand.d.ts +2 -0
- package/commands/MigrationCreateCommand.js +7 -1
- package/commands/MigrationCreateCommand.js.map +1 -1
- package/commands/MigrationGenerateCommand.d.ts +2 -0
- package/commands/MigrationGenerateCommand.js +7 -1
- package/commands/MigrationGenerateCommand.js.map +1 -1
- package/common/RelationType.d.ts +14 -0
- package/common/RelationType.js +4 -0
- package/common/RelationType.js.map +1 -0
- package/connection/BaseConnectionOptions.d.ts +5 -0
- package/connection/BaseConnectionOptions.js.map +1 -1
- package/connection/Connection.d.ts +5 -1
- package/connection/Connection.js +46 -30
- package/connection/Connection.js.map +1 -1
- package/connection/ConnectionMetadataBuilder.d.ts +3 -3
- package/connection/ConnectionMetadataBuilder.js +53 -21
- package/connection/ConnectionMetadataBuilder.js.map +1 -1
- package/connection/ConnectionOptionsReader.js +32 -27
- package/connection/ConnectionOptionsReader.js.map +1 -1
- package/connection/options-reader/ConnectionOptionsEnvReader.js +1 -0
- package/connection/options-reader/ConnectionOptionsEnvReader.js.map +1 -1
- package/driver/aurora-data-api/AuroraDataApiQueryRunner.js +1 -1
- package/driver/aurora-data-api/AuroraDataApiQueryRunner.js.map +1 -1
- package/driver/better-sqlite3/BetterSqlite3Driver.js +7 -5
- package/driver/better-sqlite3/BetterSqlite3Driver.js.map +1 -1
- package/driver/cockroachdb/CockroachQueryRunner.js +1 -1
- package/driver/cockroachdb/CockroachQueryRunner.js.map +1 -1
- package/driver/mongodb/MongoConnectionOptions.d.ts +1 -1
- package/driver/mongodb/MongoConnectionOptions.js.map +1 -1
- package/driver/mysql/MysqlQueryRunner.js +1 -1
- package/driver/mysql/MysqlQueryRunner.js.map +1 -1
- package/driver/oracle/OracleQueryRunner.js +1 -1
- package/driver/oracle/OracleQueryRunner.js.map +1 -1
- package/driver/postgres/PostgresQueryRunner.js +39 -15
- package/driver/postgres/PostgresQueryRunner.js.map +1 -1
- package/driver/sap/SapQueryRunner.js +1 -1
- package/driver/sap/SapQueryRunner.js.map +1 -1
- package/driver/sqlite/SqliteDriver.js +11 -10
- package/driver/sqlite/SqliteDriver.js.map +1 -1
- package/driver/sqlite-abstract/AbstractSqliteQueryRunner.js +1 -1
- package/driver/sqlite-abstract/AbstractSqliteQueryRunner.js.map +1 -1
- package/entity-manager/EntityManager.js +1 -11
- package/entity-manager/EntityManager.js.map +1 -1
- package/entity-schema/EntitySchemaRelationOptions.d.ts +6 -0
- package/entity-schema/EntitySchemaRelationOptions.js.map +1 -1
- package/entity-schema/EntitySchemaTransformer.js +1 -0
- package/entity-schema/EntitySchemaTransformer.js.map +1 -1
- package/find-options/FindOneOptions.d.ts +6 -0
- package/find-options/FindOneOptions.js.map +1 -1
- package/find-options/FindOptionsUtils.js +4 -0
- package/find-options/FindOptionsUtils.js.map +1 -1
- package/find-options/operator/Like.d.ts +1 -1
- package/find-options/operator/Like.js +1 -1
- package/find-options/operator/Like.js.map +1 -1
- package/find-options/operator/Not.d.ts +1 -1
- package/find-options/operator/Not.js +1 -1
- package/find-options/operator/Not.js.map +1 -1
- package/globals.js +33 -6
- package/globals.js.map +1 -1
- package/index.d.ts +2 -0
- package/index.js +4 -1
- package/index.js.map +1 -1
- package/index.mjs +352 -0
- package/migration/MigrationExecutor.js +1 -1
- package/migration/MigrationExecutor.js.map +1 -1
- package/package.json +1 -1
- package/query-builder/DeleteQueryBuilder.d.ts +3 -1
- package/query-builder/DeleteQueryBuilder.js +3 -1
- package/query-builder/DeleteQueryBuilder.js.map +1 -1
- package/query-builder/InsertQueryBuilder.js +2 -2
- package/query-builder/InsertQueryBuilder.js.map +1 -1
- package/query-builder/NotBrackets.d.ts +7 -0
- package/query-builder/NotBrackets.js +19 -0
- package/query-builder/NotBrackets.js.map +1 -0
- package/query-builder/QueryBuilder.d.ts +2 -1
- package/query-builder/QueryBuilder.js +2 -1
- package/query-builder/QueryBuilder.js.map +1 -1
- package/query-builder/RelationLoader.js +11 -6
- package/query-builder/RelationLoader.js.map +1 -1
- package/query-builder/SelectQueryBuilder.d.ts +9 -0
- package/query-builder/SelectQueryBuilder.js +27 -20
- package/query-builder/SelectQueryBuilder.js.map +1 -1
- package/query-builder/UpdateQueryBuilder.d.ts +3 -1
- package/query-builder/UpdateQueryBuilder.js +3 -1
- package/query-builder/UpdateQueryBuilder.js.map +1 -1
- package/query-builder/WhereExpressionBuilder.d.ts +3 -1
- package/query-builder/WhereExpressionBuilder.js.map +1 -1
- package/query-runner/BaseQueryRunner.d.ts +2 -2
- package/query-runner/BaseQueryRunner.js +3 -3
- package/query-runner/BaseQueryRunner.js.map +1 -1
- package/repository/TreeRepository.js +1 -1
- package/repository/TreeRepository.js.map +1 -1
- package/schema-builder/RdbmsSchemaBuilder.js +1 -1
- package/schema-builder/RdbmsSchemaBuilder.js.map +1 -1
- package/util/DirectoryExportedClassesLoader.d.ts +1 -1
- package/util/DirectoryExportedClassesLoader.js +54 -31
- package/util/DirectoryExportedClassesLoader.js.map +1 -1
- package/util/ImportUtils.d.ts +1 -0
- package/util/ImportUtils.js +94 -0
- package/util/ImportUtils.js.map +1 -0
- package/util/RandomGenerator.d.ts +0 -4
- package/util/RandomGenerator.js +0 -9
- package/util/RandomGenerator.js.map +1 -1
package/README.md
CHANGED
|
@@ -71,6 +71,7 @@ TypeORM is highly influenced by other ORMs, such as [Hibernate](http://hibernate
|
|
|
71
71
|
* Supports MongoDB NoSQL database.
|
|
72
72
|
* Works in NodeJS / Browser / Ionic / Cordova / React Native / NativeScript / Expo / Electron platforms.
|
|
73
73
|
* TypeScript and JavaScript support.
|
|
74
|
+
* ESM and CommonJS support.
|
|
74
75
|
* Produced code is performant, flexible, clean and maintainable.
|
|
75
76
|
* Follows all possible best practices.
|
|
76
77
|
* CLI.
|
|
@@ -321,6 +322,9 @@ That's it, your application should successfully run and insert a new user into t
|
|
|
321
322
|
You can continue to work with this project and integrate other modules you need and start
|
|
322
323
|
creating more entities.
|
|
323
324
|
|
|
325
|
+
> You can generate an ESM project by running
|
|
326
|
+
`typeorm init --name MyProject --database postgres --module esm` command.
|
|
327
|
+
|
|
324
328
|
> You can generate an even more advanced project with express installed by running
|
|
325
329
|
`typeorm init --name MyProject --database mysql --express` command.
|
|
326
330
|
|
|
@@ -950,6 +954,40 @@ Note that we should use the `@JoinColumn` decorator only on one side of a relati
|
|
|
950
954
|
Whichever side you put this decorator on will be the owning side of the relationship.
|
|
951
955
|
The owning side of a relationship contains a column with a foreign key in the database.
|
|
952
956
|
|
|
957
|
+
### Relations in ESM projects
|
|
958
|
+
|
|
959
|
+
If you use ESM in your TypeScript project, you should use the `Relation` wrapper type in relation properties to avoid circular dependency issues.
|
|
960
|
+
Let's modify our entities:
|
|
961
|
+
|
|
962
|
+
```javascript
|
|
963
|
+
import { Entity, Column, PrimaryGeneratedColumn, OneToOne, JoinColumn, Relation } from "typeorm";
|
|
964
|
+
import { Photo } from "./Photo";
|
|
965
|
+
|
|
966
|
+
@Entity()
|
|
967
|
+
export class PhotoMetadata {
|
|
968
|
+
|
|
969
|
+
/* ... other columns */
|
|
970
|
+
|
|
971
|
+
@OneToOne(type => Photo, photo => photo.metadata)
|
|
972
|
+
@JoinColumn()
|
|
973
|
+
photo: Relation<Photo>;
|
|
974
|
+
}
|
|
975
|
+
```
|
|
976
|
+
|
|
977
|
+
```javascript
|
|
978
|
+
import { Entity, Column, PrimaryGeneratedColumn, OneToOne, Relation } from "typeorm";
|
|
979
|
+
import { PhotoMetadata } from "./PhotoMetadata";
|
|
980
|
+
|
|
981
|
+
@Entity()
|
|
982
|
+
export class Photo {
|
|
983
|
+
|
|
984
|
+
/* ... other columns */
|
|
985
|
+
|
|
986
|
+
@OneToOne(type => PhotoMetadata, photoMetadata => photoMetadata.photo)
|
|
987
|
+
metadata: Relation<PhotoMetadata>;
|
|
988
|
+
}
|
|
989
|
+
```
|
|
990
|
+
|
|
953
991
|
### Loading objects with their relations
|
|
954
992
|
|
|
955
993
|
Now let's load our photo and its photo metadata in a single query.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wrapper type for relation type definitions in entities.
|
|
3
|
+
* Used to circumvent ESM modules circular dependency issue caused by reflection metadata saving the type of the property.
|
|
4
|
+
*
|
|
5
|
+
* Usage example:
|
|
6
|
+
* @Entity()
|
|
7
|
+
* export default class User {
|
|
8
|
+
*
|
|
9
|
+
* @OneToOne(() => Profile, profile => profile.user)
|
|
10
|
+
* profile: Relation<Profile>;
|
|
11
|
+
*
|
|
12
|
+
* }
|
|
13
|
+
*/
|
|
14
|
+
export declare type Relation<T> = T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../browser/src/common/RelationType.ts"],"names":[],"mappings":"","file":"RelationType.js","sourcesContent":["/**\n * Wrapper type for relation type definitions in entities.\n * Used to circumvent ESM modules circular dependency issue caused by reflection metadata saving the type of the property.\n *\n * Usage example:\n * @Entity()\n * export default class User {\n *\n * @OneToOne(() => Profile, profile => profile.user)\n * profile: Relation<Profile>;\n *\n * }\n */\nexport type Relation<T> = T;\n"],"sourceRoot":".."}
|
|
@@ -45,6 +45,11 @@ export interface BaseConnectionOptions {
|
|
|
45
45
|
* Transaction mode for migrations to run in
|
|
46
46
|
*/
|
|
47
47
|
readonly migrationsTransactionMode?: "all" | "none" | "each";
|
|
48
|
+
/**
|
|
49
|
+
* Typeorm metadata table name, in case of different name from "typeorm_metadata".
|
|
50
|
+
* Accepts single string name.
|
|
51
|
+
*/
|
|
52
|
+
readonly metadataTableName?: string;
|
|
48
53
|
/**
|
|
49
54
|
* Naming strategy to be used to name tables and columns in the database.
|
|
50
55
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/connection/BaseConnectionOptions.ts"],"names":[],"mappings":"","file":"BaseConnectionOptions.js","sourcesContent":["import {EntitySchema} from \"../entity-schema/EntitySchema\";\nimport {LoggerOptions} from \"../logger/LoggerOptions\";\nimport {NamingStrategyInterface} from \"../naming-strategy/NamingStrategyInterface\";\nimport {DatabaseType} from \"../driver/types/DatabaseType\";\nimport {Logger} from \"../logger/Logger\";\nimport {Connection} from \"./Connection\";\nimport {QueryResultCache} from \"../cache/QueryResultCache\";\n\n/**\n * BaseConnectionOptions is set of connection options shared by all database types.\n */\nexport interface BaseConnectionOptions {\n\n /**\n * Database type. This value is required.\n */\n readonly type: DatabaseType;\n\n /**\n * Connection name. If connection name is not given then it will be called \"default\".\n * Different connections must have different names.\n */\n readonly name?: string;\n\n /**\n * Entities to be loaded for this connection.\n * Accepts both entity classes and directories where from entities need to be loaded.\n * Directories support glob patterns.\n */\n readonly entities?: ((Function|string|EntitySchema<any>))[];\n\n /**\n * Subscribers to be loaded for this connection.\n * Accepts both subscriber classes and directories where from subscribers need to be loaded.\n * Directories support glob patterns.\n */\n readonly subscribers?: (Function|string)[];\n\n /**\n * Migrations to be loaded for this connection.\n * Accepts both migration classes and directories where from migrations need to be loaded.\n * Directories support glob patterns.\n */\n readonly migrations?: (Function|string)[];\n\n /**\n * Migrations table name, in case of different name from \"migrations\".\n * Accepts single string name.\n */\n readonly migrationsTableName?: string;\n\n /**\n * Transaction mode for migrations to run in\n */\n readonly migrationsTransactionMode?: \"all\" | \"none\" | \"each\";\n\n /**\n * Naming strategy to be used to name tables and columns in the database.\n */\n readonly namingStrategy?: NamingStrategyInterface;\n\n /**\n * Logging options.\n */\n readonly logging?: LoggerOptions;\n\n /**\n * Logger instance used to log queries and events in the ORM.\n */\n readonly logger?: \"advanced-console\"|\"simple-console\"|\"file\"|\"debug\"|Logger;\n\n /**\n * Maximum number of milliseconds query should be executed before logger log a warning.\n */\n readonly maxQueryExecutionTime?: number;\n\n /**\n * Indicates if database schema should be auto created on every application launch.\n * Be careful with this option and don't use this in production - otherwise you can lose production data.\n * This option is useful during debug and development.\n * Alternative to it, you can use CLI and run schema:sync command.\n *\n * Note that for MongoDB database it does not create schema, because MongoDB is schemaless.\n * Instead, it syncs just by creating indices.\n */\n readonly synchronize?: boolean;\n\n /**\n * Indicates if migrations should be auto run on every application launch.\n * Alternative to it, you can use CLI and run migrations:run command.\n */\n readonly migrationsRun?: boolean;\n\n /**\n * Drops the schema each time connection is being established.\n * Be careful with this option and don't use this in production - otherwise you'll lose all production data.\n * This option is useful during debug and development.\n */\n readonly dropSchema?: boolean;\n\n /**\n * Prefix to use on all tables (collections) of this connection in the database.\n */\n readonly entityPrefix?: string;\n\n /**\n * When creating new Entity instances, skip all constructors when true.\n */\n readonly entitySkipConstructor?: boolean;\n\n /**\n * Extra connection options to be passed to the underlying driver.\n *\n * todo: deprecate this and move all database-specific types into hts own connection options object.\n */\n readonly extra?: any;\n\n /**\n * Allows to setup cache options.\n */\n readonly cache?: boolean|{\n\n /**\n * Type of caching.\n *\n * - \"database\" means cached values will be stored in the separate table in database. This is default value.\n * - \"redis\" means cached values will be stored inside redis. You must provide redis connection options.\n */\n readonly type?: \"database\" | \"redis\" | \"ioredis\" | \"ioredis/cluster\"; // todo: add mongodb and other cache providers as well in the future\n\n /**\n * Factory function for custom cache providers that implement QueryResultCache.\n */\n readonly provider?: (connection: Connection) => QueryResultCache;\n\n /**\n * Configurable table name for \"database\" type cache.\n * Default value is \"query-result-cache\"\n */\n readonly tableName?: string;\n\n /**\n * Used to provide redis connection options.\n */\n readonly options?: any;\n\n /**\n * If set to true then queries (using find methods and QueryBuilder's methods) will always be cached.\n */\n readonly alwaysEnabled?: boolean;\n\n /**\n * Time in milliseconds in which cache will expire.\n * This can be setup per-query.\n * Default value is 1000 which is equivalent to 1 second.\n */\n readonly duration?: number;\n\n /**\n * Used to specify if cache errors should be ignored, and pass through the call to the Database.\n */\n readonly ignoreErrors?: boolean;\n };\n\n /**\n * CLI settings.\n */\n readonly cli?: {\n\n /**\n * Directory where entities should be created by default.\n */\n readonly entitiesDir?: string;\n\n /**\n * Directory where migrations should be created by default.\n */\n readonly migrationsDir?: string;\n\n /**\n * Directory where subscribers should be created by default.\n */\n readonly subscribersDir?: string;\n\n };\n\n}\n"],"sourceRoot":".."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/connection/BaseConnectionOptions.ts"],"names":[],"mappings":"","file":"BaseConnectionOptions.js","sourcesContent":["import {EntitySchema} from \"../entity-schema/EntitySchema\";\nimport {LoggerOptions} from \"../logger/LoggerOptions\";\nimport {NamingStrategyInterface} from \"../naming-strategy/NamingStrategyInterface\";\nimport {DatabaseType} from \"../driver/types/DatabaseType\";\nimport {Logger} from \"../logger/Logger\";\nimport {Connection} from \"./Connection\";\nimport {QueryResultCache} from \"../cache/QueryResultCache\";\n\n/**\n * BaseConnectionOptions is set of connection options shared by all database types.\n */\nexport interface BaseConnectionOptions {\n\n /**\n * Database type. This value is required.\n */\n readonly type: DatabaseType;\n\n /**\n * Connection name. If connection name is not given then it will be called \"default\".\n * Different connections must have different names.\n */\n readonly name?: string;\n\n /**\n * Entities to be loaded for this connection.\n * Accepts both entity classes and directories where from entities need to be loaded.\n * Directories support glob patterns.\n */\n readonly entities?: ((Function|string|EntitySchema<any>))[];\n\n /**\n * Subscribers to be loaded for this connection.\n * Accepts both subscriber classes and directories where from subscribers need to be loaded.\n * Directories support glob patterns.\n */\n readonly subscribers?: (Function|string)[];\n\n /**\n * Migrations to be loaded for this connection.\n * Accepts both migration classes and directories where from migrations need to be loaded.\n * Directories support glob patterns.\n */\n readonly migrations?: (Function|string)[];\n\n /**\n * Migrations table name, in case of different name from \"migrations\".\n * Accepts single string name.\n */\n readonly migrationsTableName?: string;\n\n /**\n * Transaction mode for migrations to run in\n */\n readonly migrationsTransactionMode?: \"all\" | \"none\" | \"each\";\n\n /**\n * Typeorm metadata table name, in case of different name from \"typeorm_metadata\".\n * Accepts single string name.\n */\n readonly metadataTableName?: string;\n\n /**\n * Naming strategy to be used to name tables and columns in the database.\n */\n readonly namingStrategy?: NamingStrategyInterface;\n\n /**\n * Logging options.\n */\n readonly logging?: LoggerOptions;\n\n /**\n * Logger instance used to log queries and events in the ORM.\n */\n readonly logger?: \"advanced-console\"|\"simple-console\"|\"file\"|\"debug\"|Logger;\n\n /**\n * Maximum number of milliseconds query should be executed before logger log a warning.\n */\n readonly maxQueryExecutionTime?: number;\n\n /**\n * Indicates if database schema should be auto created on every application launch.\n * Be careful with this option and don't use this in production - otherwise you can lose production data.\n * This option is useful during debug and development.\n * Alternative to it, you can use CLI and run schema:sync command.\n *\n * Note that for MongoDB database it does not create schema, because MongoDB is schemaless.\n * Instead, it syncs just by creating indices.\n */\n readonly synchronize?: boolean;\n\n /**\n * Indicates if migrations should be auto run on every application launch.\n * Alternative to it, you can use CLI and run migrations:run command.\n */\n readonly migrationsRun?: boolean;\n\n /**\n * Drops the schema each time connection is being established.\n * Be careful with this option and don't use this in production - otherwise you'll lose all production data.\n * This option is useful during debug and development.\n */\n readonly dropSchema?: boolean;\n\n /**\n * Prefix to use on all tables (collections) of this connection in the database.\n */\n readonly entityPrefix?: string;\n\n /**\n * When creating new Entity instances, skip all constructors when true.\n */\n readonly entitySkipConstructor?: boolean;\n\n /**\n * Extra connection options to be passed to the underlying driver.\n *\n * todo: deprecate this and move all database-specific types into hts own connection options object.\n */\n readonly extra?: any;\n\n /**\n * Allows to setup cache options.\n */\n readonly cache?: boolean|{\n\n /**\n * Type of caching.\n *\n * - \"database\" means cached values will be stored in the separate table in database. This is default value.\n * - \"redis\" means cached values will be stored inside redis. You must provide redis connection options.\n */\n readonly type?: \"database\" | \"redis\" | \"ioredis\" | \"ioredis/cluster\"; // todo: add mongodb and other cache providers as well in the future\n\n /**\n * Factory function for custom cache providers that implement QueryResultCache.\n */\n readonly provider?: (connection: Connection) => QueryResultCache;\n\n /**\n * Configurable table name for \"database\" type cache.\n * Default value is \"query-result-cache\"\n */\n readonly tableName?: string;\n\n /**\n * Used to provide redis connection options.\n */\n readonly options?: any;\n\n /**\n * If set to true then queries (using find methods and QueryBuilder's methods) will always be cached.\n */\n readonly alwaysEnabled?: boolean;\n\n /**\n * Time in milliseconds in which cache will expire.\n * This can be setup per-query.\n * Default value is 1000 which is equivalent to 1 second.\n */\n readonly duration?: number;\n\n /**\n * Used to specify if cache errors should be ignored, and pass through the call to the Database.\n */\n readonly ignoreErrors?: boolean;\n };\n\n /**\n * CLI settings.\n */\n readonly cli?: {\n\n /**\n * Directory where entities should be created by default.\n */\n readonly entitiesDir?: string;\n\n /**\n * Directory where migrations should be created by default.\n */\n readonly migrationsDir?: string;\n\n /**\n * Directory where subscribers should be created by default.\n */\n readonly subscribersDir?: string;\n\n };\n\n}\n"],"sourceRoot":".."}
|
|
@@ -50,6 +50,10 @@ export declare class Connection {
|
|
|
50
50
|
* Naming strategy used in the connection.
|
|
51
51
|
*/
|
|
52
52
|
readonly namingStrategy: NamingStrategyInterface;
|
|
53
|
+
/**
|
|
54
|
+
* Name for the metadata table
|
|
55
|
+
*/
|
|
56
|
+
readonly metadataTableName: string;
|
|
53
57
|
/**
|
|
54
58
|
* Logger used to log orm events.
|
|
55
59
|
*/
|
|
@@ -202,5 +206,5 @@ export declare class Connection {
|
|
|
202
206
|
/**
|
|
203
207
|
* Builds metadatas for all registered classes inside this connection.
|
|
204
208
|
*/
|
|
205
|
-
protected buildMetadatas(): void
|
|
209
|
+
protected buildMetadatas(): Promise<void>;
|
|
206
210
|
}
|
|
@@ -50,6 +50,7 @@ var Connection = /** @class */ (function () {
|
|
|
50
50
|
this.driver = new DriverFactory().create(this);
|
|
51
51
|
this.manager = this.createEntityManager();
|
|
52
52
|
this.namingStrategy = options.namingStrategy || new DefaultNamingStrategy();
|
|
53
|
+
this.metadataTableName = options.metadataTableName || "typeorm_metadata";
|
|
53
54
|
this.queryResultCache = options.cache ? new QueryResultCacheFactory(this).create() : undefined;
|
|
54
55
|
this.relationLoader = new RelationLoader(this);
|
|
55
56
|
this.isConnected = false;
|
|
@@ -118,41 +119,44 @@ var Connection = /** @class */ (function () {
|
|
|
118
119
|
ObjectUtils.assign(this, { isConnected: true });
|
|
119
120
|
_a.label = 4;
|
|
120
121
|
case 4:
|
|
121
|
-
_a.trys.push([4,
|
|
122
|
+
_a.trys.push([4, 13, , 15]);
|
|
122
123
|
// build all metadatas registered in the current connection
|
|
123
|
-
this.buildMetadatas();
|
|
124
|
-
return [4 /*yield*/, this.driver.afterConnect()];
|
|
124
|
+
return [4 /*yield*/, this.buildMetadatas()];
|
|
125
125
|
case 5:
|
|
126
|
+
// build all metadatas registered in the current connection
|
|
126
127
|
_a.sent();
|
|
127
|
-
|
|
128
|
-
return [4 /*yield*/, this.dropDatabase()];
|
|
128
|
+
return [4 /*yield*/, this.driver.afterConnect()];
|
|
129
129
|
case 6:
|
|
130
130
|
_a.sent();
|
|
131
|
-
|
|
131
|
+
if (!this.options.dropSchema) return [3 /*break*/, 8];
|
|
132
|
+
return [4 /*yield*/, this.dropDatabase()];
|
|
132
133
|
case 7:
|
|
133
|
-
if (!this.options.synchronize) return [3 /*break*/, 9];
|
|
134
|
-
return [4 /*yield*/, this.synchronize()];
|
|
135
|
-
case 8:
|
|
136
134
|
_a.sent();
|
|
137
|
-
_a.label =
|
|
135
|
+
_a.label = 8;
|
|
136
|
+
case 8:
|
|
137
|
+
if (!this.options.synchronize) return [3 /*break*/, 10];
|
|
138
|
+
return [4 /*yield*/, this.synchronize()];
|
|
138
139
|
case 9:
|
|
139
|
-
|
|
140
|
-
|
|
140
|
+
_a.sent();
|
|
141
|
+
_a.label = 10;
|
|
141
142
|
case 10:
|
|
143
|
+
if (!this.options.migrationsRun) return [3 /*break*/, 12];
|
|
144
|
+
return [4 /*yield*/, this.runMigrations({ transaction: this.options.migrationsTransactionMode })];
|
|
145
|
+
case 11:
|
|
142
146
|
_a.sent();
|
|
143
|
-
_a.label =
|
|
144
|
-
case
|
|
145
|
-
case
|
|
147
|
+
_a.label = 12;
|
|
148
|
+
case 12: return [3 /*break*/, 15];
|
|
149
|
+
case 13:
|
|
146
150
|
error_1 = _a.sent();
|
|
147
151
|
// if for some reason build metadata fail (for example validation error during entity metadata check)
|
|
148
152
|
// connection needs to be closed
|
|
149
153
|
return [4 /*yield*/, this.close()];
|
|
150
|
-
case
|
|
154
|
+
case 14:
|
|
151
155
|
// if for some reason build metadata fail (for example validation error during entity metadata check)
|
|
152
156
|
// connection needs to be closed
|
|
153
157
|
_a.sent();
|
|
154
158
|
throw error_1;
|
|
155
|
-
case
|
|
159
|
+
case 15: return [2 /*return*/, this];
|
|
156
160
|
}
|
|
157
161
|
});
|
|
158
162
|
});
|
|
@@ -501,19 +505,31 @@ var Connection = /** @class */ (function () {
|
|
|
501
505
|
* Builds metadatas for all registered classes inside this connection.
|
|
502
506
|
*/
|
|
503
507
|
Connection.prototype.buildMetadatas = function () {
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
508
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
509
|
+
var connectionMetadataBuilder, entityMetadataValidator, subscribers, entityMetadatas, migrations;
|
|
510
|
+
return __generator(this, function (_a) {
|
|
511
|
+
switch (_a.label) {
|
|
512
|
+
case 0:
|
|
513
|
+
connectionMetadataBuilder = new ConnectionMetadataBuilder(this);
|
|
514
|
+
entityMetadataValidator = new EntityMetadataValidator();
|
|
515
|
+
return [4 /*yield*/, connectionMetadataBuilder.buildSubscribers(this.options.subscribers || [])];
|
|
516
|
+
case 1:
|
|
517
|
+
subscribers = _a.sent();
|
|
518
|
+
ObjectUtils.assign(this, { subscribers: subscribers });
|
|
519
|
+
return [4 /*yield*/, connectionMetadataBuilder.buildEntityMetadatas(this.options.entities || [])];
|
|
520
|
+
case 2:
|
|
521
|
+
entityMetadatas = _a.sent();
|
|
522
|
+
ObjectUtils.assign(this, { entityMetadatas: entityMetadatas });
|
|
523
|
+
return [4 /*yield*/, connectionMetadataBuilder.buildMigrations(this.options.migrations || [])];
|
|
524
|
+
case 3:
|
|
525
|
+
migrations = _a.sent();
|
|
526
|
+
ObjectUtils.assign(this, { migrations: migrations });
|
|
527
|
+
// validate all created entity metadatas to make sure user created entities are valid and correct
|
|
528
|
+
entityMetadataValidator.validateMany(this.entityMetadatas.filter(function (metadata) { return metadata.tableType !== "view"; }), this.driver);
|
|
529
|
+
return [2 /*return*/];
|
|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AAW,IAAI,EAAE,CAAC,CAAC;QAC/F,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC,CAAC;QAEvD,yBAAyB;QACzB,IAAM,eAAe,GAAG,yBAAyB,CAAC,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;QACpG,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,eAAe,EAAE,eAAe,EAAE,CAAC,CAAC;QAE/D,6BAA6B;QAC7B,IAAM,UAAU,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;IACL,iBAAC;AAAD,CAxdA,AAwdC,IAAA","file":"Connection.js","sourcesContent":["import {Driver} from \"../driver/Driver\";\nimport {Repository} from \"../repository/Repository\";\nimport {EntitySubscriberInterface} from \"../subscriber/EntitySubscriberInterface\";\nimport {EntityTarget} from \"../common/EntityTarget\";\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 {EntitySchema} from \"../entity-schema/EntitySchema\";\nimport {SqlServerDriver} from \"../driver/sqlserver/SqlServerDriver\";\nimport {MysqlDriver} from \"../driver/mysql/MysqlDriver\";\nimport {ObjectUtils} from \"../util/ObjectUtils\";\nimport {IsolationLevel} from \"../driver/types/IsolationLevel\";\nimport {AuroraDataApiDriver} from \"../driver/aurora-data-api/AuroraDataApiDriver\";\nimport {ReplicationMode} from \"../driver/types/ReplicationMode\";\nimport { TypeORMError } from \"../error/TypeORMError\";\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 // 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.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 TypeORMError(`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 TypeORMError(`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({ transaction: this.options.migrationsTransactionMode });\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 = this.createQueryRunner();\n try {\n if (this.driver instanceof SqlServerDriver || this.driver instanceof MysqlDriver || this.driver instanceof AuroraDataApiDriver) {\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\n for (const database of databases) {\n await queryRunner.clearDatabase(database);\n }\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?: \"all\" | \"none\" | \"each\" }): Promise<Migration[]> {\n if (!this.isConnected)\n throw new CannotExecuteNotConnectedError(this.name);\n\n const migrationExecutor = new MigrationExecutor(this);\n migrationExecutor.transaction = (options && options.transaction) || \"all\";\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?: \"all\" | \"none\" | \"each\" }): Promise<void> {\n\n if (!this.isConnected)\n throw new CannotExecuteNotConnectedError(this.name);\n\n const migrationExecutor = new MigrationExecutor(this);\n migrationExecutor.transaction = (options && options.transaction) || \"all\";\n\n await migrationExecutor.undoLastMigration();\n }\n\n /**\n * Lists all migrations and whether they have been run.\n * Returns true if there are pending migrations\n */\n async showMigrations(): Promise<boolean> {\n if (!this.isConnected) {\n throw new CannotExecuteNotConnectedError(this.name);\n }\n const migrationExecutor = new MigrationExecutor(this);\n return await migrationExecutor.showMigrations();\n }\n\n /**\n * Checks if entity metadata exist for the given entity class, target name or table name.\n */\n hasMetadata(target: EntityTarget<any>): 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: EntityTarget<any>): 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: EntityTarget<Entity>): 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: EntityTarget<Entity>): 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: EntityTarget<Entity>): MongoRepository<Entity> {\n if (!(this.driver instanceof MongoDriver))\n throw new TypeORMError(`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 TypeORMError(`Queries aren't supported by MongoDB.`);\n\n if (queryRunner && queryRunner.isReleased)\n throw new QueryRunnerProviderAlreadyReleasedError();\n\n const usedQueryRunner = queryRunner || this.createQueryRunner();\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: EntityTarget<Entity>, 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?: EntityTarget<Entity>|QueryRunner, alias?: string, queryRunner?: QueryRunner): SelectQueryBuilder<Entity> {\n if (this instanceof MongoEntityManager)\n throw new TypeORMError(`Query Builder is not supported by MongoDB.`);\n\n if (alias) {\n const metadata = this.getMetadata(entityOrRunner as EntityTarget<Entity>);\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: ReplicationMode = \"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: EntityTarget<any>, relationPropertyPath: string) {\n const relationMetadata = this.getMetadata(entityTarget).findRelationWithPropertyPath(relationPropertyPath);\n if (!relationMetadata)\n throw new TypeORMError(`Relation \"${relationPropertyPath}\" was not found in ${entityTarget} entity.`);\n if (!relationMetadata.isManyToMany)\n throw new TypeORMError(`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: EntityTarget<any>): 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"],"sourceRoot":".."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/connection/Connection.ts"],"names":[],"mappings":";AAMA,OAAO,EAAC,qBAAqB,EAAC,MAAM,0CAA0C,CAAC;AAC/E,OAAO,EAAC,8BAA8B,EAAC,MAAM,yCAAyC,CAAC;AACvF,OAAO,EAAC,kCAAkC,EAAC,MAAM,6CAA6C,CAAC;AAK/F,OAAO,EAAC,2BAA2B,EAAC,MAAM,sCAAsC,CAAC;AAEjF,OAAO,EAAC,iBAAiB,EAAC,MAAM,gCAAgC,CAAC;AAGjE,OAAO,EAAC,WAAW,EAAC,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAC,kBAAkB,EAAC,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAC,uBAAuB,EAAC,MAAM,6CAA6C,CAAC;AAEpF,OAAO,EAAC,uCAAuC,EAAC,MAAM,kDAAkD,CAAC;AACzG,OAAO,EAAC,oBAAoB,EAAC,MAAM,wCAAwC,CAAC;AAC5E,OAAO,EAAC,aAAa,EAAC,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAC,yBAAyB,EAAC,MAAM,6BAA6B,CAAC;AAEtE,OAAO,EAAC,kBAAkB,EAAC,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAC,aAAa,EAAC,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAC,uBAAuB,EAAC,MAAM,kCAAkC,CAAC;AAEzE,OAAO,EAAC,kBAAkB,EAAC,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAC,cAAc,EAAC,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAC,YAAY,EAAC,MAAM,+BAA+B,CAAC;AAC3D,OAAO,EAAC,eAAe,EAAC,MAAM,qCAAqC,CAAC;AACpE,OAAO,EAAC,WAAW,EAAC,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAC,WAAW,EAAC,MAAM,qBAAqB,CAAC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AyB,CAAC,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,IAAI,EAAE,CAAC,EAAA;;wBAA9F,WAAW,GAAG,SAAgF;wBACpG,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC,CAAC;wBAG/B,qBAAM,yBAAyB,CAAC,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC,EAAA;;wBAAnG,eAAe,GAAG,SAAiF;wBACzG,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,eAAe,EAAE,eAAe,EAAE,CAAC,CAAC;wBAG5C,qBAAM,yBAAyB,CAAC,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,IAAI,EAAE,CAAC,EAAA;;wBAA3F,UAAU,GAAG,SAA8E;wBACjG,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC;wBAErD,iGAAiG;wBACjG,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;;;;;KAC7H;IACL,iBAAC;AAAD,CA9dA,AA8dC,IAAA","file":"Connection.js","sourcesContent":["import {Driver} from \"../driver/Driver\";\nimport {Repository} from \"../repository/Repository\";\nimport {EntitySubscriberInterface} from \"../subscriber/EntitySubscriberInterface\";\nimport {EntityTarget} from \"../common/EntityTarget\";\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 {EntitySchema} from \"../entity-schema/EntitySchema\";\nimport {SqlServerDriver} from \"../driver/sqlserver/SqlServerDriver\";\nimport {MysqlDriver} from \"../driver/mysql/MysqlDriver\";\nimport {ObjectUtils} from \"../util/ObjectUtils\";\nimport {IsolationLevel} from \"../driver/types/IsolationLevel\";\nimport {AuroraDataApiDriver} from \"../driver/aurora-data-api/AuroraDataApiDriver\";\nimport {ReplicationMode} from \"../driver/types/ReplicationMode\";\nimport { TypeORMError } from \"../error/TypeORMError\";\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 * Name for the metadata table\n */\n readonly metadataTableName: string;\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 // 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.metadataTableName = options.metadataTableName || \"typeorm_metadata\";\n this.queryResultCache = options.cache ? new QueryResultCacheFactory(this).create() : undefined;\n this.relationLoader = new RelationLoader(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 TypeORMError(`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 TypeORMError(`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 await 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({ transaction: this.options.migrationsTransactionMode });\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 = this.createQueryRunner();\n try {\n if (this.driver instanceof SqlServerDriver || this.driver instanceof MysqlDriver || this.driver instanceof AuroraDataApiDriver) {\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\n for (const database of databases) {\n await queryRunner.clearDatabase(database);\n }\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?: \"all\" | \"none\" | \"each\" }): Promise<Migration[]> {\n if (!this.isConnected)\n throw new CannotExecuteNotConnectedError(this.name);\n\n const migrationExecutor = new MigrationExecutor(this);\n migrationExecutor.transaction = (options && options.transaction) || \"all\";\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?: \"all\" | \"none\" | \"each\" }): Promise<void> {\n\n if (!this.isConnected)\n throw new CannotExecuteNotConnectedError(this.name);\n\n const migrationExecutor = new MigrationExecutor(this);\n migrationExecutor.transaction = (options && options.transaction) || \"all\";\n\n await migrationExecutor.undoLastMigration();\n }\n\n /**\n * Lists all migrations and whether they have been run.\n * Returns true if there are pending migrations\n */\n async showMigrations(): Promise<boolean> {\n if (!this.isConnected) {\n throw new CannotExecuteNotConnectedError(this.name);\n }\n const migrationExecutor = new MigrationExecutor(this);\n return await migrationExecutor.showMigrations();\n }\n\n /**\n * Checks if entity metadata exist for the given entity class, target name or table name.\n */\n hasMetadata(target: EntityTarget<any>): 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: EntityTarget<any>): 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: EntityTarget<Entity>): 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: EntityTarget<Entity>): 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: EntityTarget<Entity>): MongoRepository<Entity> {\n if (!(this.driver instanceof MongoDriver))\n throw new TypeORMError(`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 TypeORMError(`Queries aren't supported by MongoDB.`);\n\n if (queryRunner && queryRunner.isReleased)\n throw new QueryRunnerProviderAlreadyReleasedError();\n\n const usedQueryRunner = queryRunner || this.createQueryRunner();\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: EntityTarget<Entity>, 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?: EntityTarget<Entity>|QueryRunner, alias?: string, queryRunner?: QueryRunner): SelectQueryBuilder<Entity> {\n if (this instanceof MongoEntityManager)\n throw new TypeORMError(`Query Builder is not supported by MongoDB.`);\n\n if (alias) {\n const metadata = this.getMetadata(entityOrRunner as EntityTarget<Entity>);\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: ReplicationMode = \"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: EntityTarget<any>, relationPropertyPath: string) {\n const relationMetadata = this.getMetadata(entityTarget).findRelationWithPropertyPath(relationPropertyPath);\n if (!relationMetadata)\n throw new TypeORMError(`Relation \"${relationPropertyPath}\" was not found in ${entityTarget} entity.`);\n if (!relationMetadata.isManyToMany)\n throw new TypeORMError(`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: EntityTarget<any>): 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 async buildMetadatas(): Promise<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 = await connectionMetadataBuilder.buildSubscribers(this.options.subscribers || []);\n ObjectUtils.assign(this, { subscribers: subscribers });\n\n // build entity metadatas\n const entityMetadatas = await connectionMetadataBuilder.buildEntityMetadatas(this.options.entities || []);\n ObjectUtils.assign(this, { entityMetadatas: entityMetadatas });\n\n // create migration instances\n const migrations = await 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"],"sourceRoot":".."}
|
|
@@ -12,13 +12,13 @@ export declare class ConnectionMetadataBuilder {
|
|
|
12
12
|
/**
|
|
13
13
|
* Builds migration instances for the given classes or directories.
|
|
14
14
|
*/
|
|
15
|
-
buildMigrations(migrations: (Function | string)[]): MigrationInterface[]
|
|
15
|
+
buildMigrations(migrations: (Function | string)[]): Promise<MigrationInterface[]>;
|
|
16
16
|
/**
|
|
17
17
|
* Builds subscriber instances for the given classes or directories.
|
|
18
18
|
*/
|
|
19
|
-
buildSubscribers(subscribers: (Function | string)[]): EntitySubscriberInterface<any>[]
|
|
19
|
+
buildSubscribers(subscribers: (Function | string)[]): Promise<EntitySubscriberInterface<any>[]>;
|
|
20
20
|
/**
|
|
21
21
|
* Builds entity metadatas for the given classes or directories.
|
|
22
22
|
*/
|
|
23
|
-
buildEntityMetadatas(entities: (Function | EntitySchema<any> | string)[]): EntityMetadata[]
|
|
23
|
+
buildEntityMetadatas(entities: (Function | EntitySchema<any> | string)[]): Promise<EntityMetadata[]>;
|
|
24
24
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __read, __spreadArray } from "tslib";
|
|
1
|
+
import { __awaiter, __generator, __read, __spreadArray } from "tslib";
|
|
2
2
|
import { importClassesFromDirectories } from "../util/DirectoryExportedClassesLoader";
|
|
3
3
|
import { OrmUtils } from "../util/OrmUtils";
|
|
4
4
|
import { getFromContainer } from "../container";
|
|
@@ -23,38 +23,70 @@ var ConnectionMetadataBuilder = /** @class */ (function () {
|
|
|
23
23
|
* Builds migration instances for the given classes or directories.
|
|
24
24
|
*/
|
|
25
25
|
ConnectionMetadataBuilder.prototype.buildMigrations = function (migrations) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
27
|
+
var _a, migrationClasses, migrationDirectories, allMigrationClasses, _b;
|
|
28
|
+
return __generator(this, function (_c) {
|
|
29
|
+
switch (_c.label) {
|
|
30
|
+
case 0:
|
|
31
|
+
_a = __read(OrmUtils.splitClassesAndStrings(migrations), 2), migrationClasses = _a[0], migrationDirectories = _a[1];
|
|
32
|
+
_b = [__spreadArray([], __read(migrationClasses), false)];
|
|
33
|
+
return [4 /*yield*/, importClassesFromDirectories(this.connection.logger, migrationDirectories)];
|
|
34
|
+
case 1:
|
|
35
|
+
allMigrationClasses = __spreadArray.apply(void 0, _b.concat([__read.apply(void 0, [(_c.sent())]), false]));
|
|
36
|
+
return [2 /*return*/, allMigrationClasses.map(function (migrationClass) { return getFromContainer(migrationClass); })];
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
});
|
|
29
40
|
};
|
|
30
41
|
/**
|
|
31
42
|
* Builds subscriber instances for the given classes or directories.
|
|
32
43
|
*/
|
|
33
44
|
ConnectionMetadataBuilder.prototype.buildSubscribers = function (subscribers) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
45
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
46
|
+
var _a, subscriberClasses, subscriberDirectories, allSubscriberClasses, _b;
|
|
47
|
+
return __generator(this, function (_c) {
|
|
48
|
+
switch (_c.label) {
|
|
49
|
+
case 0:
|
|
50
|
+
_a = __read(OrmUtils.splitClassesAndStrings(subscribers || []), 2), subscriberClasses = _a[0], subscriberDirectories = _a[1];
|
|
51
|
+
_b = [__spreadArray([], __read(subscriberClasses), false)];
|
|
52
|
+
return [4 /*yield*/, importClassesFromDirectories(this.connection.logger, subscriberDirectories)];
|
|
53
|
+
case 1:
|
|
54
|
+
allSubscriberClasses = __spreadArray.apply(void 0, _b.concat([__read.apply(void 0, [(_c.sent())]), false]));
|
|
55
|
+
return [2 /*return*/, getMetadataArgsStorage()
|
|
56
|
+
.filterSubscribers(allSubscriberClasses)
|
|
57
|
+
.map(function (metadata) { return getFromContainer(metadata.target); })];
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
39
61
|
};
|
|
40
62
|
/**
|
|
41
63
|
* Builds entity metadatas for the given classes or directories.
|
|
42
64
|
*/
|
|
43
65
|
ConnectionMetadataBuilder.prototype.buildEntityMetadatas = function (entities) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
66
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
67
|
+
var _a, entityClassesOrSchemas, entityDirectories, entityClasses, entitySchemas, allEntityClasses, _b, decoratorEntityMetadatas, metadataArgsStorageFromSchema, schemaEntityMetadatas;
|
|
68
|
+
return __generator(this, function (_c) {
|
|
69
|
+
switch (_c.label) {
|
|
70
|
+
case 0:
|
|
71
|
+
_a = __read(OrmUtils.splitClassesAndStrings(entities || []), 2), entityClassesOrSchemas = _a[0], entityDirectories = _a[1];
|
|
72
|
+
entityClasses = entityClassesOrSchemas.filter(function (entityClass) { return (entityClass instanceof EntitySchema) === false; });
|
|
73
|
+
entitySchemas = entityClassesOrSchemas.filter(function (entityClass) { return entityClass instanceof EntitySchema; });
|
|
74
|
+
_b = [__spreadArray([], __read(entityClasses), false)];
|
|
75
|
+
return [4 /*yield*/, importClassesFromDirectories(this.connection.logger, entityDirectories)];
|
|
76
|
+
case 1:
|
|
77
|
+
allEntityClasses = __spreadArray.apply(void 0, _b.concat([__read.apply(void 0, [(_c.sent())]), false]));
|
|
78
|
+
allEntityClasses.forEach(function (entityClass) {
|
|
79
|
+
if (entityClass instanceof EntitySchema) {
|
|
80
|
+
entitySchemas.push(entityClass);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
decoratorEntityMetadatas = new EntityMetadataBuilder(this.connection, getMetadataArgsStorage()).build(allEntityClasses);
|
|
84
|
+
metadataArgsStorageFromSchema = new EntitySchemaTransformer().transform(entitySchemas);
|
|
85
|
+
schemaEntityMetadatas = new EntityMetadataBuilder(this.connection, metadataArgsStorageFromSchema).build();
|
|
86
|
+
return [2 /*return*/, __spreadArray(__spreadArray([], __read(decoratorEntityMetadatas), false), __read(schemaEntityMetadatas), false)];
|
|
87
|
+
}
|
|
88
|
+
});
|
|
53
89
|
});
|
|
54
|
-
var decoratorEntityMetadatas = new EntityMetadataBuilder(this.connection, getMetadataArgsStorage()).build(allEntityClasses);
|
|
55
|
-
var metadataArgsStorageFromSchema = new EntitySchemaTransformer().transform(entitySchemas);
|
|
56
|
-
var schemaEntityMetadatas = new EntityMetadataBuilder(this.connection, metadataArgsStorageFromSchema).build();
|
|
57
|
-
return __spreadArray(__spreadArray([], __read(decoratorEntityMetadatas), false), __read(schemaEntityMetadatas), false);
|
|
58
90
|
};
|
|
59
91
|
return ConnectionMetadataBuilder;
|
|
60
92
|
}());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/connection/ConnectionMetadataBuilder.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,4BAA4B,EAAC,MAAM,wCAAwC,CAAC;AACpF,OAAO,EAAC,QAAQ,EAAC,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAC,gBAAgB,EAAC,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAC,sBAAsB,EAAC,MAAM,YAAY,CAAC;AAClD,OAAO,EAAC,qBAAqB,EAAC,MAAM,2CAA2C,CAAC;AAChF,OAAO,EAAC,uBAAuB,EAAC,MAAM,0CAA0C,CAAC;AAEjF,OAAO,EAAC,YAAY,EAAC,MAAM,+BAA+B,CAAC;AAI3D;;GAEG;AACH;IAEI,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,mCAAsB,UAAsB;QAAtB,eAAU,GAA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AC,IAAI,CAAC,UAAU,EAAE,sBAAsB,EAAE,CAAC,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;wBAExH,6BAA6B,GAAG,IAAI,uBAAuB,EAAE,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;wBACvF,qBAAqB,GAAG,IAAI,qBAAqB,CAAC,IAAI,CAAC,UAAU,EAAE,6BAA6B,CAAC,CAAC,KAAK,EAAE,CAAC;wBAEhH,6DAAW,wBAAwB,kBAAK,qBAAqB,WAAE;;;;KAClE;IAEL,gCAAC;AAAD,CAzDA,AAyDC,IAAA","file":"ConnectionMetadataBuilder.js","sourcesContent":["import {importClassesFromDirectories} from \"../util/DirectoryExportedClassesLoader\";\nimport {OrmUtils} from \"../util/OrmUtils\";\nimport {getFromContainer} from \"../container\";\nimport {MigrationInterface} from \"../migration/MigrationInterface\";\nimport {getMetadataArgsStorage} from \"../globals\";\nimport {EntityMetadataBuilder} from \"../metadata-builder/EntityMetadataBuilder\";\nimport {EntitySchemaTransformer} from \"../entity-schema/EntitySchemaTransformer\";\nimport {Connection} from \"./Connection\";\nimport {EntitySchema} from \"../entity-schema/EntitySchema\";\nimport {EntityMetadata} from \"../metadata/EntityMetadata\";\nimport {EntitySubscriberInterface} from \"../subscriber/EntitySubscriberInterface\";\n\n/**\n * Builds migration instances, subscriber instances and entity metadatas for the given classes.\n */\nexport class ConnectionMetadataBuilder {\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(protected connection: Connection) {\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Builds migration instances for the given classes or directories.\n */\n async buildMigrations(migrations: (Function|string)[]): Promise<MigrationInterface[]> {\n const [migrationClasses, migrationDirectories] = OrmUtils.splitClassesAndStrings(migrations);\n const allMigrationClasses = [...migrationClasses, ...(await importClassesFromDirectories(this.connection.logger, migrationDirectories))];\n return allMigrationClasses.map(migrationClass => getFromContainer<MigrationInterface>(migrationClass));\n }\n\n /**\n * Builds subscriber instances for the given classes or directories.\n */\n async buildSubscribers(subscribers: (Function|string)[]): Promise<EntitySubscriberInterface<any>[]> {\n const [subscriberClasses, subscriberDirectories] = OrmUtils.splitClassesAndStrings(subscribers || []);\n const allSubscriberClasses = [...subscriberClasses, ...(await importClassesFromDirectories(this.connection.logger, subscriberDirectories))];\n return getMetadataArgsStorage()\n .filterSubscribers(allSubscriberClasses)\n .map(metadata => getFromContainer<EntitySubscriberInterface<any>>(metadata.target));\n }\n\n /**\n * Builds entity metadatas for the given classes or directories.\n */\n async buildEntityMetadatas(entities: (Function|EntitySchema<any>|string)[]): Promise<EntityMetadata[]> {\n // todo: instead we need to merge multiple metadata args storages\n\n const [entityClassesOrSchemas, entityDirectories] = OrmUtils.splitClassesAndStrings(entities || []);\n const entityClasses: Function[] = entityClassesOrSchemas.filter(entityClass => (entityClass instanceof EntitySchema) === false) as any;\n const entitySchemas: EntitySchema<any>[] = entityClassesOrSchemas.filter(entityClass => entityClass instanceof EntitySchema) as any;\n\n const allEntityClasses = [...entityClasses, ...(await importClassesFromDirectories(this.connection.logger, entityDirectories))];\n allEntityClasses.forEach(entityClass => { // if we have entity schemas loaded from directories\n if (entityClass instanceof EntitySchema) {\n entitySchemas.push(entityClass);\n }\n });\n const decoratorEntityMetadatas = new EntityMetadataBuilder(this.connection, getMetadataArgsStorage()).build(allEntityClasses);\n\n const metadataArgsStorageFromSchema = new EntitySchemaTransformer().transform(entitySchemas);\n const schemaEntityMetadatas = new EntityMetadataBuilder(this.connection, metadataArgsStorageFromSchema).build();\n\n return [...decoratorEntityMetadatas, ...schemaEntityMetadatas];\n }\n\n}\n"],"sourceRoot":".."}
|