taon-typeorm 18.0.19 → 18.0.20
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/browser/esm2022/lib/typeorm/driver/cordova/CordovaDriver.mjs +1 -1
- package/browser/esm2022/lib/typeorm/driver/cordova/CordovaQueryRunner.mjs +1 -1
- package/browser/esm2022/lib/typeorm/driver/nativescript/NativescriptDriver.mjs +1 -1
- package/browser/esm2022/lib/typeorm/driver/nativescript/NativescriptQueryRunner.mjs +1 -1
- package/browser/esm2022/lib/typeorm/driver/react-native/ReactNativeDriver.mjs +1 -1
- package/browser/esm2022/lib/typeorm/driver/react-native/ReactNativeQueryRunner.mjs +1 -1
- package/browser/esm2022/lib/typeorm/driver/sqljs/SqljsDriver.mjs +1 -1
- package/browser/esm2022/lib/typeorm/driver/sqljs/SqljsQueryRunner.mjs +1 -1
- package/browser/esm2022/lib/typeorm/index.mjs +1 -3
- package/browser/fesm2022/taon-typeorm.mjs.map +1 -1
- package/client/esm2022/lib/typeorm/driver/cordova/CordovaDriver.mjs +1 -1
- package/client/esm2022/lib/typeorm/driver/cordova/CordovaQueryRunner.mjs +1 -1
- package/client/esm2022/lib/typeorm/driver/nativescript/NativescriptDriver.mjs +1 -1
- package/client/esm2022/lib/typeorm/driver/nativescript/NativescriptQueryRunner.mjs +1 -1
- package/client/esm2022/lib/typeorm/driver/react-native/ReactNativeDriver.mjs +1 -1
- package/client/esm2022/lib/typeorm/driver/react-native/ReactNativeQueryRunner.mjs +1 -1
- package/client/esm2022/lib/typeorm/driver/sqljs/SqljsDriver.mjs +1 -1
- package/client/esm2022/lib/typeorm/driver/sqljs/SqljsQueryRunner.mjs +1 -1
- package/client/esm2022/lib/typeorm/index.mjs +1 -3
- package/client/fesm2022/taon-typeorm.mjs.map +1 -1
- package/index.js +15 -2
- package/index.js.map +1 -1
- package/lib/build-info._auto-generated_.js.map +1 -1
- package/lib/index._auto-generated_.d.ts +1 -0
- package/lib/index._auto-generated_.js.map +1 -1
- package/lib/index.js +15 -2
- package/lib/index.js.map +1 -1
- package/lib/typeorm/cache/DbQueryResultCache.js +178 -231
- package/lib/typeorm/cache/DbQueryResultCache.js.map +1 -1
- package/lib/typeorm/cache/QueryResultCache.js.map +1 -1
- package/lib/typeorm/cache/QueryResultCacheFactory.js +11 -11
- package/lib/typeorm/cache/QueryResultCacheFactory.js.map +1 -1
- package/lib/typeorm/cache/QueryResultCacheOptions.js.map +1 -1
- package/lib/typeorm/cache/RedisQueryResultCache.js +121 -149
- package/lib/typeorm/cache/RedisQueryResultCache.js.map +1 -1
- package/lib/typeorm/cli-ts-node-commonjs.js.map +1 -1
- package/lib/typeorm/cli-ts-node-esm.js +7 -5
- package/lib/typeorm/cli-ts-node-esm.js.map +1 -1
- package/lib/typeorm/cli.d.ts +1 -1
- package/lib/typeorm/cli.js +15 -16
- package/lib/typeorm/cli.js.map +1 -1
- package/lib/typeorm/commands/CacheClearCommand.js +37 -65
- package/lib/typeorm/commands/CacheClearCommand.js.map +1 -1
- package/lib/typeorm/commands/CommandUtils.js +57 -112
- package/lib/typeorm/commands/CommandUtils.js.map +1 -1
- package/lib/typeorm/commands/EntityCreateCommand.js +35 -47
- package/lib/typeorm/commands/EntityCreateCommand.js.map +1 -1
- package/lib/typeorm/commands/InitCommand.js +397 -168
- package/lib/typeorm/commands/InitCommand.js.map +1 -1
- package/lib/typeorm/commands/MigrationCreateCommand.js +58 -52
- package/lib/typeorm/commands/MigrationCreateCommand.js.map +1 -1
- package/lib/typeorm/commands/MigrationGenerateCommand.js +141 -138
- package/lib/typeorm/commands/MigrationGenerateCommand.js.map +1 -1
- package/lib/typeorm/commands/MigrationRevertCommand.js +49 -77
- package/lib/typeorm/commands/MigrationRevertCommand.js.map +1 -1
- package/lib/typeorm/commands/MigrationRunCommand.js +52 -82
- package/lib/typeorm/commands/MigrationRunCommand.js.map +1 -1
- package/lib/typeorm/commands/MigrationShowCommand.js +32 -60
- package/lib/typeorm/commands/MigrationShowCommand.js.map +1 -1
- package/lib/typeorm/commands/QueryCommand.js +47 -83
- package/lib/typeorm/commands/QueryCommand.js.map +1 -1
- package/lib/typeorm/commands/SchemaDropCommand.js +33 -61
- package/lib/typeorm/commands/SchemaDropCommand.js.map +1 -1
- package/lib/typeorm/commands/SchemaLogCommand.js +57 -81
- package/lib/typeorm/commands/SchemaLogCommand.js.map +1 -1
- package/lib/typeorm/commands/SchemaSyncCommand.js +33 -61
- package/lib/typeorm/commands/SchemaSyncCommand.js.map +1 -1
- package/lib/typeorm/commands/SubscriberCreateCommand.js +35 -47
- package/lib/typeorm/commands/SubscriberCreateCommand.js.map +1 -1
- package/lib/typeorm/commands/VersionCommand.js +38 -54
- package/lib/typeorm/commands/VersionCommand.js.map +1 -1
- package/lib/typeorm/common/DeepPartial.js.map +1 -1
- package/lib/typeorm/common/EntityTarget.js.map +1 -1
- package/lib/typeorm/common/MixedList.js.map +1 -1
- package/lib/typeorm/common/NonNever.js.map +1 -1
- package/lib/typeorm/common/ObjectLiteral.js.map +1 -1
- package/lib/typeorm/common/ObjectType.js.map +1 -1
- package/lib/typeorm/common/RelationType.js.map +1 -1
- package/lib/typeorm/connection/BaseConnectionOptions.js.map +1 -1
- package/lib/typeorm/connection/Connection.js +3 -9
- package/lib/typeorm/connection/Connection.js.map +1 -1
- package/lib/typeorm/connection/ConnectionManager.js +23 -31
- package/lib/typeorm/connection/ConnectionManager.js.map +1 -1
- package/lib/typeorm/connection/ConnectionMetadataBuilder.js +48 -78
- package/lib/typeorm/connection/ConnectionMetadataBuilder.js.map +1 -1
- package/lib/typeorm/connection/ConnectionOptions.js.map +1 -1
- package/lib/typeorm/connection/ConnectionOptionsReader.js +146 -214
- package/lib/typeorm/connection/ConnectionOptionsReader.js.map +1 -1
- package/lib/typeorm/connection/options-reader/ConnectionOptionsEnvReader.js +50 -58
- package/lib/typeorm/connection/options-reader/ConnectionOptionsEnvReader.js.map +1 -1
- package/lib/typeorm/connection/options-reader/ConnectionOptionsXmlReader.js +45 -58
- package/lib/typeorm/connection/options-reader/ConnectionOptionsXmlReader.js.map +1 -1
- package/lib/typeorm/connection/options-reader/ConnectionOptionsYmlReader.js +14 -23
- package/lib/typeorm/connection/options-reader/ConnectionOptionsYmlReader.js.map +1 -1
- package/lib/typeorm/constants.js.map +1 -1
- package/lib/typeorm/container.js +9 -12
- package/lib/typeorm/container.js.map +1 -1
- package/lib/typeorm/data-source/BaseDataSourceOptions.js.map +1 -1
- package/lib/typeorm/data-source/DataSource.js +320 -478
- package/lib/typeorm/data-source/DataSource.js.map +1 -1
- package/lib/typeorm/data-source/DataSourceOptions.js.map +1 -1
- package/lib/typeorm/data-source/index.js +16 -3
- package/lib/typeorm/data-source/index.js.map +1 -1
- package/lib/typeorm/decorator/Check.js +5 -5
- package/lib/typeorm/decorator/Check.js.map +1 -1
- package/lib/typeorm/decorator/EntityRepository.js +1 -1
- package/lib/typeorm/decorator/EntityRepository.js.map +1 -1
- package/lib/typeorm/decorator/Exclusion.js +5 -5
- package/lib/typeorm/decorator/Exclusion.js.map +1 -1
- package/lib/typeorm/decorator/Generated.js +2 -3
- package/lib/typeorm/decorator/Generated.js.map +1 -1
- package/lib/typeorm/decorator/Index.js +5 -5
- package/lib/typeorm/decorator/Index.js.map +1 -1
- package/lib/typeorm/decorator/Unique.js +8 -8
- package/lib/typeorm/decorator/Unique.js.map +1 -1
- package/lib/typeorm/decorator/columns/Column.js +4 -4
- package/lib/typeorm/decorator/columns/Column.js.map +1 -1
- package/lib/typeorm/decorator/columns/CreateDateColumn.js +1 -1
- package/lib/typeorm/decorator/columns/CreateDateColumn.js.map +1 -1
- package/lib/typeorm/decorator/columns/DeleteDateColumn.js +1 -1
- package/lib/typeorm/decorator/columns/DeleteDateColumn.js.map +1 -1
- package/lib/typeorm/decorator/columns/ObjectIdColumn.js +1 -1
- package/lib/typeorm/decorator/columns/ObjectIdColumn.js.map +1 -1
- package/lib/typeorm/decorator/columns/PrimaryColumn.js +5 -5
- package/lib/typeorm/decorator/columns/PrimaryColumn.js.map +1 -1
- package/lib/typeorm/decorator/columns/PrimaryGeneratedColumn.js +4 -4
- package/lib/typeorm/decorator/columns/PrimaryGeneratedColumn.js.map +1 -1
- package/lib/typeorm/decorator/columns/UpdateDateColumn.js +1 -1
- package/lib/typeorm/decorator/columns/UpdateDateColumn.js.map +1 -1
- package/lib/typeorm/decorator/columns/VersionColumn.js +1 -1
- package/lib/typeorm/decorator/columns/VersionColumn.js.map +1 -1
- package/lib/typeorm/decorator/columns/ViewColumn.js +1 -1
- package/lib/typeorm/decorator/columns/ViewColumn.js.map +1 -1
- package/lib/typeorm/decorator/columns/VirtualColumn.js +5 -5
- package/lib/typeorm/decorator/columns/VirtualColumn.js.map +1 -1
- package/lib/typeorm/decorator/entity/ChildEntity.js +1 -1
- package/lib/typeorm/decorator/entity/ChildEntity.js.map +1 -1
- package/lib/typeorm/decorator/entity/Entity.js +4 -4
- package/lib/typeorm/decorator/entity/Entity.js.map +1 -1
- package/lib/typeorm/decorator/entity/TableInheritance.js +1 -1
- package/lib/typeorm/decorator/entity/TableInheritance.js.map +1 -1
- package/lib/typeorm/decorator/entity-view/ViewEntity.js +4 -4
- package/lib/typeorm/decorator/entity-view/ViewEntity.js.map +1 -1
- package/lib/typeorm/decorator/listeners/AfterInsert.js +2 -2
- package/lib/typeorm/decorator/listeners/AfterInsert.js.map +1 -1
- package/lib/typeorm/decorator/listeners/AfterLoad.js +2 -2
- package/lib/typeorm/decorator/listeners/AfterLoad.js.map +1 -1
- package/lib/typeorm/decorator/listeners/AfterRecover.js +2 -2
- package/lib/typeorm/decorator/listeners/AfterRecover.js.map +1 -1
- package/lib/typeorm/decorator/listeners/AfterRemove.js +2 -2
- package/lib/typeorm/decorator/listeners/AfterRemove.js.map +1 -1
- package/lib/typeorm/decorator/listeners/AfterSoftRemove.js +2 -2
- package/lib/typeorm/decorator/listeners/AfterSoftRemove.js.map +1 -1
- package/lib/typeorm/decorator/listeners/AfterUpdate.js +2 -2
- package/lib/typeorm/decorator/listeners/AfterUpdate.js.map +1 -1
- package/lib/typeorm/decorator/listeners/BeforeInsert.js +2 -2
- package/lib/typeorm/decorator/listeners/BeforeInsert.js.map +1 -1
- package/lib/typeorm/decorator/listeners/BeforeRecover.js +2 -2
- package/lib/typeorm/decorator/listeners/BeforeRecover.js.map +1 -1
- package/lib/typeorm/decorator/listeners/BeforeRemove.js +2 -2
- package/lib/typeorm/decorator/listeners/BeforeRemove.js.map +1 -1
- package/lib/typeorm/decorator/listeners/BeforeSoftRemove.js +2 -2
- package/lib/typeorm/decorator/listeners/BeforeSoftRemove.js.map +1 -1
- package/lib/typeorm/decorator/listeners/BeforeUpdate.js +2 -2
- package/lib/typeorm/decorator/listeners/BeforeUpdate.js.map +1 -1
- package/lib/typeorm/decorator/listeners/EventSubscriber.js +1 -1
- package/lib/typeorm/decorator/listeners/EventSubscriber.js.map +1 -1
- package/lib/typeorm/decorator/options/ColumnCommonOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/ColumnEmbeddedOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/ColumnEnumOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/ColumnHstoreOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/ColumnNumericOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/ColumnOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/ColumnWithLengthOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/ColumnWithWidthOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/EntityOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/IndexOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/JoinColumnOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/JoinTableMultipleColumnsOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/JoinTableOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/PrimaryGeneratedColumnIdentityOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/PrimaryGeneratedColumnNumericOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/PrimaryGeneratedColumnUUIDOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/RelationOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/SpatialColumnOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/TransactionOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/UniqueOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/ValueTransformer.js.map +1 -1
- package/lib/typeorm/decorator/options/ViewColumnOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/ViewEntityOptions.js.map +1 -1
- package/lib/typeorm/decorator/options/VirtualColumnOptions.js.map +1 -1
- package/lib/typeorm/decorator/relations/JoinColumn.js +3 -3
- package/lib/typeorm/decorator/relations/JoinColumn.js.map +1 -1
- package/lib/typeorm/decorator/relations/JoinTable.js +1 -1
- package/lib/typeorm/decorator/relations/JoinTable.js.map +1 -1
- package/lib/typeorm/decorator/relations/ManyToMany.js +5 -5
- package/lib/typeorm/decorator/relations/ManyToMany.js.map +1 -1
- package/lib/typeorm/decorator/relations/ManyToOne.js +5 -5
- package/lib/typeorm/decorator/relations/ManyToOne.js.map +1 -1
- package/lib/typeorm/decorator/relations/OneToMany.js +3 -3
- package/lib/typeorm/decorator/relations/OneToMany.js.map +1 -1
- package/lib/typeorm/decorator/relations/OneToOne.js +5 -5
- package/lib/typeorm/decorator/relations/OneToOne.js.map +1 -1
- package/lib/typeorm/decorator/relations/RelationCount.js +1 -1
- package/lib/typeorm/decorator/relations/RelationCount.js.map +1 -1
- package/lib/typeorm/decorator/relations/RelationId.js +1 -1
- package/lib/typeorm/decorator/relations/RelationId.js.map +1 -1
- package/lib/typeorm/decorator/tree/Tree.js +1 -1
- package/lib/typeorm/decorator/tree/Tree.js.map +1 -1
- package/lib/typeorm/decorator/tree/TreeChildren.js +4 -4
- package/lib/typeorm/decorator/tree/TreeChildren.js.map +1 -1
- package/lib/typeorm/decorator/tree/TreeLevelColumn.js +1 -1
- package/lib/typeorm/decorator/tree/TreeLevelColumn.js.map +1 -1
- package/lib/typeorm/decorator/tree/TreeParent.js +4 -4
- package/lib/typeorm/decorator/tree/TreeParent.js.map +1 -1
- package/lib/typeorm/driver/Driver.js.map +1 -1
- package/lib/typeorm/driver/DriverFactory.js +24 -27
- package/lib/typeorm/driver/DriverFactory.js.map +1 -1
- package/lib/typeorm/driver/DriverUtils.js +78 -126
- package/lib/typeorm/driver/DriverUtils.js.map +1 -1
- package/lib/typeorm/driver/Query.js +6 -5
- package/lib/typeorm/driver/Query.js.map +1 -1
- package/lib/typeorm/driver/SqlInMemory.js +4 -7
- package/lib/typeorm/driver/SqlInMemory.js.map +1 -1
- package/lib/typeorm/driver/aurora-mysql/AuroraMysqlConnection.js +9 -12
- package/lib/typeorm/driver/aurora-mysql/AuroraMysqlConnection.js.map +1 -1
- package/lib/typeorm/driver/aurora-mysql/AuroraMysqlConnectionCredentialsOptions.js.map +1 -1
- package/lib/typeorm/driver/aurora-mysql/AuroraMysqlConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/aurora-mysql/AuroraMysqlDriver.js +392 -399
- package/lib/typeorm/driver/aurora-mysql/AuroraMysqlDriver.js.map +1 -1
- package/lib/typeorm/driver/aurora-mysql/AuroraMysqlQueryRunner.js +1320 -2084
- package/lib/typeorm/driver/aurora-mysql/AuroraMysqlQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/aurora-postgres/AuroraPostgresConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/aurora-postgres/AuroraPostgresDriver.js +50 -78
- package/lib/typeorm/driver/aurora-postgres/AuroraPostgresDriver.js.map +1 -1
- package/lib/typeorm/driver/aurora-postgres/AuroraPostgresQueryRunner.js +89 -160
- package/lib/typeorm/driver/aurora-postgres/AuroraPostgresQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/better-sqlite3/BetterSqlite3ConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/better-sqlite3/BetterSqlite3Driver.js +78 -152
- package/lib/typeorm/driver/better-sqlite3/BetterSqlite3Driver.js.map +1 -1
- package/lib/typeorm/driver/better-sqlite3/BetterSqlite3QueryRunner.js +96 -155
- package/lib/typeorm/driver/better-sqlite3/BetterSqlite3QueryRunner.js.map +1 -1
- package/lib/typeorm/driver/capacitor/CapacitorConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/capacitor/CapacitorDriver.js +44 -89
- package/lib/typeorm/driver/capacitor/CapacitorDriver.js.map +1 -1
- package/lib/typeorm/driver/capacitor/CapacitorQueryRunner.js +70 -122
- package/lib/typeorm/driver/capacitor/CapacitorQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/cockroachdb/CockroachConnectionCredentialsOptions.js.map +1 -1
- package/lib/typeorm/driver/cockroachdb/CockroachConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/cockroachdb/CockroachDriver.js +368 -404
- package/lib/typeorm/driver/cockroachdb/CockroachDriver.js.map +1 -1
- package/lib/typeorm/driver/cockroachdb/CockroachQueryRunner.js +1752 -2862
- package/lib/typeorm/driver/cockroachdb/CockroachQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/cordova/CordovaConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/cordova/CordovaDriver.js +36 -58
- package/lib/typeorm/driver/cordova/CordovaDriver.js.map +1 -1
- package/lib/typeorm/driver/cordova/CordovaQueryRunner.js +86 -164
- package/lib/typeorm/driver/cordova/CordovaQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/expo/ExpoConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/expo/ExpoDriver.js +34 -44
- package/lib/typeorm/driver/expo/ExpoDriver.js.map +1 -1
- package/lib/typeorm/driver/expo/ExpoQueryRunner.js +114 -204
- package/lib/typeorm/driver/expo/ExpoQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/mongodb/MongoConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/mongodb/MongoDriver.js +269 -243
- package/lib/typeorm/driver/mongodb/MongoDriver.js.map +1 -1
- package/lib/typeorm/driver/mongodb/MongoQueryRunner.js +357 -793
- package/lib/typeorm/driver/mongodb/MongoQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/mongodb/typings.js.map +1 -1
- package/lib/typeorm/driver/mysql/MysqlConnectionCredentialsOptions.js.map +1 -1
- package/lib/typeorm/driver/mysql/MysqlConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/mysql/MysqlDriver.js +475 -480
- package/lib/typeorm/driver/mysql/MysqlDriver.js.map +1 -1
- package/lib/typeorm/driver/mysql/MysqlQueryRunner.js +1692 -2466
- package/lib/typeorm/driver/mysql/MysqlQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/nativescript/NativescriptConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/nativescript/NativescriptDriver.js +46 -50
- package/lib/typeorm/driver/nativescript/NativescriptDriver.js.map +1 -1
- package/lib/typeorm/driver/nativescript/NativescriptQueryRunner.js +62 -101
- package/lib/typeorm/driver/nativescript/NativescriptQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/oracle/OracleConnectionCredentialsOptions.js.map +1 -1
- package/lib/typeorm/driver/oracle/OracleConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/oracle/OracleDriver.js +345 -377
- package/lib/typeorm/driver/oracle/OracleDriver.js.map +1 -1
- package/lib/typeorm/driver/oracle/OracleQueryRunner.js +1484 -2384
- package/lib/typeorm/driver/oracle/OracleQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/postgres/PostgresConnectionCredentialsOptions.js.map +1 -1
- package/lib/typeorm/driver/postgres/PostgresConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/postgres/PostgresDriver.js +574 -690
- package/lib/typeorm/driver/postgres/PostgresDriver.js.map +1 -1
- package/lib/typeorm/driver/postgres/PostgresQueryRunner.js +2153 -3379
- package/lib/typeorm/driver/postgres/PostgresQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/react-native/ReactNativeConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/react-native/ReactNativeDriver.js +34 -44
- package/lib/typeorm/driver/react-native/ReactNativeDriver.js.map +1 -1
- package/lib/typeorm/driver/react-native/ReactNativeQueryRunner.js +60 -94
- package/lib/typeorm/driver/react-native/ReactNativeQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/sap/SapConnectionCredentialsOptions.js.map +1 -1
- package/lib/typeorm/driver/sap/SapConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/sap/SapDriver.js +310 -305
- package/lib/typeorm/driver/sap/SapDriver.js.map +1 -1
- package/lib/typeorm/driver/sap/SapQueryRunner.js +1635 -2561
- package/lib/typeorm/driver/sap/SapQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/spanner/SpannerConnectionCredentialsOptions.js.map +1 -1
- package/lib/typeorm/driver/spanner/SpannerConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/spanner/SpannerDriver.js +250 -236
- package/lib/typeorm/driver/spanner/SpannerDriver.js.map +1 -1
- package/lib/typeorm/driver/spanner/SpannerQueryRunner.js +1136 -2168
- package/lib/typeorm/driver/spanner/SpannerQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/sqlite/SqliteConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/sqlite/SqliteDriver.js +82 -169
- package/lib/typeorm/driver/sqlite/SqliteDriver.js.map +1 -1
- package/lib/typeorm/driver/sqlite/SqliteQueryRunner.js +78 -122
- package/lib/typeorm/driver/sqlite/SqliteQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/sqlite-abstract/AbstractSqliteDriver.js +280 -268
- package/lib/typeorm/driver/sqlite-abstract/AbstractSqliteDriver.js.map +1 -1
- package/lib/typeorm/driver/sqlite-abstract/AbstractSqliteQueryRunner.js +1158 -1990
- package/lib/typeorm/driver/sqlite-abstract/AbstractSqliteQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/sqljs/SqljsConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/sqljs/SqljsDriver.js +187 -253
- package/lib/typeorm/driver/sqljs/SqljsDriver.js.map +1 -1
- package/lib/typeorm/driver/sqljs/SqljsQueryRunner.js +88 -147
- package/lib/typeorm/driver/sqljs/SqljsQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/sqlserver/MssqlParameter.js +10 -13
- package/lib/typeorm/driver/sqlserver/MssqlParameter.js.map +1 -1
- package/lib/typeorm/driver/sqlserver/SqlServerConnectionCredentialsOptions.js.map +1 -1
- package/lib/typeorm/driver/sqlserver/SqlServerConnectionOptions.js.map +1 -1
- package/lib/typeorm/driver/sqlserver/SqlServerDriver.js +352 -372
- package/lib/typeorm/driver/sqlserver/SqlServerDriver.js.map +1 -1
- package/lib/typeorm/driver/sqlserver/SqlServerQueryRunner.js +1979 -3068
- package/lib/typeorm/driver/sqlserver/SqlServerQueryRunner.js.map +1 -1
- package/lib/typeorm/driver/sqlserver/authentication/AzureActiveDirectoryAccessTokenAuthentication.js.map +1 -1
- package/lib/typeorm/driver/sqlserver/authentication/AzureActiveDirectoryMsiAppServiceAuthentication.js.map +1 -1
- package/lib/typeorm/driver/sqlserver/authentication/AzureActiveDirectoryMsiVmAuthentication.js.map +1 -1
- package/lib/typeorm/driver/sqlserver/authentication/AzureActiveDirectoryPasswordAuthentication.js.map +1 -1
- package/lib/typeorm/driver/sqlserver/authentication/AzureActiveDirectoryServicePrincipalSecret.js.map +1 -1
- package/lib/typeorm/driver/sqlserver/authentication/DefaultAuthentication.js.map +1 -1
- package/lib/typeorm/driver/sqlserver/authentication/NtlmAuthentication.js.map +1 -1
- package/lib/typeorm/driver/types/ColumnTypes.js.map +1 -1
- package/lib/typeorm/driver/types/CteCapabilities.js.map +1 -1
- package/lib/typeorm/driver/types/DataTypeDefaults.js.map +1 -1
- package/lib/typeorm/driver/types/DatabaseType.js.map +1 -1
- package/lib/typeorm/driver/types/IsolationLevel.js.map +1 -1
- package/lib/typeorm/driver/types/MappedColumnTypes.js.map +1 -1
- package/lib/typeorm/driver/types/MetadataTableType.js.map +1 -1
- package/lib/typeorm/driver/types/ReplicationMode.js.map +1 -1
- package/lib/typeorm/driver/types/UpsertType.js.map +1 -1
- package/lib/typeorm/entity-manager/EntityManager.js +351 -469
- package/lib/typeorm/entity-manager/EntityManager.js.map +1 -1
- package/lib/typeorm/entity-manager/EntityManagerFactory.js +7 -10
- package/lib/typeorm/entity-manager/EntityManagerFactory.js.map +1 -1
- package/lib/typeorm/entity-manager/MongoEntityManager.js +371 -487
- package/lib/typeorm/entity-manager/MongoEntityManager.js.map +1 -1
- package/lib/typeorm/entity-manager/SqljsEntityManager.js +16 -37
- package/lib/typeorm/entity-manager/SqljsEntityManager.js.map +1 -1
- package/lib/typeorm/entity-schema/EntitySchema.js +5 -5
- package/lib/typeorm/entity-schema/EntitySchema.js.map +1 -1
- package/lib/typeorm/entity-schema/EntitySchemaCheckOptions.js.map +1 -1
- package/lib/typeorm/entity-schema/EntitySchemaColumnOptions.js.map +1 -1
- package/lib/typeorm/entity-schema/EntitySchemaEmbeddedColumnOptions.js +17 -5
- package/lib/typeorm/entity-schema/EntitySchemaEmbeddedColumnOptions.js.map +1 -1
- package/lib/typeorm/entity-schema/EntitySchemaEmbeddedError.js +11 -14
- package/lib/typeorm/entity-schema/EntitySchemaEmbeddedError.js.map +1 -1
- package/lib/typeorm/entity-schema/EntitySchemaExclusionOptions.js.map +1 -1
- package/lib/typeorm/entity-schema/EntitySchemaIndexOptions.js.map +1 -1
- package/lib/typeorm/entity-schema/EntitySchemaOptions.js +82 -5
- package/lib/typeorm/entity-schema/EntitySchemaOptions.js.map +1 -1
- package/lib/typeorm/entity-schema/EntitySchemaRelationIdOptions.js.map +1 -1
- package/lib/typeorm/entity-schema/EntitySchemaRelationOptions.js.map +1 -1
- package/lib/typeorm/entity-schema/EntitySchemaTransformer.js +51 -68
- package/lib/typeorm/entity-schema/EntitySchemaTransformer.js.map +1 -1
- package/lib/typeorm/entity-schema/EntitySchemaUniqueOptions.js.map +1 -1
- package/lib/typeorm/error/AlreadyHasActiveConnectionError.js +6 -9
- package/lib/typeorm/error/AlreadyHasActiveConnectionError.js.map +1 -1
- package/lib/typeorm/error/CannotAttachTreeChildrenEntityError.js +6 -9
- package/lib/typeorm/error/CannotAttachTreeChildrenEntityError.js.map +1 -1
- package/lib/typeorm/error/CannotConnectAlreadyConnectedError.js +5 -8
- package/lib/typeorm/error/CannotConnectAlreadyConnectedError.js.map +1 -1
- package/lib/typeorm/error/CannotCreateEntityIdMapError.js +7 -11
- package/lib/typeorm/error/CannotCreateEntityIdMapError.js.map +1 -1
- package/lib/typeorm/error/CannotDetermineEntityError.js +6 -9
- package/lib/typeorm/error/CannotDetermineEntityError.js.map +1 -1
- package/lib/typeorm/error/CannotExecuteNotConnectedError.js +5 -8
- package/lib/typeorm/error/CannotExecuteNotConnectedError.js.map +1 -1
- package/lib/typeorm/error/CannotGetEntityManagerNotConnectedError.js +5 -8
- package/lib/typeorm/error/CannotGetEntityManagerNotConnectedError.js.map +1 -1
- package/lib/typeorm/error/CannotReflectMethodParameterTypeError.js +7 -10
- package/lib/typeorm/error/CannotReflectMethodParameterTypeError.js.map +1 -1
- package/lib/typeorm/error/CircularRelationsError.js +6 -9
- package/lib/typeorm/error/CircularRelationsError.js.map +1 -1
- package/lib/typeorm/error/ColumnTypeUndefinedError.js +8 -11
- package/lib/typeorm/error/ColumnTypeUndefinedError.js.map +1 -1
- package/lib/typeorm/error/ConnectionIsNotSetError.js +5 -8
- package/lib/typeorm/error/ConnectionIsNotSetError.js.map +1 -1
- package/lib/typeorm/error/ConnectionNotFoundError.js +5 -8
- package/lib/typeorm/error/ConnectionNotFoundError.js.map +1 -1
- package/lib/typeorm/error/CustomRepositoryCannotInheritRepositoryError.js +7 -10
- package/lib/typeorm/error/CustomRepositoryCannotInheritRepositoryError.js.map +1 -1
- package/lib/typeorm/error/CustomRepositoryDoesNotHaveEntityError.js +7 -10
- package/lib/typeorm/error/CustomRepositoryDoesNotHaveEntityError.js.map +1 -1
- package/lib/typeorm/error/CustomRepositoryNotFoundError.js +7 -10
- package/lib/typeorm/error/CustomRepositoryNotFoundError.js.map +1 -1
- package/lib/typeorm/error/DataTypeNotSupportedError.js +7 -11
- package/lib/typeorm/error/DataTypeNotSupportedError.js.map +1 -1
- package/lib/typeorm/error/DriverOptionNotSetError.js +6 -9
- package/lib/typeorm/error/DriverOptionNotSetError.js.map +1 -1
- package/lib/typeorm/error/DriverPackageNotInstalledError.js +6 -9
- package/lib/typeorm/error/DriverPackageNotInstalledError.js.map +1 -1
- package/lib/typeorm/error/EntityMetadataNotFoundError.js +10 -14
- package/lib/typeorm/error/EntityMetadataNotFoundError.js.map +1 -1
- package/lib/typeorm/error/EntityNotFoundError.js +13 -17
- package/lib/typeorm/error/EntityNotFoundError.js.map +1 -1
- package/lib/typeorm/error/EntityPropertyNotFoundError.js +7 -11
- package/lib/typeorm/error/EntityPropertyNotFoundError.js.map +1 -1
- package/lib/typeorm/error/FindRelationsNotFoundError.js +9 -13
- package/lib/typeorm/error/FindRelationsNotFoundError.js.map +1 -1
- package/lib/typeorm/error/ForbiddenTransactionModeOverrideError.js +6 -9
- package/lib/typeorm/error/ForbiddenTransactionModeOverrideError.js.map +1 -1
- package/lib/typeorm/error/InitializedRelationError.js +7 -10
- package/lib/typeorm/error/InitializedRelationError.js.map +1 -1
- package/lib/typeorm/error/InsertValuesMissingError.js +6 -9
- package/lib/typeorm/error/InsertValuesMissingError.js.map +1 -1
- package/lib/typeorm/error/LimitOnUpdateNotSupportedError.js +5 -8
- package/lib/typeorm/error/LimitOnUpdateNotSupportedError.js.map +1 -1
- package/lib/typeorm/error/LockNotSupportedOnGivenDriverError.js +5 -8
- package/lib/typeorm/error/LockNotSupportedOnGivenDriverError.js.map +1 -1
- package/lib/typeorm/error/MetadataAlreadyExistsError.js +6 -9
- package/lib/typeorm/error/MetadataAlreadyExistsError.js.map +1 -1
- package/lib/typeorm/error/MetadataWithSuchNameAlreadyExistsError.js +6 -9
- package/lib/typeorm/error/MetadataWithSuchNameAlreadyExistsError.js.map +1 -1
- package/lib/typeorm/error/MissingDeleteDateColumnError.js +5 -8
- package/lib/typeorm/error/MissingDeleteDateColumnError.js.map +1 -1
- package/lib/typeorm/error/MissingDriverError.js +6 -10
- package/lib/typeorm/error/MissingDriverError.js.map +1 -1
- package/lib/typeorm/error/MissingJoinColumnError.js +12 -16
- package/lib/typeorm/error/MissingJoinColumnError.js.map +1 -1
- package/lib/typeorm/error/MissingJoinTableError.js +12 -16
- package/lib/typeorm/error/MissingJoinTableError.js.map +1 -1
- package/lib/typeorm/error/MissingPrimaryColumnError.js +6 -9
- package/lib/typeorm/error/MissingPrimaryColumnError.js.map +1 -1
- package/lib/typeorm/error/MustBeEntityError.js +5 -8
- package/lib/typeorm/error/MustBeEntityError.js.map +1 -1
- package/lib/typeorm/error/NamingStrategyNotFoundError.js +9 -13
- package/lib/typeorm/error/NamingStrategyNotFoundError.js.map +1 -1
- package/lib/typeorm/error/NestedSetMultipleRootError.js +5 -8
- package/lib/typeorm/error/NestedSetMultipleRootError.js.map +1 -1
- package/lib/typeorm/error/NoConnectionForRepositoryError.js +6 -9
- package/lib/typeorm/error/NoConnectionForRepositoryError.js.map +1 -1
- package/lib/typeorm/error/NoConnectionOptionError.js +6 -9
- package/lib/typeorm/error/NoConnectionOptionError.js.map +1 -1
- package/lib/typeorm/error/NoNeedToReleaseEntityManagerError.js +7 -10
- package/lib/typeorm/error/NoNeedToReleaseEntityManagerError.js.map +1 -1
- package/lib/typeorm/error/NoVersionOrUpdateDateColumnError.js +5 -8
- package/lib/typeorm/error/NoVersionOrUpdateDateColumnError.js.map +1 -1
- package/lib/typeorm/error/OffsetWithoutLimitNotSupportedError.js +7 -10
- package/lib/typeorm/error/OffsetWithoutLimitNotSupportedError.js.map +1 -1
- package/lib/typeorm/error/OptimisticLockCanNotBeUsedError.js +5 -8
- package/lib/typeorm/error/OptimisticLockCanNotBeUsedError.js.map +1 -1
- package/lib/typeorm/error/OptimisticLockVersionMismatchError.js +5 -8
- package/lib/typeorm/error/OptimisticLockVersionMismatchError.js.map +1 -1
- package/lib/typeorm/error/PersistedEntityNotFoundError.js +5 -8
- package/lib/typeorm/error/PersistedEntityNotFoundError.js.map +1 -1
- package/lib/typeorm/error/PessimisticLockTransactionRequiredError.js +5 -8
- package/lib/typeorm/error/PessimisticLockTransactionRequiredError.js.map +1 -1
- package/lib/typeorm/error/PrimaryColumnCannotBeNullableError.js +6 -9
- package/lib/typeorm/error/PrimaryColumnCannotBeNullableError.js.map +1 -1
- package/lib/typeorm/error/QueryFailedError.js +18 -17
- package/lib/typeorm/error/QueryFailedError.js.map +1 -1
- package/lib/typeorm/error/QueryRunnerAlreadyReleasedError.js +5 -8
- package/lib/typeorm/error/QueryRunnerAlreadyReleasedError.js.map +1 -1
- package/lib/typeorm/error/QueryRunnerProviderAlreadyReleasedError.js +6 -9
- package/lib/typeorm/error/QueryRunnerProviderAlreadyReleasedError.js.map +1 -1
- package/lib/typeorm/error/RepositoryNotTreeError.js +9 -13
- package/lib/typeorm/error/RepositoryNotTreeError.js.map +1 -1
- package/lib/typeorm/error/ReturningStatementNotSupportedError.js +5 -8
- package/lib/typeorm/error/ReturningStatementNotSupportedError.js.map +1 -1
- package/lib/typeorm/error/SubjectRemovedAndUpdatedError.js +6 -9
- package/lib/typeorm/error/SubjectRemovedAndUpdatedError.js.map +1 -1
- package/lib/typeorm/error/SubjectWithoutIdentifierError.js +5 -8
- package/lib/typeorm/error/SubjectWithoutIdentifierError.js.map +1 -1
- package/lib/typeorm/error/TransactionAlreadyStartedError.js +5 -8
- package/lib/typeorm/error/TransactionAlreadyStartedError.js.map +1 -1
- package/lib/typeorm/error/TransactionNotStartedError.js +5 -8
- package/lib/typeorm/error/TransactionNotStartedError.js.map +1 -1
- package/lib/typeorm/error/TreeRepositoryNotSupportedError.js +5 -8
- package/lib/typeorm/error/TreeRepositoryNotSupportedError.js.map +1 -1
- package/lib/typeorm/error/TypeORMError.js +9 -18
- package/lib/typeorm/error/TypeORMError.js.map +1 -1
- package/lib/typeorm/error/UpdateValuesMissingError.js +5 -8
- package/lib/typeorm/error/UpdateValuesMissingError.js.map +1 -1
- package/lib/typeorm/error/UsingJoinColumnIsNotAllowedError.js +6 -9
- package/lib/typeorm/error/UsingJoinColumnIsNotAllowedError.js.map +1 -1
- package/lib/typeorm/error/UsingJoinColumnOnlyOnOneSideAllowedError.js +7 -10
- package/lib/typeorm/error/UsingJoinColumnOnlyOnOneSideAllowedError.js.map +1 -1
- package/lib/typeorm/error/UsingJoinTableIsNotAllowedError.js +7 -10
- package/lib/typeorm/error/UsingJoinTableIsNotAllowedError.js.map +1 -1
- package/lib/typeorm/error/UsingJoinTableOnlyOnOneSideAllowedError.js +7 -10
- package/lib/typeorm/error/UsingJoinTableOnlyOnOneSideAllowedError.js.map +1 -1
- package/lib/typeorm/error/index.js +75 -62
- package/lib/typeorm/error/index.js.map +1 -1
- package/lib/typeorm/find-options/EqualOperator.js +6 -10
- package/lib/typeorm/find-options/EqualOperator.js.map +1 -1
- package/lib/typeorm/find-options/FindManyOptions.js.map +1 -1
- package/lib/typeorm/find-options/FindOneOptions.js.map +1 -1
- package/lib/typeorm/find-options/FindOperator.js +90 -94
- package/lib/typeorm/find-options/FindOperator.js.map +1 -1
- package/lib/typeorm/find-options/FindOperatorType.js.map +1 -1
- package/lib/typeorm/find-options/FindOptionsOrder.js.map +1 -1
- package/lib/typeorm/find-options/FindOptionsRelations.js.map +1 -1
- package/lib/typeorm/find-options/FindOptionsSelect.js.map +1 -1
- package/lib/typeorm/find-options/FindOptionsUtils.js +56 -87
- package/lib/typeorm/find-options/FindOptionsUtils.js.map +1 -1
- package/lib/typeorm/find-options/FindOptionsWhere.js.map +1 -1
- package/lib/typeorm/find-options/FindTreeOptions.js.map +1 -1
- package/lib/typeorm/find-options/JoinOptions.js.map +1 -1
- package/lib/typeorm/find-options/OrderByCondition.js.map +1 -1
- package/lib/typeorm/find-options/mongodb/MongoFindManyOptions.js.map +1 -1
- package/lib/typeorm/find-options/mongodb/MongoFindOneOptions.js.map +1 -1
- package/lib/typeorm/find-options/operator/And.js +2 -6
- package/lib/typeorm/find-options/operator/And.js.map +1 -1
- package/lib/typeorm/find-options/operator/Any.js +1 -1
- package/lib/typeorm/find-options/operator/Any.js.map +1 -1
- package/lib/typeorm/find-options/operator/ArrayContainedBy.js +1 -1
- package/lib/typeorm/find-options/operator/ArrayContainedBy.js.map +1 -1
- package/lib/typeorm/find-options/operator/ArrayContains.js +1 -1
- package/lib/typeorm/find-options/operator/ArrayContains.js.map +1 -1
- package/lib/typeorm/find-options/operator/ArrayOverlap.js +1 -1
- package/lib/typeorm/find-options/operator/ArrayOverlap.js.map +1 -1
- package/lib/typeorm/find-options/operator/Between.js +1 -1
- package/lib/typeorm/find-options/operator/Between.js.map +1 -1
- package/lib/typeorm/find-options/operator/Equal.js +1 -1
- package/lib/typeorm/find-options/operator/Equal.js.map +1 -1
- package/lib/typeorm/find-options/operator/ILike.js +1 -1
- package/lib/typeorm/find-options/operator/ILike.js.map +1 -1
- package/lib/typeorm/find-options/operator/In.js +1 -1
- package/lib/typeorm/find-options/operator/In.js.map +1 -1
- package/lib/typeorm/find-options/operator/IsNull.js +1 -1
- package/lib/typeorm/find-options/operator/IsNull.js.map +1 -1
- package/lib/typeorm/find-options/operator/LessThan.js +1 -1
- package/lib/typeorm/find-options/operator/LessThan.js.map +1 -1
- package/lib/typeorm/find-options/operator/LessThanOrEqual.js +1 -1
- package/lib/typeorm/find-options/operator/LessThanOrEqual.js.map +1 -1
- package/lib/typeorm/find-options/operator/Like.js +1 -1
- package/lib/typeorm/find-options/operator/Like.js.map +1 -1
- package/lib/typeorm/find-options/operator/MoreThan.js +1 -1
- package/lib/typeorm/find-options/operator/MoreThan.js.map +1 -1
- package/lib/typeorm/find-options/operator/MoreThanOrEqual.js +1 -1
- package/lib/typeorm/find-options/operator/MoreThanOrEqual.js.map +1 -1
- package/lib/typeorm/find-options/operator/Not.js +1 -1
- package/lib/typeorm/find-options/operator/Not.js.map +1 -1
- package/lib/typeorm/find-options/operator/Raw.js +1 -1
- package/lib/typeorm/find-options/operator/Raw.js.map +1 -1
- package/lib/typeorm/globals.js +33 -99
- package/lib/typeorm/globals.js.map +1 -1
- package/lib/typeorm/index.d.ts +0 -1
- package/lib/typeorm/index.js +136 -126
- package/lib/typeorm/index.js.map +1 -1
- package/lib/typeorm/logger/AdvancedConsoleLogger.js +26 -26
- package/lib/typeorm/logger/AdvancedConsoleLogger.js.map +1 -1
- package/lib/typeorm/logger/DebugLogger.js +24 -27
- package/lib/typeorm/logger/DebugLogger.js.map +1 -1
- package/lib/typeorm/logger/FileLogger.js +31 -30
- package/lib/typeorm/logger/FileLogger.js.map +1 -1
- package/lib/typeorm/logger/Logger.js.map +1 -1
- package/lib/typeorm/logger/LoggerFactory.js +9 -12
- package/lib/typeorm/logger/LoggerFactory.js.map +1 -1
- package/lib/typeorm/logger/LoggerOptions.js.map +1 -1
- package/lib/typeorm/logger/SimpleConsoleLogger.js +25 -25
- package/lib/typeorm/logger/SimpleConsoleLogger.js.map +1 -1
- package/lib/typeorm/metadata/CheckMetadata.js +30 -6
- package/lib/typeorm/metadata/CheckMetadata.js.map +1 -1
- package/lib/typeorm/metadata/ColumnMetadata.js +343 -199
- package/lib/typeorm/metadata/ColumnMetadata.js.map +1 -1
- package/lib/typeorm/metadata/EmbeddedMetadata.js +174 -153
- package/lib/typeorm/metadata/EmbeddedMetadata.js.map +1 -1
- package/lib/typeorm/metadata/EntityListenerMetadata.js +35 -15
- package/lib/typeorm/metadata/EntityListenerMetadata.js.map +1 -1
- package/lib/typeorm/metadata/EntityMetadata.js +516 -372
- package/lib/typeorm/metadata/EntityMetadata.js.map +1 -1
- package/lib/typeorm/metadata/ExclusionMetadata.js +30 -6
- package/lib/typeorm/metadata/ExclusionMetadata.js.map +1 -1
- package/lib/typeorm/metadata/ForeignKeyMetadata.js +60 -24
- package/lib/typeorm/metadata/ForeignKeyMetadata.js.map +1 -1
- package/lib/typeorm/metadata/IndexMetadata.js +119 -73
- package/lib/typeorm/metadata/IndexMetadata.js.map +1 -1
- package/lib/typeorm/metadata/RelationCountMetadata.js +40 -10
- package/lib/typeorm/metadata/RelationCountMetadata.js.map +1 -1
- package/lib/typeorm/metadata/RelationIdMetadata.js +47 -18
- package/lib/typeorm/metadata/RelationIdMetadata.js.map +1 -1
- package/lib/typeorm/metadata/RelationMetadata.js +270 -187
- package/lib/typeorm/metadata/RelationMetadata.js.map +1 -1
- package/lib/typeorm/metadata/UniqueMetadata.js +72 -47
- package/lib/typeorm/metadata/UniqueMetadata.js.map +1 -1
- package/lib/typeorm/metadata/types/ClosureTreeOptions.js.map +1 -1
- package/lib/typeorm/metadata/types/DeferrableType.js.map +1 -1
- package/lib/typeorm/metadata/types/EventListenerTypes.js +13 -16
- package/lib/typeorm/metadata/types/EventListenerTypes.js.map +1 -1
- package/lib/typeorm/metadata/types/OnDeleteType.js.map +1 -1
- package/lib/typeorm/metadata/types/OnUpdateType.js.map +1 -1
- package/lib/typeorm/metadata/types/PropertyTypeInFunction.js.map +1 -1
- package/lib/typeorm/metadata/types/RelationTypeInFunction.js.map +1 -1
- package/lib/typeorm/metadata/types/RelationTypes.js.map +1 -1
- package/lib/typeorm/metadata/types/TableTypes.js.map +1 -1
- package/lib/typeorm/metadata/types/TreeTypes.js.map +1 -1
- package/lib/typeorm/metadata-args/CheckMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/ColumnMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/DiscriminatorValueMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/EmbeddedMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/EntityListenerMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/EntityRepositoryMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/EntitySubscriberMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/ExclusionMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/GeneratedMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/IndexMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/InheritanceMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/JoinColumnMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/JoinTableMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/MetadataArgsStorage.js +108 -113
- package/lib/typeorm/metadata-args/MetadataArgsStorage.js.map +1 -1
- package/lib/typeorm/metadata-args/NamingStrategyMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/RelationCountMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/RelationIdMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/RelationMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/TableMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/TransactionEntityMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/TransactionRepositoryMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/TreeMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/UniqueMetadataArgs.js.map +1 -1
- package/lib/typeorm/metadata-args/types/ColumnMode.js.map +1 -1
- package/lib/typeorm/metadata-builder/ClosureJunctionEntityMetadataBuilder.js +14 -15
- package/lib/typeorm/metadata-builder/ClosureJunctionEntityMetadataBuilder.js.map +1 -1
- package/lib/typeorm/metadata-builder/EntityMetadataBuilder.js +291 -347
- package/lib/typeorm/metadata-builder/EntityMetadataBuilder.js.map +1 -1
- package/lib/typeorm/metadata-builder/EntityMetadataValidator.js +63 -77
- package/lib/typeorm/metadata-builder/EntityMetadataValidator.js.map +1 -1
- package/lib/typeorm/metadata-builder/JunctionEntityMetadataBuilder.js +64 -69
- package/lib/typeorm/metadata-builder/JunctionEntityMetadataBuilder.js.map +1 -1
- package/lib/typeorm/metadata-builder/MetadataUtils.js +12 -15
- package/lib/typeorm/metadata-builder/MetadataUtils.js.map +1 -1
- package/lib/typeorm/metadata-builder/RelationJoinColumnBuilder.js +43 -49
- package/lib/typeorm/metadata-builder/RelationJoinColumnBuilder.js.map +1 -1
- package/lib/typeorm/migration/Migration.js +23 -4
- package/lib/typeorm/migration/Migration.js.map +1 -1
- package/lib/typeorm/migration/MigrationExecutor.js +432 -691
- package/lib/typeorm/migration/MigrationExecutor.js.map +1 -1
- package/lib/typeorm/migration/MigrationInterface.js.map +1 -1
- package/lib/typeorm/naming-strategy/DefaultNamingStrategy.js +80 -84
- package/lib/typeorm/naming-strategy/DefaultNamingStrategy.js.map +1 -1
- package/lib/typeorm/naming-strategy/NamingStrategyInterface.js.map +1 -1
- package/lib/typeorm/persistence/EntityPersistExecutor.js +154 -212
- package/lib/typeorm/persistence/EntityPersistExecutor.js.map +1 -1
- package/lib/typeorm/persistence/Subject.js +162 -149
- package/lib/typeorm/persistence/Subject.js.map +1 -1
- package/lib/typeorm/persistence/SubjectChangeMap.js.map +1 -1
- package/lib/typeorm/persistence/SubjectChangedColumnsComputer.js +29 -35
- package/lib/typeorm/persistence/SubjectChangedColumnsComputer.js.map +1 -1
- package/lib/typeorm/persistence/SubjectDatabaseEntityLoader.js +99 -130
- package/lib/typeorm/persistence/SubjectDatabaseEntityLoader.js.map +1 -1
- package/lib/typeorm/persistence/SubjectExecutor.js +635 -879
- package/lib/typeorm/persistence/SubjectExecutor.js.map +1 -1
- package/lib/typeorm/persistence/SubjectTopoligicalSorter.js +62 -58
- package/lib/typeorm/persistence/SubjectTopoligicalSorter.js.map +1 -1
- package/lib/typeorm/persistence/subject-builder/CascadesSubjectBuilder.js +16 -19
- package/lib/typeorm/persistence/subject-builder/CascadesSubjectBuilder.js.map +1 -1
- package/lib/typeorm/persistence/subject-builder/ManyToManySubjectBuilder.js +50 -53
- package/lib/typeorm/persistence/subject-builder/ManyToManySubjectBuilder.js.map +1 -1
- package/lib/typeorm/persistence/subject-builder/OneToManySubjectBuilder.js +28 -33
- package/lib/typeorm/persistence/subject-builder/OneToManySubjectBuilder.js.map +1 -1
- package/lib/typeorm/persistence/subject-builder/OneToOneInverseSideSubjectBuilder.js +19 -20
- package/lib/typeorm/persistence/subject-builder/OneToOneInverseSideSubjectBuilder.js.map +1 -1
- package/lib/typeorm/persistence/tree/ClosureSubjectExecutor.js +202 -271
- package/lib/typeorm/persistence/tree/ClosureSubjectExecutor.js.map +1 -1
- package/lib/typeorm/persistence/tree/MaterializedPathSubjectExecutor.js +79 -121
- package/lib/typeorm/persistence/tree/MaterializedPathSubjectExecutor.js.map +1 -1
- package/lib/typeorm/persistence/tree/NestedSetSubjectExecutor.js +220 -353
- package/lib/typeorm/persistence/tree/NestedSetSubjectExecutor.js.map +1 -1
- package/lib/typeorm/platform/PlatformTools.js +66 -78
- package/lib/typeorm/platform/PlatformTools.js.map +1 -1
- package/lib/typeorm/query-builder/Alias.js +31 -32
- package/lib/typeorm/query-builder/Alias.js.map +1 -1
- package/lib/typeorm/query-builder/Brackets.js +8 -5
- package/lib/typeorm/query-builder/Brackets.js.map +1 -1
- package/lib/typeorm/query-builder/DeleteQueryBuilder.js +96 -120
- package/lib/typeorm/query-builder/DeleteQueryBuilder.js.map +1 -1
- package/lib/typeorm/query-builder/InsertOrUpdateOptions.js.map +1 -1
- package/lib/typeorm/query-builder/InsertQueryBuilder.js +321 -367
- package/lib/typeorm/query-builder/InsertQueryBuilder.js.map +1 -1
- package/lib/typeorm/query-builder/JoinAttribute.js +175 -206
- package/lib/typeorm/query-builder/JoinAttribute.js.map +1 -1
- package/lib/typeorm/query-builder/JoinOptions.js.map +1 -1
- package/lib/typeorm/query-builder/NotBrackets.js +4 -11
- package/lib/typeorm/query-builder/NotBrackets.js.map +1 -1
- package/lib/typeorm/query-builder/QueryBuilder.js +400 -646
- package/lib/typeorm/query-builder/QueryBuilder.js.map +1 -1
- package/lib/typeorm/query-builder/QueryBuilderCte.js.map +1 -1
- package/lib/typeorm/query-builder/QueryBuilderUtils.js +5 -9
- package/lib/typeorm/query-builder/QueryBuilderUtils.js.map +1 -1
- package/lib/typeorm/query-builder/QueryExpressionMap.js +304 -233
- package/lib/typeorm/query-builder/QueryExpressionMap.js.map +1 -1
- package/lib/typeorm/query-builder/QueryPartialEntity.js.map +1 -1
- package/lib/typeorm/query-builder/RelationIdLoader.js +166 -189
- package/lib/typeorm/query-builder/RelationIdLoader.js.map +1 -1
- package/lib/typeorm/query-builder/RelationLoader.js +81 -94
- package/lib/typeorm/query-builder/RelationLoader.js.map +1 -1
- package/lib/typeorm/query-builder/RelationQueryBuilder.js +91 -127
- package/lib/typeorm/query-builder/RelationQueryBuilder.js.map +1 -1
- package/lib/typeorm/query-builder/RelationRemover.js +121 -124
- package/lib/typeorm/query-builder/RelationRemover.js.map +1 -1
- package/lib/typeorm/query-builder/RelationUpdater.js +130 -148
- package/lib/typeorm/query-builder/RelationUpdater.js.map +1 -1
- package/lib/typeorm/query-builder/ReturningResultsEntityUpdator.js +131 -159
- package/lib/typeorm/query-builder/ReturningResultsEntityUpdator.js.map +1 -1
- package/lib/typeorm/query-builder/SelectQuery.js.map +1 -1
- package/lib/typeorm/query-builder/SelectQueryBuilder.js +955 -1211
- package/lib/typeorm/query-builder/SelectQueryBuilder.js.map +1 -1
- package/lib/typeorm/query-builder/SelectQueryBuilderOption.js.map +1 -1
- package/lib/typeorm/query-builder/SoftDeleteQueryBuilder.js +155 -194
- package/lib/typeorm/query-builder/SoftDeleteQueryBuilder.js.map +1 -1
- package/lib/typeorm/query-builder/UpdateQueryBuilder.js +204 -246
- package/lib/typeorm/query-builder/UpdateQueryBuilder.js.map +1 -1
- package/lib/typeorm/query-builder/WhereClause.js.map +1 -1
- package/lib/typeorm/query-builder/WhereExpressionBuilder.js.map +1 -1
- package/lib/typeorm/query-builder/relation-count/RelationCountAttribute.js +85 -98
- package/lib/typeorm/query-builder/relation-count/RelationCountAttribute.js.map +1 -1
- package/lib/typeorm/query-builder/relation-count/RelationCountLoadResult.js.map +1 -1
- package/lib/typeorm/query-builder/relation-count/RelationCountLoader.js +153 -172
- package/lib/typeorm/query-builder/relation-count/RelationCountLoader.js.map +1 -1
- package/lib/typeorm/query-builder/relation-count/RelationCountMetadataToAttributeTransformer.js +16 -17
- package/lib/typeorm/query-builder/relation-count/RelationCountMetadataToAttributeTransformer.js.map +1 -1
- package/lib/typeorm/query-builder/relation-id/RelationIdAttribute.js +93 -107
- package/lib/typeorm/query-builder/relation-id/RelationIdAttribute.js.map +1 -1
- package/lib/typeorm/query-builder/relation-id/RelationIdLoadResult.js.map +1 -1
- package/lib/typeorm/query-builder/relation-id/RelationIdLoader.js +259 -267
- package/lib/typeorm/query-builder/relation-id/RelationIdLoader.js.map +1 -1
- package/lib/typeorm/query-builder/relation-id/RelationIdMetadataToAttributeTransformer.js +16 -17
- package/lib/typeorm/query-builder/relation-id/RelationIdMetadataToAttributeTransformer.js.map +1 -1
- package/lib/typeorm/query-builder/result/DeleteResult.js +14 -8
- package/lib/typeorm/query-builder/result/DeleteResult.js.map +1 -1
- package/lib/typeorm/query-builder/result/InsertResult.js +19 -18
- package/lib/typeorm/query-builder/result/InsertResult.js.map +1 -1
- package/lib/typeorm/query-builder/result/UpdateResult.js +24 -18
- package/lib/typeorm/query-builder/result/UpdateResult.js.map +1 -1
- package/lib/typeorm/query-builder/transformer/DocumentToEntityTransformer.js +24 -26
- package/lib/typeorm/query-builder/transformer/DocumentToEntityTransformer.js.map +1 -1
- package/lib/typeorm/query-builder/transformer/PlainObjectToDatabaseEntityTransformer.js +77 -112
- package/lib/typeorm/query-builder/transformer/PlainObjectToDatabaseEntityTransformer.js.map +1 -1
- package/lib/typeorm/query-builder/transformer/PlainObjectToNewEntityTransformer.js +16 -22
- package/lib/typeorm/query-builder/transformer/PlainObjectToNewEntityTransformer.js.map +1 -1
- package/lib/typeorm/query-builder/transformer/RawSqlResultsToEntityTransformer.js +117 -132
- package/lib/typeorm/query-builder/transformer/RawSqlResultsToEntityTransformer.js.map +1 -1
- package/lib/typeorm/query-runner/BaseQueryRunner.js +227 -393
- package/lib/typeorm/query-runner/BaseQueryRunner.js.map +1 -1
- package/lib/typeorm/query-runner/QueryLock.js +19 -32
- package/lib/typeorm/query-runner/QueryLock.js.map +1 -1
- package/lib/typeorm/query-runner/QueryResult.js +14 -9
- package/lib/typeorm/query-runner/QueryResult.js.map +1 -1
- package/lib/typeorm/query-runner/QueryRunner.js.map +1 -1
- package/lib/typeorm/repository/AbstractRepository.js +46 -50
- package/lib/typeorm/repository/AbstractRepository.js.map +1 -1
- package/lib/typeorm/repository/BaseEntity.js +106 -123
- package/lib/typeorm/repository/BaseEntity.js.map +1 -1
- package/lib/typeorm/repository/EntityId.js.map +1 -1
- package/lib/typeorm/repository/FindTreesOptions.js.map +1 -1
- package/lib/typeorm/repository/MongoRepository.js +109 -135
- package/lib/typeorm/repository/MongoRepository.js.map +1 -1
- package/lib/typeorm/repository/RemoveOptions.js.map +1 -1
- package/lib/typeorm/repository/Repository.js +108 -140
- package/lib/typeorm/repository/Repository.js.map +1 -1
- package/lib/typeorm/repository/SaveOptions.js.map +1 -1
- package/lib/typeorm/repository/TreeRepository.js +107 -154
- package/lib/typeorm/repository/TreeRepository.js.map +1 -1
- package/lib/typeorm/repository/UpsertOptions.js.map +1 -1
- package/lib/typeorm/schema-builder/MongoSchemaBuilder.js +30 -42
- package/lib/typeorm/schema-builder/MongoSchemaBuilder.js.map +1 -1
- package/lib/typeorm/schema-builder/RdbmsSchemaBuilder.js +727 -1938
- package/lib/typeorm/schema-builder/RdbmsSchemaBuilder.js.map +1 -1
- package/lib/typeorm/schema-builder/SchemaBuilder.js.map +1 -1
- package/lib/typeorm/schema-builder/options/TableCheckOptions.js.map +1 -1
- package/lib/typeorm/schema-builder/options/TableColumnOptions.js.map +1 -1
- package/lib/typeorm/schema-builder/options/TableExclusionOptions.js.map +1 -1
- package/lib/typeorm/schema-builder/options/TableForeignKeyOptions.js.map +1 -1
- package/lib/typeorm/schema-builder/options/TableIndexOptions.js.map +1 -1
- package/lib/typeorm/schema-builder/options/TableOptions.js.map +1 -1
- package/lib/typeorm/schema-builder/options/TableUniqueOptions.js.map +1 -1
- package/lib/typeorm/schema-builder/options/ViewOptions.js.map +1 -1
- package/lib/typeorm/schema-builder/table/Table.js +160 -157
- package/lib/typeorm/schema-builder/table/Table.js.map +1 -1
- package/lib/typeorm/schema-builder/table/TableCheck.js +24 -15
- package/lib/typeorm/schema-builder/table/TableCheck.js.map +1 -1
- package/lib/typeorm/schema-builder/table/TableColumn.js +123 -41
- package/lib/typeorm/schema-builder/table/TableColumn.js.map +1 -1
- package/lib/typeorm/schema-builder/table/TableExclusion.js +19 -9
- package/lib/typeorm/schema-builder/table/TableExclusion.js.map +1 -1
- package/lib/typeorm/schema-builder/table/TableForeignKey.js +52 -20
- package/lib/typeorm/schema-builder/table/TableForeignKey.js.map +1 -1
- package/lib/typeorm/schema-builder/table/TableIndex.js +52 -16
- package/lib/typeorm/schema-builder/table/TableIndex.js.map +1 -1
- package/lib/typeorm/schema-builder/table/TableUnique.js +26 -16
- package/lib/typeorm/schema-builder/table/TableUnique.js.map +1 -1
- package/lib/typeorm/schema-builder/util/TableUtils.js +5 -8
- package/lib/typeorm/schema-builder/util/TableUtils.js.map +1 -1
- package/lib/typeorm/schema-builder/util/ViewUtils.js +4 -7
- package/lib/typeorm/schema-builder/util/ViewUtils.js.map +1 -1
- package/lib/typeorm/schema-builder/view/View.js +32 -10
- package/lib/typeorm/schema-builder/view/View.js.map +1 -1
- package/lib/typeorm/subscriber/Broadcaster.js +180 -216
- package/lib/typeorm/subscriber/Broadcaster.js.map +1 -1
- package/lib/typeorm/subscriber/BroadcasterResult.js +16 -29
- package/lib/typeorm/subscriber/BroadcasterResult.js.map +1 -1
- package/lib/typeorm/subscriber/EntitySubscriberInterface.js.map +1 -1
- package/lib/typeorm/subscriber/event/InsertEvent.js.map +1 -1
- package/lib/typeorm/subscriber/event/LoadEvent.js.map +1 -1
- package/lib/typeorm/subscriber/event/RecoverEvent.js.map +1 -1
- package/lib/typeorm/subscriber/event/RemoveEvent.js.map +1 -1
- package/lib/typeorm/subscriber/event/SoftRemoveEvent.js.map +1 -1
- package/lib/typeorm/subscriber/event/TransactionCommitEvent.js.map +1 -1
- package/lib/typeorm/subscriber/event/TransactionRollbackEvent.js.map +1 -1
- package/lib/typeorm/subscriber/event/TransactionStartEvent.js.map +1 -1
- package/lib/typeorm/subscriber/event/UpdateEvent.js.map +1 -1
- package/lib/typeorm/util/ApplyValueTransformers.js +9 -12
- package/lib/typeorm/util/ApplyValueTransformers.js.map +1 -1
- package/lib/typeorm/util/DateUtils.js +44 -53
- package/lib/typeorm/util/DateUtils.js.map +1 -1
- package/lib/typeorm/util/DepGraph.js +50 -53
- package/lib/typeorm/util/DepGraph.js.map +1 -1
- package/lib/typeorm/util/DirectoryExportedClassesLoader.js +48 -70
- package/lib/typeorm/util/DirectoryExportedClassesLoader.js.map +1 -1
- package/lib/typeorm/util/ImportUtils.js +43 -65
- package/lib/typeorm/util/ImportUtils.js.map +1 -1
- package/lib/typeorm/util/InstanceChecker.js +64 -67
- package/lib/typeorm/util/InstanceChecker.js.map +1 -1
- package/lib/typeorm/util/ObjectUtils.js +13 -42
- package/lib/typeorm/util/ObjectUtils.js.map +1 -1
- package/lib/typeorm/util/OrmUtils.js +91 -158
- package/lib/typeorm/util/OrmUtils.js.map +1 -1
- package/lib/typeorm/util/PathUtils.js +8 -8
- package/lib/typeorm/util/PathUtils.js.map +1 -1
- package/lib/typeorm/util/RandomGenerator.js +22 -25
- package/lib/typeorm/util/RandomGenerator.js.map +1 -1
- package/lib/typeorm/util/StringUtils.js +17 -21
- package/lib/typeorm/util/StringUtils.js.map +1 -1
- package/lib/typeorm/util/TreeRepositoryUtils.js +27 -30
- package/lib/typeorm/util/TreeRepositoryUtils.js.map +1 -1
- package/lib/typeorm/util/VersionUtils.js +9 -13
- package/lib/typeorm/util/VersionUtils.js.map +1 -1
- package/lib/typeorm/util/escapeRegExp.js +2 -2
- package/lib/typeorm/util/escapeRegExp.js.map +1 -1
- package/migrations/index.js +15 -2
- package/migrations/index.js.map +1 -1
- package/migrations/migrations_index._auto-generated_.d.ts +1 -0
- package/migrations/migrations_index._auto-generated_.js.map +1 -1
- package/package.json +8 -44
- package/src.d.ts +1 -1
- package/taon.jsonc +3 -30
- package/tmp-environment.json +8 -370
- package/websql/esm2022/lib/typeorm/driver/cordova/CordovaDriver.mjs +1 -1
- package/websql/esm2022/lib/typeorm/driver/cordova/CordovaQueryRunner.mjs +1 -1
- package/websql/esm2022/lib/typeorm/driver/nativescript/NativescriptDriver.mjs +1 -1
- package/websql/esm2022/lib/typeorm/driver/nativescript/NativescriptQueryRunner.mjs +1 -1
- package/websql/esm2022/lib/typeorm/driver/react-native/ReactNativeDriver.mjs +1 -1
- package/websql/esm2022/lib/typeorm/driver/react-native/ReactNativeQueryRunner.mjs +1 -1
- package/websql/esm2022/lib/typeorm/driver/sqljs/SqljsDriver.mjs +1 -1
- package/websql/esm2022/lib/typeorm/driver/sqljs/SqljsQueryRunner.mjs +1 -1
- package/websql/esm2022/lib/typeorm/index.mjs +1 -3
- package/websql/fesm2022/taon-typeorm.mjs.map +1 -1
- package/browser/package.json +0 -25
- package/websql/package.json +0 -25
|
@@ -1,59 +1,59 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var SelectQueryBuilder_1;
|
|
2
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
10
|
exports.SelectQueryBuilder = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var QueryBuilder_1 = require("./QueryBuilder");
|
|
11
|
+
const RawSqlResultsToEntityTransformer_1 = require("./transformer/RawSqlResultsToEntityTransformer");
|
|
12
|
+
const PessimisticLockTransactionRequiredError_1 = require("../error/PessimisticLockTransactionRequiredError");
|
|
13
|
+
const NoVersionOrUpdateDateColumnError_1 = require("../error/NoVersionOrUpdateDateColumnError");
|
|
14
|
+
const OptimisticLockVersionMismatchError_1 = require("../error/OptimisticLockVersionMismatchError");
|
|
15
|
+
const OptimisticLockCanNotBeUsedError_1 = require("../error/OptimisticLockCanNotBeUsedError");
|
|
16
|
+
const JoinAttribute_1 = require("./JoinAttribute");
|
|
17
|
+
const RelationIdAttribute_1 = require("./relation-id/RelationIdAttribute");
|
|
18
|
+
const RelationCountAttribute_1 = require("./relation-count/RelationCountAttribute");
|
|
19
|
+
const RelationIdLoader_1 = require("./relation-id/RelationIdLoader");
|
|
20
|
+
const RelationIdMetadataToAttributeTransformer_1 = require("./relation-id/RelationIdMetadataToAttributeTransformer");
|
|
21
|
+
const RelationCountLoader_1 = require("./relation-count/RelationCountLoader");
|
|
22
|
+
const RelationCountMetadataToAttributeTransformer_1 = require("./relation-count/RelationCountMetadataToAttributeTransformer");
|
|
23
|
+
const QueryBuilder_1 = require("./QueryBuilder");
|
|
18
24
|
//#endregion
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
const LockNotSupportedOnGivenDriverError_1 = require("../error/LockNotSupportedOnGivenDriverError");
|
|
26
|
+
const OffsetWithoutLimitNotSupportedError_1 = require("../error/OffsetWithoutLimitNotSupportedError");
|
|
27
|
+
const ObjectUtils_1 = require("../util/ObjectUtils");
|
|
28
|
+
const DriverUtils_1 = require("../driver/DriverUtils");
|
|
29
|
+
const EntityNotFoundError_1 = require("../error/EntityNotFoundError");
|
|
30
|
+
const error_1 = require("../error");
|
|
31
|
+
const FindOptionsUtils_1 = require("../find-options/FindOptionsUtils");
|
|
32
|
+
const ApplyValueTransformers_1 = require("../util/ApplyValueTransformers");
|
|
33
|
+
const OrmUtils_1 = require("../util/OrmUtils");
|
|
34
|
+
const EntityPropertyNotFoundError_1 = require("../error/EntityPropertyNotFoundError");
|
|
29
35
|
//#endregion
|
|
30
|
-
|
|
31
|
-
|
|
36
|
+
const InstanceChecker_1 = require("../util/InstanceChecker");
|
|
37
|
+
const typescript_class_helpers_1 = require("typescript-class-helpers");
|
|
32
38
|
/**
|
|
33
39
|
* Allows to build complex sql queries in a fashion way and execute those queries.
|
|
34
40
|
*/
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
_this.conditions = "";
|
|
44
|
-
_this.orderBys = [];
|
|
45
|
-
_this.relationMetadatas = [];
|
|
46
|
-
return _this;
|
|
47
|
-
}
|
|
48
|
-
SelectQueryBuilder_1 = SelectQueryBuilder;
|
|
41
|
+
let SelectQueryBuilder = SelectQueryBuilder_1 = class SelectQueryBuilder extends QueryBuilder_1.QueryBuilder {
|
|
42
|
+
"@instanceof" = Symbol.for("SelectQueryBuilder");
|
|
43
|
+
findOptions = {};
|
|
44
|
+
selects = [];
|
|
45
|
+
joins = [];
|
|
46
|
+
conditions = "";
|
|
47
|
+
orderBys = [];
|
|
48
|
+
relationMetadatas = [];
|
|
49
49
|
// -------------------------------------------------------------------------
|
|
50
50
|
// Public Implemented Methods
|
|
51
51
|
// -------------------------------------------------------------------------
|
|
52
52
|
/**
|
|
53
53
|
* Gets generated SQL query without parameters being replaced.
|
|
54
54
|
*/
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
getQuery() {
|
|
56
|
+
let sql = this.createComment();
|
|
57
57
|
sql += this.createCteExpression();
|
|
58
58
|
sql += this.createSelectExpression();
|
|
59
59
|
sql += this.createJoinExpression();
|
|
@@ -67,37 +67,37 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
67
67
|
if (this.expressionMap.subQuery)
|
|
68
68
|
sql = "(" + sql + ")";
|
|
69
69
|
return sql;
|
|
70
|
-
}
|
|
70
|
+
}
|
|
71
71
|
// -------------------------------------------------------------------------
|
|
72
72
|
// Public Methods
|
|
73
73
|
// -------------------------------------------------------------------------
|
|
74
|
-
|
|
74
|
+
setFindOptions(findOptions) {
|
|
75
75
|
this.findOptions = findOptions;
|
|
76
76
|
this.applyFindOptions();
|
|
77
77
|
return this;
|
|
78
|
-
}
|
|
78
|
+
}
|
|
79
79
|
/**
|
|
80
80
|
* Creates a subquery - query that can be used inside other queries.
|
|
81
81
|
*/
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
subQuery() {
|
|
83
|
+
const qb = this.createQueryBuilder();
|
|
84
84
|
qb.expressionMap.subQuery = true;
|
|
85
85
|
qb.parentQueryBuilder = this;
|
|
86
86
|
return qb;
|
|
87
|
-
}
|
|
87
|
+
}
|
|
88
88
|
/**
|
|
89
89
|
* Creates SELECT query and selects given data.
|
|
90
90
|
* Replaces all previous selections if they exist.
|
|
91
91
|
*/
|
|
92
|
-
|
|
92
|
+
select(selection, selectionAliasName) {
|
|
93
93
|
this.expressionMap.queryType = "select";
|
|
94
94
|
if (Array.isArray(selection)) {
|
|
95
|
-
this.expressionMap.selects = selection.map(
|
|
95
|
+
this.expressionMap.selects = selection.map((selection) => ({
|
|
96
96
|
selection: selection,
|
|
97
|
-
})
|
|
97
|
+
}));
|
|
98
98
|
}
|
|
99
99
|
else if (typeof selection === "function") {
|
|
100
|
-
|
|
100
|
+
const subQueryBuilder = selection(this.subQuery());
|
|
101
101
|
this.setParameters(subQueryBuilder.getParameters());
|
|
102
102
|
this.expressionMap.selects.push({
|
|
103
103
|
selection: subQueryBuilder.getQuery(),
|
|
@@ -110,18 +110,18 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
110
110
|
];
|
|
111
111
|
}
|
|
112
112
|
return this;
|
|
113
|
-
}
|
|
113
|
+
}
|
|
114
114
|
/**
|
|
115
115
|
* Adds new selection to the SELECT query.
|
|
116
116
|
*/
|
|
117
|
-
|
|
117
|
+
addSelect(selection, selectionAliasName) {
|
|
118
118
|
if (!selection)
|
|
119
119
|
return this;
|
|
120
120
|
if (Array.isArray(selection)) {
|
|
121
|
-
this.expressionMap.selects = this.expressionMap.selects.concat(selection.map(
|
|
121
|
+
this.expressionMap.selects = this.expressionMap.selects.concat(selection.map((selection) => ({ selection: selection })));
|
|
122
122
|
}
|
|
123
123
|
else if (typeof selection === "function") {
|
|
124
|
-
|
|
124
|
+
const subQueryBuilder = selection(this.subQuery());
|
|
125
125
|
this.setParameters(subQueryBuilder.getParameters());
|
|
126
126
|
this.expressionMap.selects.push({
|
|
127
127
|
selection: subQueryBuilder.getQuery(),
|
|
@@ -135,88 +135,87 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
135
135
|
});
|
|
136
136
|
}
|
|
137
137
|
return this;
|
|
138
|
-
}
|
|
138
|
+
}
|
|
139
139
|
/**
|
|
140
140
|
* Set max execution time.
|
|
141
141
|
* @param milliseconds
|
|
142
142
|
*/
|
|
143
|
-
|
|
143
|
+
maxExecutionTime(milliseconds) {
|
|
144
144
|
this.expressionMap.maxExecutionTime = milliseconds;
|
|
145
145
|
return this;
|
|
146
|
-
}
|
|
146
|
+
}
|
|
147
147
|
/**
|
|
148
148
|
* Sets whether the selection is DISTINCT.
|
|
149
149
|
*/
|
|
150
|
-
|
|
151
|
-
if (distinct === void 0) { distinct = true; }
|
|
150
|
+
distinct(distinct = true) {
|
|
152
151
|
this.expressionMap.selectDistinct = distinct;
|
|
153
152
|
return this;
|
|
154
|
-
}
|
|
153
|
+
}
|
|
155
154
|
/**
|
|
156
155
|
* Sets the distinct on clause for Postgres.
|
|
157
156
|
*/
|
|
158
|
-
|
|
157
|
+
distinctOn(distinctOn) {
|
|
159
158
|
this.expressionMap.selectDistinctOn = distinctOn;
|
|
160
159
|
return this;
|
|
161
|
-
}
|
|
160
|
+
}
|
|
162
161
|
/**
|
|
163
162
|
* Specifies FROM which entity's table select/update/delete will be executed.
|
|
164
163
|
* Also sets a main string alias of the selection data.
|
|
165
164
|
* Removes all previously set from-s.
|
|
166
165
|
*/
|
|
167
|
-
|
|
168
|
-
|
|
166
|
+
from(entityTarget, aliasName) {
|
|
167
|
+
const mainAlias = this.createFromAlias(entityTarget, aliasName);
|
|
169
168
|
this.expressionMap.setMainAlias(mainAlias);
|
|
170
169
|
return this;
|
|
171
|
-
}
|
|
170
|
+
}
|
|
172
171
|
/**
|
|
173
172
|
* Specifies FROM which entity's table select/update/delete will be executed.
|
|
174
173
|
* Also sets a main string alias of the selection data.
|
|
175
174
|
*/
|
|
176
|
-
|
|
177
|
-
|
|
175
|
+
addFrom(entityTarget, aliasName) {
|
|
176
|
+
const alias = this.createFromAlias(entityTarget, aliasName);
|
|
178
177
|
if (!this.expressionMap.mainAlias)
|
|
179
178
|
this.expressionMap.setMainAlias(alias);
|
|
180
179
|
return this;
|
|
181
|
-
}
|
|
180
|
+
}
|
|
182
181
|
/**
|
|
183
182
|
* INNER JOINs (without selection).
|
|
184
183
|
* You also need to specify an alias of the joined data.
|
|
185
184
|
* Optionally, you can add condition and parameters used in condition.
|
|
186
185
|
*/
|
|
187
|
-
|
|
186
|
+
innerJoin(entityOrProperty, alias, condition, parameters) {
|
|
188
187
|
this.join("INNER", entityOrProperty, alias, condition, parameters);
|
|
189
188
|
return this;
|
|
190
|
-
}
|
|
189
|
+
}
|
|
191
190
|
/**
|
|
192
191
|
* LEFT JOINs (without selection).
|
|
193
192
|
* You also need to specify an alias of the joined data.
|
|
194
193
|
* Optionally, you can add condition and parameters used in condition.
|
|
195
194
|
*/
|
|
196
|
-
|
|
195
|
+
leftJoin(entityOrProperty, alias, condition, parameters) {
|
|
197
196
|
this.join("LEFT", entityOrProperty, alias, condition, parameters);
|
|
198
197
|
return this;
|
|
199
|
-
}
|
|
198
|
+
}
|
|
200
199
|
/**
|
|
201
200
|
* INNER JOINs and adds all selection properties to SELECT.
|
|
202
201
|
* You also need to specify an alias of the joined data.
|
|
203
202
|
* Optionally, you can add condition and parameters used in condition.
|
|
204
203
|
*/
|
|
205
|
-
|
|
204
|
+
innerJoinAndSelect(entityOrProperty, alias, condition, parameters) {
|
|
206
205
|
this.addSelect(alias);
|
|
207
206
|
this.innerJoin(entityOrProperty, alias, condition, parameters);
|
|
208
207
|
return this;
|
|
209
|
-
}
|
|
208
|
+
}
|
|
210
209
|
/**
|
|
211
210
|
* LEFT JOINs and adds all selection properties to SELECT.
|
|
212
211
|
* You also need to specify an alias of the joined data.
|
|
213
212
|
* Optionally, you can add condition and parameters used in condition.
|
|
214
213
|
*/
|
|
215
|
-
|
|
214
|
+
leftJoinAndSelect(entityOrProperty, alias, condition, parameters) {
|
|
216
215
|
this.addSelect(alias);
|
|
217
216
|
this.leftJoin(entityOrProperty, alias, condition, parameters);
|
|
218
217
|
return this;
|
|
219
|
-
}
|
|
218
|
+
}
|
|
220
219
|
/**
|
|
221
220
|
* INNER JOINs, SELECTs the data returned by a join and MAPs all that data to some entity's property.
|
|
222
221
|
* This is extremely useful when you want to select some data and map it to some virtual property.
|
|
@@ -224,11 +223,11 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
224
223
|
* You also need to specify an alias of the joined data.
|
|
225
224
|
* Optionally, you can add condition and parameters used in condition.
|
|
226
225
|
*/
|
|
227
|
-
|
|
226
|
+
innerJoinAndMapMany(mapToProperty, entityOrProperty, alias, condition, parameters) {
|
|
228
227
|
this.addSelect(alias);
|
|
229
228
|
this.join("INNER", entityOrProperty, alias, condition, parameters, mapToProperty, true);
|
|
230
229
|
return this;
|
|
231
|
-
}
|
|
230
|
+
}
|
|
232
231
|
/**
|
|
233
232
|
* INNER JOINs, SELECTs the data returned by a join and MAPs all that data to some entity's property.
|
|
234
233
|
* This is extremely useful when you want to select some data and map it to some virtual property.
|
|
@@ -236,11 +235,11 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
236
235
|
* You also need to specify an alias of the joined data.
|
|
237
236
|
* Optionally, you can add condition and parameters used in condition.
|
|
238
237
|
*/
|
|
239
|
-
|
|
238
|
+
innerJoinAndMapOne(mapToProperty, entityOrProperty, alias, condition, parameters) {
|
|
240
239
|
this.addSelect(alias);
|
|
241
240
|
this.join("INNER", entityOrProperty, alias, condition, parameters, mapToProperty, false);
|
|
242
241
|
return this;
|
|
243
|
-
}
|
|
242
|
+
}
|
|
244
243
|
/**
|
|
245
244
|
* LEFT JOINs, SELECTs the data returned by a join and MAPs all that data to some entity's property.
|
|
246
245
|
* This is extremely useful when you want to select some data and map it to some virtual property.
|
|
@@ -248,11 +247,11 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
248
247
|
* You also need to specify an alias of the joined data.
|
|
249
248
|
* Optionally, you can add condition and parameters used in condition.
|
|
250
249
|
*/
|
|
251
|
-
|
|
250
|
+
leftJoinAndMapMany(mapToProperty, entityOrProperty, alias, condition, parameters) {
|
|
252
251
|
this.addSelect(alias);
|
|
253
252
|
this.join("LEFT", entityOrProperty, alias, condition, parameters, mapToProperty, true);
|
|
254
253
|
return this;
|
|
255
|
-
}
|
|
254
|
+
}
|
|
256
255
|
/**
|
|
257
256
|
* LEFT JOINs, SELECTs the data returned by a join and MAPs all that data to some entity's property.
|
|
258
257
|
* This is extremely useful when you want to select some data and map it to some virtual property.
|
|
@@ -260,17 +259,17 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
260
259
|
* You also need to specify an alias of the joined data.
|
|
261
260
|
* Optionally, you can add condition and parameters used in condition.
|
|
262
261
|
*/
|
|
263
|
-
|
|
262
|
+
leftJoinAndMapOne(mapToProperty, entityOrProperty, alias, condition, parameters) {
|
|
264
263
|
this.addSelect(alias);
|
|
265
264
|
this.join("LEFT", entityOrProperty, alias, condition, parameters, mapToProperty, false);
|
|
266
265
|
return this;
|
|
267
|
-
}
|
|
266
|
+
}
|
|
268
267
|
/**
|
|
269
268
|
* LEFT JOINs relation id and maps it into some entity's property.
|
|
270
269
|
* Optionally, you can add condition and parameters used in condition.
|
|
271
270
|
*/
|
|
272
|
-
|
|
273
|
-
|
|
271
|
+
loadRelationIdAndMap(mapToProperty, relationName, aliasNameOrOptions, queryBuilderFactory) {
|
|
272
|
+
const relationIdAttribute = new RelationIdAttribute_1.RelationIdAttribute(this.expressionMap);
|
|
274
273
|
relationIdAttribute.mapToProperty = mapToProperty;
|
|
275
274
|
relationIdAttribute.relationName = relationName;
|
|
276
275
|
if (typeof aliasNameOrOptions === "string")
|
|
@@ -288,13 +287,13 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
288
287
|
});
|
|
289
288
|
}
|
|
290
289
|
return this;
|
|
291
|
-
}
|
|
290
|
+
}
|
|
292
291
|
/**
|
|
293
292
|
* Counts number of entities of entity's relation and maps the value into some entity's property.
|
|
294
293
|
* Optionally, you can add condition and parameters used in condition.
|
|
295
294
|
*/
|
|
296
|
-
|
|
297
|
-
|
|
295
|
+
loadRelationCountAndMap(mapToProperty, relationName, aliasName, queryBuilderFactory) {
|
|
296
|
+
const relationCountAttribute = new RelationCountAttribute_1.RelationCountAttribute(this.expressionMap);
|
|
298
297
|
relationCountAttribute.mapToProperty = mapToProperty;
|
|
299
298
|
relationCountAttribute.relationName = relationName;
|
|
300
299
|
relationCountAttribute.alias = aliasName;
|
|
@@ -312,37 +311,36 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
312
311
|
});
|
|
313
312
|
}
|
|
314
313
|
return this;
|
|
315
|
-
}
|
|
314
|
+
}
|
|
316
315
|
/**
|
|
317
316
|
* Loads all relation ids for all relations of the selected entity.
|
|
318
317
|
* All relation ids will be mapped to relation property themself.
|
|
319
318
|
* If array of strings is given then loads only relation ids of the given properties.
|
|
320
319
|
*/
|
|
321
|
-
|
|
322
|
-
var _this = this;
|
|
320
|
+
loadAllRelationIds(options) {
|
|
323
321
|
// todo: add skip relations
|
|
324
|
-
this.expressionMap.mainAlias.metadata.relations.forEach(
|
|
322
|
+
this.expressionMap.mainAlias.metadata.relations.forEach((relation) => {
|
|
325
323
|
if (options !== undefined &&
|
|
326
324
|
options.relations !== undefined &&
|
|
327
325
|
options.relations.indexOf(relation.propertyPath) === -1)
|
|
328
326
|
return;
|
|
329
|
-
|
|
327
|
+
this.loadRelationIdAndMap(this.expressionMap.mainAlias.name +
|
|
330
328
|
"." +
|
|
331
|
-
relation.propertyPath,
|
|
329
|
+
relation.propertyPath, this.expressionMap.mainAlias.name +
|
|
332
330
|
"." +
|
|
333
331
|
relation.propertyPath, options);
|
|
334
332
|
});
|
|
335
333
|
return this;
|
|
336
|
-
}
|
|
334
|
+
}
|
|
337
335
|
/**
|
|
338
336
|
* Sets WHERE condition in the query builder.
|
|
339
337
|
* If you had previously WHERE expression defined,
|
|
340
338
|
* calling this function will override previously set WHERE conditions.
|
|
341
339
|
* Additionally you can add parameters used in where expression.
|
|
342
340
|
*/
|
|
343
|
-
|
|
341
|
+
where(where, parameters) {
|
|
344
342
|
this.expressionMap.wheres = []; // don't move this block below since computeWhereParameter can add where expressions
|
|
345
|
-
|
|
343
|
+
const condition = this.getWhereCondition(where);
|
|
346
344
|
if (condition)
|
|
347
345
|
this.expressionMap.wheres = [
|
|
348
346
|
{ type: "simple", condition: condition },
|
|
@@ -350,12 +348,12 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
350
348
|
if (parameters)
|
|
351
349
|
this.setParameters(parameters);
|
|
352
350
|
return this;
|
|
353
|
-
}
|
|
351
|
+
}
|
|
354
352
|
/**
|
|
355
353
|
* Adds new AND WHERE condition in the query builder.
|
|
356
354
|
* Additionally you can add parameters used in where expression.
|
|
357
355
|
*/
|
|
358
|
-
|
|
356
|
+
andWhere(where, parameters) {
|
|
359
357
|
this.expressionMap.wheres.push({
|
|
360
358
|
type: "and",
|
|
361
359
|
condition: this.getWhereCondition(where),
|
|
@@ -363,12 +361,12 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
363
361
|
if (parameters)
|
|
364
362
|
this.setParameters(parameters);
|
|
365
363
|
return this;
|
|
366
|
-
}
|
|
364
|
+
}
|
|
367
365
|
/**
|
|
368
366
|
* Adds new OR WHERE condition in the query builder.
|
|
369
367
|
* Additionally you can add parameters used in where expression.
|
|
370
368
|
*/
|
|
371
|
-
|
|
369
|
+
orWhere(where, parameters) {
|
|
372
370
|
this.expressionMap.wheres.push({
|
|
373
371
|
type: "or",
|
|
374
372
|
condition: this.getWhereCondition(where),
|
|
@@ -376,7 +374,7 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
376
374
|
if (parameters)
|
|
377
375
|
this.setParameters(parameters);
|
|
378
376
|
return this;
|
|
379
|
-
}
|
|
377
|
+
}
|
|
380
378
|
/**
|
|
381
379
|
* Adds new AND WHERE with conditions for the given ids.
|
|
382
380
|
*
|
|
@@ -385,9 +383,9 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
385
383
|
* If you have multiple primary keys you need to pass object with property names and values specified,
|
|
386
384
|
* for example [{ firstId: 1, secondId: 2 }, { firstId: 2, secondId: 3 }, ...]
|
|
387
385
|
*/
|
|
388
|
-
|
|
386
|
+
whereInIds(ids) {
|
|
389
387
|
return this.where(this.getWhereInIdsCondition(ids));
|
|
390
|
-
}
|
|
388
|
+
}
|
|
391
389
|
/**
|
|
392
390
|
* Adds new AND WHERE with conditions for the given ids.
|
|
393
391
|
*
|
|
@@ -396,9 +394,9 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
396
394
|
* If you have multiple primary keys you need to pass object with property names and values specified,
|
|
397
395
|
* for example [{ firstId: 1, secondId: 2 }, { firstId: 2, secondId: 3 }, ...]
|
|
398
396
|
*/
|
|
399
|
-
|
|
397
|
+
andWhereInIds(ids) {
|
|
400
398
|
return this.andWhere(this.getWhereInIdsCondition(ids));
|
|
401
|
-
}
|
|
399
|
+
}
|
|
402
400
|
/**
|
|
403
401
|
* Adds new OR WHERE with conditions for the given ids.
|
|
404
402
|
*
|
|
@@ -407,47 +405,47 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
407
405
|
* If you have multiple primary keys you need to pass object with property names and values specified,
|
|
408
406
|
* for example [{ firstId: 1, secondId: 2 }, { firstId: 2, secondId: 3 }, ...]
|
|
409
407
|
*/
|
|
410
|
-
|
|
408
|
+
orWhereInIds(ids) {
|
|
411
409
|
return this.orWhere(this.getWhereInIdsCondition(ids));
|
|
412
|
-
}
|
|
410
|
+
}
|
|
413
411
|
/**
|
|
414
412
|
* Sets HAVING condition in the query builder.
|
|
415
413
|
* If you had previously HAVING expression defined,
|
|
416
414
|
* calling this function will override previously set HAVING conditions.
|
|
417
415
|
* Additionally you can add parameters used in where expression.
|
|
418
416
|
*/
|
|
419
|
-
|
|
417
|
+
having(having, parameters) {
|
|
420
418
|
this.expressionMap.havings.push({ type: "simple", condition: having });
|
|
421
419
|
if (parameters)
|
|
422
420
|
this.setParameters(parameters);
|
|
423
421
|
return this;
|
|
424
|
-
}
|
|
422
|
+
}
|
|
425
423
|
/**
|
|
426
424
|
* Adds new AND HAVING condition in the query builder.
|
|
427
425
|
* Additionally you can add parameters used in where expression.
|
|
428
426
|
*/
|
|
429
|
-
|
|
427
|
+
andHaving(having, parameters) {
|
|
430
428
|
this.expressionMap.havings.push({ type: "and", condition: having });
|
|
431
429
|
if (parameters)
|
|
432
430
|
this.setParameters(parameters);
|
|
433
431
|
return this;
|
|
434
|
-
}
|
|
432
|
+
}
|
|
435
433
|
/**
|
|
436
434
|
* Adds new OR HAVING condition in the query builder.
|
|
437
435
|
* Additionally you can add parameters used in where expression.
|
|
438
436
|
*/
|
|
439
|
-
|
|
437
|
+
orHaving(having, parameters) {
|
|
440
438
|
this.expressionMap.havings.push({ type: "or", condition: having });
|
|
441
439
|
if (parameters)
|
|
442
440
|
this.setParameters(parameters);
|
|
443
441
|
return this;
|
|
444
|
-
}
|
|
442
|
+
}
|
|
445
443
|
/**
|
|
446
444
|
* Sets GROUP BY condition in the query builder.
|
|
447
445
|
* If you had previously GROUP BY expression defined,
|
|
448
446
|
* calling this function will override previously set GROUP BY conditions.
|
|
449
447
|
*/
|
|
450
|
-
|
|
448
|
+
groupBy(groupBy) {
|
|
451
449
|
if (groupBy) {
|
|
452
450
|
this.expressionMap.groupBys = [groupBy];
|
|
453
451
|
}
|
|
@@ -455,40 +453,38 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
455
453
|
this.expressionMap.groupBys = [];
|
|
456
454
|
}
|
|
457
455
|
return this;
|
|
458
|
-
}
|
|
456
|
+
}
|
|
459
457
|
/**
|
|
460
458
|
* Adds GROUP BY condition in the query builder.
|
|
461
459
|
*/
|
|
462
|
-
|
|
460
|
+
addGroupBy(groupBy) {
|
|
463
461
|
this.expressionMap.groupBys.push(groupBy);
|
|
464
462
|
return this;
|
|
465
|
-
}
|
|
463
|
+
}
|
|
466
464
|
/**
|
|
467
465
|
* Sets ORDER BY condition in the query builder.
|
|
468
466
|
* If you had previously ORDER BY expression defined,
|
|
469
467
|
* calling this function will override previously set ORDER BY conditions.
|
|
470
468
|
*/
|
|
471
|
-
|
|
472
|
-
var _a, _b;
|
|
473
|
-
if (order === void 0) { order = "ASC"; }
|
|
469
|
+
orderBy(sort, order = "ASC", nulls) {
|
|
474
470
|
if (order !== undefined && order !== "ASC" && order !== "DESC")
|
|
475
|
-
throw new error_1.TypeORMError(
|
|
471
|
+
throw new error_1.TypeORMError(`SelectQueryBuilder.addOrderBy "order" can accept only "ASC" and "DESC" values.`);
|
|
476
472
|
if (nulls !== undefined &&
|
|
477
473
|
nulls !== "NULLS FIRST" &&
|
|
478
474
|
nulls !== "NULLS LAST")
|
|
479
|
-
throw new error_1.TypeORMError(
|
|
475
|
+
throw new error_1.TypeORMError(`SelectQueryBuilder.addOrderBy "nulls" can accept only "NULLS FIRST" and "NULLS LAST" values.`);
|
|
480
476
|
if (sort) {
|
|
481
477
|
if (typeof sort === "object") {
|
|
482
478
|
this.expressionMap.orderBys = sort;
|
|
483
479
|
}
|
|
484
480
|
else {
|
|
485
481
|
if (nulls) {
|
|
486
|
-
this.expressionMap.orderBys =
|
|
487
|
-
|
|
488
|
-
|
|
482
|
+
this.expressionMap.orderBys = {
|
|
483
|
+
[sort]: { order, nulls },
|
|
484
|
+
};
|
|
489
485
|
}
|
|
490
486
|
else {
|
|
491
|
-
this.expressionMap.orderBys =
|
|
487
|
+
this.expressionMap.orderBys = { [sort]: order };
|
|
492
488
|
}
|
|
493
489
|
}
|
|
494
490
|
}
|
|
@@ -496,517 +492,363 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
496
492
|
this.expressionMap.orderBys = {};
|
|
497
493
|
}
|
|
498
494
|
return this;
|
|
499
|
-
}
|
|
495
|
+
}
|
|
500
496
|
/**
|
|
501
497
|
* Adds ORDER BY condition in the query builder.
|
|
502
498
|
*/
|
|
503
|
-
|
|
504
|
-
if (order === void 0) { order = "ASC"; }
|
|
499
|
+
addOrderBy(sort, order = "ASC", nulls) {
|
|
505
500
|
if (order !== undefined && order !== "ASC" && order !== "DESC")
|
|
506
|
-
throw new error_1.TypeORMError(
|
|
501
|
+
throw new error_1.TypeORMError(`SelectQueryBuilder.addOrderBy "order" can accept only "ASC" and "DESC" values.`);
|
|
507
502
|
if (nulls !== undefined &&
|
|
508
503
|
nulls !== "NULLS FIRST" &&
|
|
509
504
|
nulls !== "NULLS LAST")
|
|
510
|
-
throw new error_1.TypeORMError(
|
|
505
|
+
throw new error_1.TypeORMError(`SelectQueryBuilder.addOrderBy "nulls" can accept only "NULLS FIRST" and "NULLS LAST" values.`);
|
|
511
506
|
if (nulls) {
|
|
512
|
-
this.expressionMap.orderBys[sort] = { order
|
|
507
|
+
this.expressionMap.orderBys[sort] = { order, nulls };
|
|
513
508
|
}
|
|
514
509
|
else {
|
|
515
510
|
this.expressionMap.orderBys[sort] = order;
|
|
516
511
|
}
|
|
517
512
|
return this;
|
|
518
|
-
}
|
|
513
|
+
}
|
|
519
514
|
/**
|
|
520
515
|
* Set's LIMIT - maximum number of rows to be selected.
|
|
521
516
|
* NOTE that it may not work as you expect if you are using joins.
|
|
522
517
|
* If you want to implement pagination, and you are having join in your query,
|
|
523
518
|
* then use instead take method instead.
|
|
524
519
|
*/
|
|
525
|
-
|
|
520
|
+
limit(limit) {
|
|
526
521
|
this.expressionMap.limit = this.normalizeNumber(limit);
|
|
527
522
|
if (this.expressionMap.limit !== undefined &&
|
|
528
523
|
isNaN(this.expressionMap.limit))
|
|
529
|
-
throw new error_1.TypeORMError(
|
|
524
|
+
throw new error_1.TypeORMError(`Provided "limit" value is not a number. Please provide a numeric value.`);
|
|
530
525
|
return this;
|
|
531
|
-
}
|
|
526
|
+
}
|
|
532
527
|
/**
|
|
533
528
|
* Set's OFFSET - selection offset.
|
|
534
529
|
* NOTE that it may not work as you expect if you are using joins.
|
|
535
530
|
* If you want to implement pagination, and you are having join in your query,
|
|
536
531
|
* then use instead skip method instead.
|
|
537
532
|
*/
|
|
538
|
-
|
|
533
|
+
offset(offset) {
|
|
539
534
|
this.expressionMap.offset = this.normalizeNumber(offset);
|
|
540
535
|
if (this.expressionMap.offset !== undefined &&
|
|
541
536
|
isNaN(this.expressionMap.offset))
|
|
542
|
-
throw new error_1.TypeORMError(
|
|
537
|
+
throw new error_1.TypeORMError(`Provided "offset" value is not a number. Please provide a numeric value.`);
|
|
543
538
|
return this;
|
|
544
|
-
}
|
|
539
|
+
}
|
|
545
540
|
/**
|
|
546
541
|
* Sets maximal number of entities to take.
|
|
547
542
|
*/
|
|
548
|
-
|
|
543
|
+
take(take) {
|
|
549
544
|
this.expressionMap.take = this.normalizeNumber(take);
|
|
550
545
|
if (this.expressionMap.take !== undefined &&
|
|
551
546
|
isNaN(this.expressionMap.take))
|
|
552
|
-
throw new error_1.TypeORMError(
|
|
547
|
+
throw new error_1.TypeORMError(`Provided "take" value is not a number. Please provide a numeric value.`);
|
|
553
548
|
return this;
|
|
554
|
-
}
|
|
549
|
+
}
|
|
555
550
|
/**
|
|
556
551
|
* Sets number of entities to skip.
|
|
557
552
|
*/
|
|
558
|
-
|
|
553
|
+
skip(skip) {
|
|
559
554
|
this.expressionMap.skip = this.normalizeNumber(skip);
|
|
560
555
|
if (this.expressionMap.skip !== undefined &&
|
|
561
556
|
isNaN(this.expressionMap.skip))
|
|
562
|
-
throw new error_1.TypeORMError(
|
|
557
|
+
throw new error_1.TypeORMError(`Provided "skip" value is not a number. Please provide a numeric value.`);
|
|
563
558
|
return this;
|
|
564
|
-
}
|
|
559
|
+
}
|
|
565
560
|
/**
|
|
566
561
|
* Set certain index to be used by the query.
|
|
567
562
|
*
|
|
568
563
|
* @param index Name of index to be used.
|
|
569
564
|
*/
|
|
570
|
-
|
|
565
|
+
useIndex(index) {
|
|
571
566
|
this.expressionMap.useIndex = index;
|
|
572
567
|
return this;
|
|
573
|
-
}
|
|
568
|
+
}
|
|
574
569
|
/**
|
|
575
570
|
* Sets locking mode.
|
|
576
571
|
*/
|
|
577
|
-
|
|
572
|
+
setLock(lockMode, lockVersion, lockTables) {
|
|
578
573
|
this.expressionMap.lockMode = lockMode;
|
|
579
574
|
this.expressionMap.lockVersion = lockVersion;
|
|
580
575
|
this.expressionMap.lockTables = lockTables;
|
|
581
576
|
return this;
|
|
582
|
-
}
|
|
577
|
+
}
|
|
583
578
|
/**
|
|
584
579
|
* Sets lock handling by adding NO WAIT or SKIP LOCKED.
|
|
585
580
|
*/
|
|
586
|
-
|
|
581
|
+
setOnLocked(onLocked) {
|
|
587
582
|
this.expressionMap.onLocked = onLocked;
|
|
588
583
|
return this;
|
|
589
|
-
}
|
|
584
|
+
}
|
|
590
585
|
/**
|
|
591
586
|
* Disables the global condition of "non-deleted" for the entity with delete date columns.
|
|
592
587
|
*/
|
|
593
|
-
|
|
588
|
+
withDeleted() {
|
|
594
589
|
this.expressionMap.withDeleted = true;
|
|
595
590
|
return this;
|
|
596
|
-
}
|
|
591
|
+
}
|
|
597
592
|
/**
|
|
598
593
|
* Gets first raw result returned by execution of generated query builder sql.
|
|
599
594
|
*/
|
|
600
|
-
|
|
601
|
-
return
|
|
602
|
-
|
|
603
|
-
switch (_a.label) {
|
|
604
|
-
case 0: return [4 /*yield*/, this.getRawMany()];
|
|
605
|
-
case 1: return [2 /*return*/, (_a.sent())[0]];
|
|
606
|
-
}
|
|
607
|
-
});
|
|
608
|
-
});
|
|
609
|
-
};
|
|
595
|
+
async getRawOne() {
|
|
596
|
+
return (await this.getRawMany())[0];
|
|
597
|
+
}
|
|
610
598
|
/**
|
|
611
599
|
* Gets all raw results returned by execution of generated query builder sql.
|
|
612
600
|
*/
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
results = _a.sent();
|
|
639
|
-
if (!transactionStartedByUs) return [3 /*break*/, 6];
|
|
640
|
-
return [4 /*yield*/, queryRunner.commitTransaction()];
|
|
641
|
-
case 5:
|
|
642
|
-
_a.sent();
|
|
643
|
-
_a.label = 6;
|
|
644
|
-
case 6: return [2 /*return*/, results];
|
|
645
|
-
case 7:
|
|
646
|
-
error_2 = _a.sent();
|
|
647
|
-
if (!transactionStartedByUs) return [3 /*break*/, 11];
|
|
648
|
-
_a.label = 8;
|
|
649
|
-
case 8:
|
|
650
|
-
_a.trys.push([8, 10, , 11]);
|
|
651
|
-
return [4 /*yield*/, queryRunner.rollbackTransaction()];
|
|
652
|
-
case 9:
|
|
653
|
-
_a.sent();
|
|
654
|
-
return [3 /*break*/, 11];
|
|
655
|
-
case 10:
|
|
656
|
-
rollbackError_1 = _a.sent();
|
|
657
|
-
return [3 /*break*/, 11];
|
|
658
|
-
case 11: throw error_2;
|
|
659
|
-
case 12:
|
|
660
|
-
if (!(queryRunner !== this.queryRunner)) return [3 /*break*/, 14];
|
|
661
|
-
// means we created our own query runner
|
|
662
|
-
return [4 /*yield*/, queryRunner.release()];
|
|
663
|
-
case 13:
|
|
664
|
-
// means we created our own query runner
|
|
665
|
-
_a.sent();
|
|
666
|
-
_a.label = 14;
|
|
667
|
-
case 14: return [7 /*endfinally*/];
|
|
668
|
-
case 15: return [2 /*return*/];
|
|
601
|
+
async getRawMany() {
|
|
602
|
+
if (this.expressionMap.lockMode === "optimistic")
|
|
603
|
+
throw new OptimisticLockCanNotBeUsedError_1.OptimisticLockCanNotBeUsedError();
|
|
604
|
+
this.expressionMap.queryEntity = false;
|
|
605
|
+
const queryRunner = this.obtainQueryRunner();
|
|
606
|
+
let transactionStartedByUs = false;
|
|
607
|
+
try {
|
|
608
|
+
// start transaction if it was enabled
|
|
609
|
+
if (this.expressionMap.useTransaction === true &&
|
|
610
|
+
queryRunner.isTransactionActive === false) {
|
|
611
|
+
await queryRunner.startTransaction();
|
|
612
|
+
transactionStartedByUs = true;
|
|
613
|
+
}
|
|
614
|
+
const results = await this.loadRawResults(queryRunner);
|
|
615
|
+
// close transaction if we started it
|
|
616
|
+
if (transactionStartedByUs) {
|
|
617
|
+
await queryRunner.commitTransaction();
|
|
618
|
+
}
|
|
619
|
+
return results;
|
|
620
|
+
}
|
|
621
|
+
catch (error) {
|
|
622
|
+
// rollback transaction if we started it
|
|
623
|
+
if (transactionStartedByUs) {
|
|
624
|
+
try {
|
|
625
|
+
await queryRunner.rollbackTransaction();
|
|
669
626
|
}
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
627
|
+
catch (rollbackError) { }
|
|
628
|
+
}
|
|
629
|
+
throw error;
|
|
630
|
+
}
|
|
631
|
+
finally {
|
|
632
|
+
if (queryRunner !== this.queryRunner) {
|
|
633
|
+
// means we created our own query runner
|
|
634
|
+
await queryRunner.release();
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
}
|
|
673
638
|
/**
|
|
674
639
|
* Executes sql generated by query builder and returns object with raw results and entities created from them.
|
|
675
640
|
*/
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
case 4:
|
|
700
|
-
results = _a.sent();
|
|
701
|
-
if (!transactionStartedByUs) return [3 /*break*/, 6];
|
|
702
|
-
return [4 /*yield*/, queryRunner.commitTransaction()];
|
|
703
|
-
case 5:
|
|
704
|
-
_a.sent();
|
|
705
|
-
_a.label = 6;
|
|
706
|
-
case 6: return [2 /*return*/, results];
|
|
707
|
-
case 7:
|
|
708
|
-
error_3 = _a.sent();
|
|
709
|
-
if (!transactionStartedByUs) return [3 /*break*/, 11];
|
|
710
|
-
_a.label = 8;
|
|
711
|
-
case 8:
|
|
712
|
-
_a.trys.push([8, 10, , 11]);
|
|
713
|
-
return [4 /*yield*/, queryRunner.rollbackTransaction()];
|
|
714
|
-
case 9:
|
|
715
|
-
_a.sent();
|
|
716
|
-
return [3 /*break*/, 11];
|
|
717
|
-
case 10:
|
|
718
|
-
rollbackError_2 = _a.sent();
|
|
719
|
-
return [3 /*break*/, 11];
|
|
720
|
-
case 11: throw error_3;
|
|
721
|
-
case 12:
|
|
722
|
-
if (!(queryRunner !== this.queryRunner)) return [3 /*break*/, 14];
|
|
723
|
-
// means we created our own query runner
|
|
724
|
-
return [4 /*yield*/, queryRunner.release()];
|
|
725
|
-
case 13:
|
|
726
|
-
// means we created our own query runner
|
|
727
|
-
_a.sent();
|
|
728
|
-
_a.label = 14;
|
|
729
|
-
case 14: return [7 /*endfinally*/];
|
|
730
|
-
case 15: return [2 /*return*/];
|
|
641
|
+
async getRawAndEntities() {
|
|
642
|
+
const queryRunner = this.obtainQueryRunner();
|
|
643
|
+
let transactionStartedByUs = false;
|
|
644
|
+
try {
|
|
645
|
+
// start transaction if it was enabled
|
|
646
|
+
if (this.expressionMap.useTransaction === true &&
|
|
647
|
+
queryRunner.isTransactionActive === false) {
|
|
648
|
+
await queryRunner.startTransaction();
|
|
649
|
+
transactionStartedByUs = true;
|
|
650
|
+
}
|
|
651
|
+
this.expressionMap.queryEntity = true;
|
|
652
|
+
const results = await this.executeEntitiesAndRawResults(queryRunner);
|
|
653
|
+
// close transaction if we started it
|
|
654
|
+
if (transactionStartedByUs) {
|
|
655
|
+
await queryRunner.commitTransaction();
|
|
656
|
+
}
|
|
657
|
+
return results;
|
|
658
|
+
}
|
|
659
|
+
catch (error) {
|
|
660
|
+
// rollback transaction if we started it
|
|
661
|
+
if (transactionStartedByUs) {
|
|
662
|
+
try {
|
|
663
|
+
await queryRunner.rollbackTransaction();
|
|
731
664
|
}
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
665
|
+
catch (rollbackError) { }
|
|
666
|
+
}
|
|
667
|
+
throw error;
|
|
668
|
+
}
|
|
669
|
+
finally {
|
|
670
|
+
if (queryRunner !== this.queryRunner)
|
|
671
|
+
// means we created our own query runner
|
|
672
|
+
await queryRunner.release();
|
|
673
|
+
}
|
|
674
|
+
}
|
|
735
675
|
/**
|
|
736
676
|
* Gets single entity returned by execution of generated query builder sql.
|
|
737
677
|
*/
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
throw new OptimisticLockVersionMismatchError_1.OptimisticLockVersionMismatchError(metadata.name, this.expressionMap.lockVersion, actualVersion);
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
if (result === undefined) {
|
|
766
|
-
return [2 /*return*/, null];
|
|
767
|
-
}
|
|
768
|
-
return [2 /*return*/, result];
|
|
769
|
-
}
|
|
770
|
-
});
|
|
771
|
-
});
|
|
772
|
-
};
|
|
678
|
+
async getOne() {
|
|
679
|
+
const results = await this.getRawAndEntities();
|
|
680
|
+
const result = results.entities[0];
|
|
681
|
+
if (result &&
|
|
682
|
+
this.expressionMap.lockMode === "optimistic" &&
|
|
683
|
+
this.expressionMap.lockVersion) {
|
|
684
|
+
const metadata = this.expressionMap.mainAlias.metadata;
|
|
685
|
+
if (this.expressionMap.lockVersion instanceof Date) {
|
|
686
|
+
const actualVersion = metadata.updateDateColumn.getEntityValue(result); // what if columns arent set?
|
|
687
|
+
if (actualVersion.getTime() !==
|
|
688
|
+
this.expressionMap.lockVersion.getTime())
|
|
689
|
+
throw new OptimisticLockVersionMismatchError_1.OptimisticLockVersionMismatchError(metadata.name, this.expressionMap.lockVersion, actualVersion);
|
|
690
|
+
}
|
|
691
|
+
else {
|
|
692
|
+
const actualVersion = metadata.versionColumn.getEntityValue(result); // what if columns arent set?
|
|
693
|
+
if (actualVersion !== this.expressionMap.lockVersion)
|
|
694
|
+
throw new OptimisticLockVersionMismatchError_1.OptimisticLockVersionMismatchError(metadata.name, this.expressionMap.lockVersion, actualVersion);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
if (result === undefined) {
|
|
698
|
+
return null;
|
|
699
|
+
}
|
|
700
|
+
return result;
|
|
701
|
+
}
|
|
773
702
|
/**
|
|
774
703
|
* Gets the first entity returned by execution of generated query builder sql or rejects the returned promise on error.
|
|
775
704
|
*/
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
entity = _a.sent();
|
|
784
|
-
if (!entity) {
|
|
785
|
-
throw new EntityNotFoundError_1.EntityNotFoundError(this.expressionMap.mainAlias.target, this);
|
|
786
|
-
}
|
|
787
|
-
return [2 /*return*/, entity];
|
|
788
|
-
}
|
|
789
|
-
});
|
|
790
|
-
});
|
|
791
|
-
};
|
|
705
|
+
async getOneOrFail() {
|
|
706
|
+
const entity = await this.getOne();
|
|
707
|
+
if (!entity) {
|
|
708
|
+
throw new EntityNotFoundError_1.EntityNotFoundError(this.expressionMap.mainAlias.target, this);
|
|
709
|
+
}
|
|
710
|
+
return entity;
|
|
711
|
+
}
|
|
792
712
|
/**
|
|
793
713
|
* Gets entities returned by execution of generated query builder sql.
|
|
794
714
|
*/
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
if (this.expressionMap.lockMode === "optimistic")
|
|
802
|
-
throw new OptimisticLockCanNotBeUsedError_1.OptimisticLockCanNotBeUsedError();
|
|
803
|
-
return [4 /*yield*/, this.getRawAndEntities()];
|
|
804
|
-
case 1:
|
|
805
|
-
results = _a.sent();
|
|
806
|
-
return [2 /*return*/, results.entities];
|
|
807
|
-
}
|
|
808
|
-
});
|
|
809
|
-
});
|
|
810
|
-
};
|
|
715
|
+
async getMany() {
|
|
716
|
+
if (this.expressionMap.lockMode === "optimistic")
|
|
717
|
+
throw new OptimisticLockCanNotBeUsedError_1.OptimisticLockCanNotBeUsedError();
|
|
718
|
+
const results = await this.getRawAndEntities();
|
|
719
|
+
return results.entities;
|
|
720
|
+
}
|
|
811
721
|
/**
|
|
812
722
|
* Gets count - number of entities selected by sql generated by this query builder.
|
|
813
723
|
* Count excludes all limitations set by setFirstResult and setMaxResults methods call.
|
|
814
724
|
*/
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
case 4:
|
|
841
|
-
results = _a.sent();
|
|
842
|
-
if (!transactionStartedByUs) return [3 /*break*/, 6];
|
|
843
|
-
return [4 /*yield*/, queryRunner.commitTransaction()];
|
|
844
|
-
case 5:
|
|
845
|
-
_a.sent();
|
|
846
|
-
_a.label = 6;
|
|
847
|
-
case 6: return [2 /*return*/, results];
|
|
848
|
-
case 7:
|
|
849
|
-
error_4 = _a.sent();
|
|
850
|
-
if (!transactionStartedByUs) return [3 /*break*/, 11];
|
|
851
|
-
_a.label = 8;
|
|
852
|
-
case 8:
|
|
853
|
-
_a.trys.push([8, 10, , 11]);
|
|
854
|
-
return [4 /*yield*/, queryRunner.rollbackTransaction()];
|
|
855
|
-
case 9:
|
|
856
|
-
_a.sent();
|
|
857
|
-
return [3 /*break*/, 11];
|
|
858
|
-
case 10:
|
|
859
|
-
rollbackError_3 = _a.sent();
|
|
860
|
-
return [3 /*break*/, 11];
|
|
861
|
-
case 11: throw error_4;
|
|
862
|
-
case 12:
|
|
863
|
-
if (!(queryRunner !== this.queryRunner)) return [3 /*break*/, 14];
|
|
864
|
-
// means we created our own query runner
|
|
865
|
-
return [4 /*yield*/, queryRunner.release()];
|
|
866
|
-
case 13:
|
|
867
|
-
// means we created our own query runner
|
|
868
|
-
_a.sent();
|
|
869
|
-
_a.label = 14;
|
|
870
|
-
case 14: return [7 /*endfinally*/];
|
|
871
|
-
case 15: return [2 /*return*/];
|
|
725
|
+
async getCount() {
|
|
726
|
+
if (this.expressionMap.lockMode === "optimistic")
|
|
727
|
+
throw new OptimisticLockCanNotBeUsedError_1.OptimisticLockCanNotBeUsedError();
|
|
728
|
+
const queryRunner = this.obtainQueryRunner();
|
|
729
|
+
let transactionStartedByUs = false;
|
|
730
|
+
try {
|
|
731
|
+
// start transaction if it was enabled
|
|
732
|
+
if (this.expressionMap.useTransaction === true &&
|
|
733
|
+
queryRunner.isTransactionActive === false) {
|
|
734
|
+
await queryRunner.startTransaction();
|
|
735
|
+
transactionStartedByUs = true;
|
|
736
|
+
}
|
|
737
|
+
this.expressionMap.queryEntity = false;
|
|
738
|
+
const results = await this.executeCountQuery(queryRunner);
|
|
739
|
+
// close transaction if we started it
|
|
740
|
+
if (transactionStartedByUs) {
|
|
741
|
+
await queryRunner.commitTransaction();
|
|
742
|
+
}
|
|
743
|
+
return results;
|
|
744
|
+
}
|
|
745
|
+
catch (error) {
|
|
746
|
+
// rollback transaction if we started it
|
|
747
|
+
if (transactionStartedByUs) {
|
|
748
|
+
try {
|
|
749
|
+
await queryRunner.rollbackTransaction();
|
|
872
750
|
}
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
751
|
+
catch (rollbackError) { }
|
|
752
|
+
}
|
|
753
|
+
throw error;
|
|
754
|
+
}
|
|
755
|
+
finally {
|
|
756
|
+
if (queryRunner !== this.queryRunner)
|
|
757
|
+
// means we created our own query runner
|
|
758
|
+
await queryRunner.release();
|
|
759
|
+
}
|
|
760
|
+
}
|
|
876
761
|
/**
|
|
877
762
|
* Executes built SQL query and returns entities and overall entities count (without limitation).
|
|
878
763
|
* This method is useful to build pagination.
|
|
879
764
|
*/
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
count = _a.sent();
|
|
913
|
-
results = [entitiesAndRaw.entities, count];
|
|
914
|
-
if (!transactionStartedByUs) return [3 /*break*/, 7];
|
|
915
|
-
return [4 /*yield*/, queryRunner.commitTransaction()];
|
|
916
|
-
case 6:
|
|
917
|
-
_a.sent();
|
|
918
|
-
_a.label = 7;
|
|
919
|
-
case 7: return [2 /*return*/, results];
|
|
920
|
-
case 8:
|
|
921
|
-
error_5 = _a.sent();
|
|
922
|
-
if (!transactionStartedByUs) return [3 /*break*/, 12];
|
|
923
|
-
_a.label = 9;
|
|
924
|
-
case 9:
|
|
925
|
-
_a.trys.push([9, 11, , 12]);
|
|
926
|
-
return [4 /*yield*/, queryRunner.rollbackTransaction()];
|
|
927
|
-
case 10:
|
|
928
|
-
_a.sent();
|
|
929
|
-
return [3 /*break*/, 12];
|
|
930
|
-
case 11:
|
|
931
|
-
rollbackError_4 = _a.sent();
|
|
932
|
-
return [3 /*break*/, 12];
|
|
933
|
-
case 12: throw error_5;
|
|
934
|
-
case 13:
|
|
935
|
-
if (!(queryRunner !== this.queryRunner)) return [3 /*break*/, 15];
|
|
936
|
-
// means we created our own query runner
|
|
937
|
-
return [4 /*yield*/, queryRunner.release()];
|
|
938
|
-
case 14:
|
|
939
|
-
// means we created our own query runner
|
|
940
|
-
_a.sent();
|
|
941
|
-
_a.label = 15;
|
|
942
|
-
case 15: return [7 /*endfinally*/];
|
|
943
|
-
case 16: return [2 /*return*/];
|
|
765
|
+
async getManyAndCount() {
|
|
766
|
+
if (this.expressionMap.lockMode === "optimistic")
|
|
767
|
+
throw new OptimisticLockCanNotBeUsedError_1.OptimisticLockCanNotBeUsedError();
|
|
768
|
+
const queryRunner = this.obtainQueryRunner();
|
|
769
|
+
let transactionStartedByUs = false;
|
|
770
|
+
try {
|
|
771
|
+
// start transaction if it was enabled
|
|
772
|
+
if (this.expressionMap.useTransaction === true &&
|
|
773
|
+
queryRunner.isTransactionActive === false) {
|
|
774
|
+
await queryRunner.startTransaction();
|
|
775
|
+
transactionStartedByUs = true;
|
|
776
|
+
}
|
|
777
|
+
this.expressionMap.queryEntity = true;
|
|
778
|
+
const entitiesAndRaw = await this.executeEntitiesAndRawResults(queryRunner);
|
|
779
|
+
this.expressionMap.queryEntity = false;
|
|
780
|
+
const cacheId = this.expressionMap.cacheId;
|
|
781
|
+
// Creates a new cacheId for the count query, or it will retreive the above query results
|
|
782
|
+
// and count will return 0.
|
|
783
|
+
this.expressionMap.cacheId = cacheId ? `${cacheId}-count` : cacheId;
|
|
784
|
+
const count = await this.executeCountQuery(queryRunner);
|
|
785
|
+
const results = [entitiesAndRaw.entities, count];
|
|
786
|
+
// close transaction if we started it
|
|
787
|
+
if (transactionStartedByUs) {
|
|
788
|
+
await queryRunner.commitTransaction();
|
|
789
|
+
}
|
|
790
|
+
return results;
|
|
791
|
+
}
|
|
792
|
+
catch (error) {
|
|
793
|
+
// rollback transaction if we started it
|
|
794
|
+
if (transactionStartedByUs) {
|
|
795
|
+
try {
|
|
796
|
+
await queryRunner.rollbackTransaction();
|
|
944
797
|
}
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
798
|
+
catch (rollbackError) { }
|
|
799
|
+
}
|
|
800
|
+
throw error;
|
|
801
|
+
}
|
|
802
|
+
finally {
|
|
803
|
+
if (queryRunner !== this.queryRunner)
|
|
804
|
+
// means we created our own query runner
|
|
805
|
+
await queryRunner.release();
|
|
806
|
+
}
|
|
807
|
+
}
|
|
948
808
|
//#region @backend
|
|
949
809
|
/**
|
|
950
810
|
* Executes built SQL query and returns raw data stream.
|
|
951
811
|
*/
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
return [4 /*yield*/, queryRunner.commitTransaction()];
|
|
983
|
-
case 4:
|
|
984
|
-
_b.sent();
|
|
985
|
-
_b.label = 5;
|
|
986
|
-
case 5: return [2 /*return*/, results];
|
|
987
|
-
case 6:
|
|
988
|
-
error_6 = _b.sent();
|
|
989
|
-
if (!transactionStartedByUs) return [3 /*break*/, 10];
|
|
990
|
-
_b.label = 7;
|
|
991
|
-
case 7:
|
|
992
|
-
_b.trys.push([7, 9, , 10]);
|
|
993
|
-
return [4 /*yield*/, queryRunner.rollbackTransaction()];
|
|
994
|
-
case 8:
|
|
995
|
-
_b.sent();
|
|
996
|
-
return [3 /*break*/, 10];
|
|
997
|
-
case 9:
|
|
998
|
-
rollbackError_5 = _b.sent();
|
|
999
|
-
return [3 /*break*/, 10];
|
|
1000
|
-
case 10: throw error_6;
|
|
1001
|
-
case 11: return [2 /*return*/];
|
|
812
|
+
async stream() {
|
|
813
|
+
this.expressionMap.queryEntity = false;
|
|
814
|
+
const [sql, parameters] = this.getQueryAndParameters();
|
|
815
|
+
const queryRunner = this.obtainQueryRunner();
|
|
816
|
+
let transactionStartedByUs = false;
|
|
817
|
+
try {
|
|
818
|
+
// start transaction if it was enabled
|
|
819
|
+
if (this.expressionMap.useTransaction === true &&
|
|
820
|
+
queryRunner.isTransactionActive === false) {
|
|
821
|
+
await queryRunner.startTransaction();
|
|
822
|
+
transactionStartedByUs = true;
|
|
823
|
+
}
|
|
824
|
+
const releaseFn = () => {
|
|
825
|
+
if (queryRunner !== this.queryRunner)
|
|
826
|
+
// means we created our own query runner
|
|
827
|
+
return queryRunner.release();
|
|
828
|
+
return;
|
|
829
|
+
};
|
|
830
|
+
const results = queryRunner.stream(sql, parameters, releaseFn, releaseFn);
|
|
831
|
+
// close transaction if we started it
|
|
832
|
+
if (transactionStartedByUs) {
|
|
833
|
+
await queryRunner.commitTransaction();
|
|
834
|
+
}
|
|
835
|
+
return results;
|
|
836
|
+
}
|
|
837
|
+
catch (error) {
|
|
838
|
+
// rollback transaction if we started it
|
|
839
|
+
if (transactionStartedByUs) {
|
|
840
|
+
try {
|
|
841
|
+
await queryRunner.rollbackTransaction();
|
|
1002
842
|
}
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
843
|
+
catch (rollbackError) { }
|
|
844
|
+
}
|
|
845
|
+
throw error;
|
|
846
|
+
}
|
|
847
|
+
}
|
|
1006
848
|
/**
|
|
1007
849
|
* Enables or disables query result caching.
|
|
1008
850
|
*/
|
|
1009
|
-
|
|
851
|
+
cache(enabledOrMillisecondsOrId, maybeMilliseconds) {
|
|
1010
852
|
if (typeof enabledOrMillisecondsOrId === "boolean") {
|
|
1011
853
|
this.expressionMap.cache = enabledOrMillisecondsOrId;
|
|
1012
854
|
}
|
|
@@ -1023,20 +865,20 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
1023
865
|
this.expressionMap.cacheDuration = maybeMilliseconds;
|
|
1024
866
|
}
|
|
1025
867
|
return this;
|
|
1026
|
-
}
|
|
868
|
+
}
|
|
1027
869
|
/**
|
|
1028
870
|
* Sets extra options that can be used to configure how query builder works.
|
|
1029
871
|
*/
|
|
1030
|
-
|
|
872
|
+
setOption(option) {
|
|
1031
873
|
this.expressionMap.options.push(option);
|
|
1032
874
|
return this;
|
|
1033
|
-
}
|
|
875
|
+
}
|
|
1034
876
|
// -------------------------------------------------------------------------
|
|
1035
877
|
// Protected Methods
|
|
1036
878
|
// -------------------------------------------------------------------------
|
|
1037
|
-
|
|
879
|
+
join(direction, entityOrProperty, aliasName, condition, parameters, mapToProperty, isMappingMany) {
|
|
1038
880
|
this.setParameters(parameters || {});
|
|
1039
|
-
|
|
881
|
+
const joinAttribute = new JoinAttribute_1.JoinAttribute(this.connection, this.expressionMap);
|
|
1040
882
|
joinAttribute.direction = direction;
|
|
1041
883
|
joinAttribute.mapToProperty = mapToProperty;
|
|
1042
884
|
joinAttribute.isMappingMany = isMappingMany;
|
|
@@ -1047,10 +889,10 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
1047
889
|
if (joinAttribute.metadata) {
|
|
1048
890
|
if (joinAttribute.metadata.deleteDateColumn &&
|
|
1049
891
|
!this.expressionMap.withDeleted) {
|
|
1050
|
-
|
|
892
|
+
const conditionDeleteColumn = `${aliasName}.${joinAttribute.metadata.deleteDateColumn.propertyName} IS NULL`;
|
|
1051
893
|
joinAttribute.condition = joinAttribute.condition
|
|
1052
|
-
?
|
|
1053
|
-
:
|
|
894
|
+
? ` ${joinAttribute.condition} AND ${conditionDeleteColumn}`
|
|
895
|
+
: `${conditionDeleteColumn}`;
|
|
1054
896
|
}
|
|
1055
897
|
// todo: find and set metadata right there?
|
|
1056
898
|
joinAttribute.alias = this.expressionMap.createAlias({
|
|
@@ -1068,16 +910,16 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
1068
910
|
}
|
|
1069
911
|
}
|
|
1070
912
|
else {
|
|
1071
|
-
|
|
913
|
+
let subQuery = "";
|
|
1072
914
|
if (typeof entityOrProperty === "function") {
|
|
1073
|
-
|
|
915
|
+
const subQueryBuilder = entityOrProperty(this.subQuery());
|
|
1074
916
|
this.setParameters(subQueryBuilder.getParameters());
|
|
1075
917
|
subQuery = subQueryBuilder.getQuery();
|
|
1076
918
|
}
|
|
1077
919
|
else {
|
|
1078
920
|
subQuery = entityOrProperty;
|
|
1079
921
|
}
|
|
1080
|
-
|
|
922
|
+
const isSubQuery = typeof entityOrProperty === "function" ||
|
|
1081
923
|
(entityOrProperty.substr(0, 1) === "(" &&
|
|
1082
924
|
entityOrProperty.substr(-1) === ")");
|
|
1083
925
|
joinAttribute.alias = this.expressionMap.createAlias({
|
|
@@ -1089,79 +931,72 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
1089
931
|
subQuery: isSubQuery === true ? subQuery : undefined,
|
|
1090
932
|
});
|
|
1091
933
|
}
|
|
1092
|
-
}
|
|
934
|
+
}
|
|
1093
935
|
/**
|
|
1094
936
|
* Creates "SELECT FROM" part of SQL query.
|
|
1095
937
|
*/
|
|
1096
|
-
|
|
1097
|
-
var _this = this;
|
|
938
|
+
createSelectExpression() {
|
|
1098
939
|
if (!this.expressionMap.mainAlias)
|
|
1099
940
|
throw new error_1.TypeORMError("Cannot build query because main alias is not set (call qb#from method)");
|
|
1100
941
|
// todo throw exception if selects or from is missing
|
|
1101
|
-
|
|
1102
|
-
|
|
942
|
+
const allSelects = [];
|
|
943
|
+
const excludedSelects = [];
|
|
1103
944
|
if (this.expressionMap.mainAlias.hasMetadata) {
|
|
1104
|
-
|
|
1105
|
-
allSelects.push
|
|
1106
|
-
excludedSelects.push
|
|
945
|
+
const metadata = this.expressionMap.mainAlias.metadata;
|
|
946
|
+
allSelects.push(...this.buildEscapedEntityColumnSelects(this.expressionMap.mainAlias.name, metadata));
|
|
947
|
+
excludedSelects.push(...this.findEntityColumnSelects(this.expressionMap.mainAlias.name, metadata));
|
|
1107
948
|
}
|
|
1108
949
|
// add selects from joins
|
|
1109
|
-
this.expressionMap.joinAttributes.forEach(
|
|
950
|
+
this.expressionMap.joinAttributes.forEach((join) => {
|
|
1110
951
|
if (join.metadata) {
|
|
1111
|
-
allSelects.push
|
|
1112
|
-
excludedSelects.push
|
|
952
|
+
allSelects.push(...this.buildEscapedEntityColumnSelects(join.alias.name, join.metadata));
|
|
953
|
+
excludedSelects.push(...this.findEntityColumnSelects(join.alias.name, join.metadata));
|
|
1113
954
|
}
|
|
1114
955
|
else {
|
|
1115
|
-
|
|
956
|
+
const hasMainAlias = this.expressionMap.selects.some((select) => select.selection === join.alias.name);
|
|
1116
957
|
if (hasMainAlias) {
|
|
1117
958
|
allSelects.push({
|
|
1118
|
-
selection:
|
|
959
|
+
selection: this.escape(join.alias.name) + ".*",
|
|
1119
960
|
});
|
|
1120
|
-
|
|
961
|
+
const excludedSelect = this.expressionMap.selects.find((select) => select.selection === join.alias.name);
|
|
1121
962
|
excludedSelects.push(excludedSelect);
|
|
1122
963
|
}
|
|
1123
964
|
}
|
|
1124
965
|
});
|
|
1125
966
|
// add all other selects
|
|
1126
967
|
this.expressionMap.selects
|
|
1127
|
-
.filter(
|
|
1128
|
-
.forEach(
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
});
|
|
1133
|
-
});
|
|
968
|
+
.filter((select) => excludedSelects.indexOf(select) === -1)
|
|
969
|
+
.forEach((select) => allSelects.push({
|
|
970
|
+
selection: this.replacePropertyNames(select.selection),
|
|
971
|
+
aliasName: select.aliasName,
|
|
972
|
+
}));
|
|
1134
973
|
// if still selection is empty, then simply set it to all (*)
|
|
1135
974
|
if (allSelects.length === 0)
|
|
1136
975
|
allSelects.push({ selection: "*" });
|
|
1137
976
|
// Use certain index
|
|
1138
|
-
|
|
977
|
+
let useIndex = "";
|
|
1139
978
|
if (this.expressionMap.useIndex) {
|
|
1140
979
|
if (DriverUtils_1.DriverUtils.isMySQLFamily(this.connection.driver)) {
|
|
1141
|
-
useIndex =
|
|
980
|
+
useIndex = ` USE INDEX (${this.expressionMap.useIndex})`;
|
|
1142
981
|
}
|
|
1143
982
|
}
|
|
1144
983
|
// create a selection query
|
|
1145
|
-
|
|
1146
|
-
.filter(
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
})
|
|
1150
|
-
.map(function (alias) {
|
|
984
|
+
const froms = this.expressionMap.aliases
|
|
985
|
+
.filter((alias) => alias.type === "from" &&
|
|
986
|
+
(alias.tablePath || alias.subQuery))
|
|
987
|
+
.map((alias) => {
|
|
1151
988
|
if (alias.subQuery)
|
|
1152
|
-
return alias.subQuery + " " +
|
|
1153
|
-
return (
|
|
989
|
+
return alias.subQuery + " " + this.escape(alias.name);
|
|
990
|
+
return (this.getTableName(alias.tablePath) +
|
|
1154
991
|
" " +
|
|
1155
|
-
|
|
992
|
+
this.escape(alias.name));
|
|
1156
993
|
});
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
.map(
|
|
1160
|
-
|
|
1161
|
-
(select.aliasName
|
|
1162
|
-
|
|
1163
|
-
: "");
|
|
1164
|
-
})
|
|
994
|
+
const select = this.createSelectDistinctExpression();
|
|
995
|
+
const selection = allSelects
|
|
996
|
+
.map((select) => select.selection +
|
|
997
|
+
(select.aliasName
|
|
998
|
+
? " AS " + this.escape(select.aliasName)
|
|
999
|
+
: ""))
|
|
1165
1000
|
.join(", ");
|
|
1166
1001
|
return (select +
|
|
1167
1002
|
selection +
|
|
@@ -1169,36 +1004,35 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
1169
1004
|
froms.join(", ") +
|
|
1170
1005
|
this.createTableLockExpression() +
|
|
1171
1006
|
useIndex);
|
|
1172
|
-
}
|
|
1007
|
+
}
|
|
1173
1008
|
/**
|
|
1174
1009
|
* Creates select | select distinct part of SQL query.
|
|
1175
1010
|
*/
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
var select = "SELECT ";
|
|
1011
|
+
createSelectDistinctExpression() {
|
|
1012
|
+
const { selectDistinct, selectDistinctOn, maxExecutionTime } = this.expressionMap;
|
|
1013
|
+
const { driver } = this.connection;
|
|
1014
|
+
let select = "SELECT ";
|
|
1181
1015
|
if (maxExecutionTime > 0) {
|
|
1182
1016
|
if (DriverUtils_1.DriverUtils.isMySQLFamily(driver)) {
|
|
1183
|
-
select +=
|
|
1017
|
+
select += `/*+ MAX_EXECUTION_TIME(${this.expressionMap.maxExecutionTime}) */ `;
|
|
1184
1018
|
}
|
|
1185
1019
|
}
|
|
1186
1020
|
if (DriverUtils_1.DriverUtils.isPostgresFamily(driver) &&
|
|
1187
1021
|
selectDistinctOn.length > 0) {
|
|
1188
|
-
|
|
1189
|
-
.map(
|
|
1022
|
+
const selectDistinctOnMap = selectDistinctOn
|
|
1023
|
+
.map((on) => this.replacePropertyNames(on))
|
|
1190
1024
|
.join(", ");
|
|
1191
|
-
select =
|
|
1025
|
+
select = `SELECT DISTINCT ON (${selectDistinctOnMap}) `;
|
|
1192
1026
|
}
|
|
1193
1027
|
else if (selectDistinct) {
|
|
1194
1028
|
select = "SELECT DISTINCT ";
|
|
1195
1029
|
}
|
|
1196
1030
|
return select;
|
|
1197
|
-
}
|
|
1031
|
+
}
|
|
1198
1032
|
/**
|
|
1199
1033
|
* Creates "JOIN" part of SQL query.
|
|
1200
1034
|
*/
|
|
1201
|
-
|
|
1035
|
+
createJoinExpression() {
|
|
1202
1036
|
// examples:
|
|
1203
1037
|
// select from owning side
|
|
1204
1038
|
// qb.select("post")
|
|
@@ -1206,37 +1040,36 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
1206
1040
|
// select from non-owning side
|
|
1207
1041
|
// qb.select("category")
|
|
1208
1042
|
// .leftJoinAndSelect("category.post", "post");
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
var appendedCondition = joinAttr.condition
|
|
1043
|
+
const joins = this.expressionMap.joinAttributes.map((joinAttr) => {
|
|
1044
|
+
const relation = joinAttr.relation;
|
|
1045
|
+
const destinationTableName = joinAttr.tablePath;
|
|
1046
|
+
const destinationTableAlias = joinAttr.alias.name;
|
|
1047
|
+
let appendedCondition = joinAttr.condition
|
|
1215
1048
|
? " AND (" + joinAttr.condition + ")"
|
|
1216
1049
|
: "";
|
|
1217
|
-
|
|
1050
|
+
const parentAlias = joinAttr.parentAlias;
|
|
1218
1051
|
// if join was build without relation (e.g. without "post.category") then it means that we have direct
|
|
1219
1052
|
// table to join, without junction table involved. This means we simply join direct table.
|
|
1220
1053
|
if (!parentAlias || !relation) {
|
|
1221
|
-
|
|
1054
|
+
const destinationJoin = joinAttr.alias.subQuery
|
|
1222
1055
|
? joinAttr.alias.subQuery
|
|
1223
|
-
:
|
|
1056
|
+
: this.getTableName(destinationTableName);
|
|
1224
1057
|
return (" " +
|
|
1225
1058
|
joinAttr.direction +
|
|
1226
1059
|
" JOIN " +
|
|
1227
1060
|
destinationJoin +
|
|
1228
1061
|
" " +
|
|
1229
|
-
|
|
1230
|
-
|
|
1062
|
+
this.escape(destinationTableAlias) +
|
|
1063
|
+
this.createTableLockExpression() +
|
|
1231
1064
|
(joinAttr.condition
|
|
1232
|
-
? " ON " +
|
|
1065
|
+
? " ON " + this.replacePropertyNames(joinAttr.condition)
|
|
1233
1066
|
: ""));
|
|
1234
1067
|
}
|
|
1235
1068
|
// if real entity relation is involved
|
|
1236
1069
|
if (relation.isManyToOne || relation.isOneToOneOwner) {
|
|
1237
1070
|
// JOIN `category` `category` ON `category`.`id` = `post`.`categoryId`
|
|
1238
|
-
|
|
1239
|
-
.map(
|
|
1071
|
+
const condition = relation.joinColumns
|
|
1072
|
+
.map((joinColumn) => {
|
|
1240
1073
|
return (destinationTableAlias +
|
|
1241
1074
|
"." +
|
|
1242
1075
|
joinColumn.referencedColumn.propertyPath +
|
|
@@ -1251,17 +1084,17 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
1251
1084
|
return (" " +
|
|
1252
1085
|
joinAttr.direction +
|
|
1253
1086
|
" JOIN " +
|
|
1254
|
-
|
|
1087
|
+
this.getTableName(destinationTableName) +
|
|
1255
1088
|
" " +
|
|
1256
|
-
|
|
1257
|
-
|
|
1089
|
+
this.escape(destinationTableAlias) +
|
|
1090
|
+
this.createTableLockExpression() +
|
|
1258
1091
|
" ON " +
|
|
1259
|
-
|
|
1092
|
+
this.replacePropertyNames(condition + appendedCondition));
|
|
1260
1093
|
}
|
|
1261
1094
|
else if (relation.isOneToMany || relation.isOneToOneNotOwner) {
|
|
1262
1095
|
// JOIN `post` `post` ON `post`.`categoryId` = `category`.`id`
|
|
1263
|
-
|
|
1264
|
-
.inverseRelation.joinColumns.map(
|
|
1096
|
+
const condition = relation
|
|
1097
|
+
.inverseRelation.joinColumns.map((joinColumn) => {
|
|
1265
1098
|
if (relation.inverseEntityMetadata.tableType ===
|
|
1266
1099
|
"entity-child" &&
|
|
1267
1100
|
relation.inverseEntityMetadata.discriminatorColumn) {
|
|
@@ -1290,23 +1123,23 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
1290
1123
|
return (" " +
|
|
1291
1124
|
joinAttr.direction +
|
|
1292
1125
|
" JOIN " +
|
|
1293
|
-
|
|
1126
|
+
this.getTableName(destinationTableName) +
|
|
1294
1127
|
" " +
|
|
1295
|
-
|
|
1296
|
-
|
|
1128
|
+
this.escape(destinationTableAlias) +
|
|
1129
|
+
this.createTableLockExpression() +
|
|
1297
1130
|
" ON " +
|
|
1298
|
-
|
|
1131
|
+
this.replacePropertyNames(condition + appendedCondition));
|
|
1299
1132
|
}
|
|
1300
1133
|
else {
|
|
1301
1134
|
// means many-to-many
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1135
|
+
const junctionTableName = relation.junctionEntityMetadata.tablePath;
|
|
1136
|
+
const junctionAlias = joinAttr.junctionAlias;
|
|
1137
|
+
let junctionCondition = "", destinationCondition = "";
|
|
1305
1138
|
if (relation.isOwning) {
|
|
1306
1139
|
junctionCondition = relation.joinColumns
|
|
1307
|
-
.map(
|
|
1140
|
+
.map((joinColumn) => {
|
|
1308
1141
|
// `post_category`.`postId` = `post`.`id`
|
|
1309
|
-
return (
|
|
1142
|
+
return (junctionAlias +
|
|
1310
1143
|
"." +
|
|
1311
1144
|
joinColumn.propertyPath +
|
|
1312
1145
|
"=" +
|
|
@@ -1316,13 +1149,13 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
1316
1149
|
})
|
|
1317
1150
|
.join(" AND ");
|
|
1318
1151
|
destinationCondition = relation.inverseJoinColumns
|
|
1319
|
-
.map(
|
|
1152
|
+
.map((joinColumn) => {
|
|
1320
1153
|
// `category`.`id` = `post_category`.`categoryId`
|
|
1321
1154
|
return (destinationTableAlias +
|
|
1322
1155
|
"." +
|
|
1323
1156
|
joinColumn.referencedColumn.propertyPath +
|
|
1324
1157
|
"=" +
|
|
1325
|
-
|
|
1158
|
+
junctionAlias +
|
|
1326
1159
|
"." +
|
|
1327
1160
|
joinColumn.propertyPath);
|
|
1328
1161
|
})
|
|
@@ -1330,9 +1163,9 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
1330
1163
|
}
|
|
1331
1164
|
else {
|
|
1332
1165
|
junctionCondition = relation
|
|
1333
|
-
.inverseRelation.inverseJoinColumns.map(
|
|
1166
|
+
.inverseRelation.inverseJoinColumns.map((joinColumn) => {
|
|
1334
1167
|
// `post_category`.`categoryId` = `category`.`id`
|
|
1335
|
-
return (
|
|
1168
|
+
return (junctionAlias +
|
|
1336
1169
|
"." +
|
|
1337
1170
|
joinColumn.propertyPath +
|
|
1338
1171
|
"=" +
|
|
@@ -1342,13 +1175,13 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
1342
1175
|
})
|
|
1343
1176
|
.join(" AND ");
|
|
1344
1177
|
destinationCondition = relation
|
|
1345
|
-
.inverseRelation.joinColumns.map(
|
|
1178
|
+
.inverseRelation.joinColumns.map((joinColumn) => {
|
|
1346
1179
|
// `post`.`id` = `post_category`.`postId`
|
|
1347
1180
|
return (destinationTableAlias +
|
|
1348
1181
|
"." +
|
|
1349
1182
|
joinColumn.referencedColumn.propertyPath +
|
|
1350
1183
|
"=" +
|
|
1351
|
-
|
|
1184
|
+
junctionAlias +
|
|
1352
1185
|
"." +
|
|
1353
1186
|
joinColumn.propertyPath);
|
|
1354
1187
|
})
|
|
@@ -1357,51 +1190,50 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
1357
1190
|
return (" " +
|
|
1358
1191
|
joinAttr.direction +
|
|
1359
1192
|
" JOIN " +
|
|
1360
|
-
|
|
1193
|
+
this.getTableName(junctionTableName) +
|
|
1361
1194
|
" " +
|
|
1362
|
-
|
|
1363
|
-
|
|
1195
|
+
this.escape(junctionAlias) +
|
|
1196
|
+
this.createTableLockExpression() +
|
|
1364
1197
|
" ON " +
|
|
1365
|
-
|
|
1198
|
+
this.replacePropertyNames(junctionCondition) +
|
|
1366
1199
|
" " +
|
|
1367
1200
|
joinAttr.direction +
|
|
1368
1201
|
" JOIN " +
|
|
1369
|
-
|
|
1202
|
+
this.getTableName(destinationTableName) +
|
|
1370
1203
|
" " +
|
|
1371
|
-
|
|
1372
|
-
|
|
1204
|
+
this.escape(destinationTableAlias) +
|
|
1205
|
+
this.createTableLockExpression() +
|
|
1373
1206
|
" ON " +
|
|
1374
|
-
|
|
1207
|
+
this.replacePropertyNames(destinationCondition + appendedCondition));
|
|
1375
1208
|
}
|
|
1376
1209
|
});
|
|
1377
1210
|
return joins.join(" ");
|
|
1378
|
-
}
|
|
1211
|
+
}
|
|
1379
1212
|
/**
|
|
1380
1213
|
* Creates "GROUP BY" part of SQL query.
|
|
1381
1214
|
*/
|
|
1382
|
-
|
|
1215
|
+
createGroupByExpression() {
|
|
1383
1216
|
if (!this.expressionMap.groupBys || !this.expressionMap.groupBys.length)
|
|
1384
1217
|
return "";
|
|
1385
1218
|
return (" GROUP BY " +
|
|
1386
1219
|
this.replacePropertyNames(this.expressionMap.groupBys.join(", ")));
|
|
1387
|
-
}
|
|
1220
|
+
}
|
|
1388
1221
|
/**
|
|
1389
1222
|
* Creates "ORDER BY" part of SQL query.
|
|
1390
1223
|
*/
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
var orderBys = this.expressionMap.allOrderBys;
|
|
1224
|
+
createOrderByExpression() {
|
|
1225
|
+
const orderBys = this.expressionMap.allOrderBys;
|
|
1394
1226
|
if (Object.keys(orderBys).length > 0)
|
|
1395
1227
|
return (" ORDER BY " +
|
|
1396
1228
|
Object.keys(orderBys)
|
|
1397
|
-
.map(
|
|
1229
|
+
.map((columnName) => {
|
|
1398
1230
|
if (typeof orderBys[columnName] === "string") {
|
|
1399
|
-
return (
|
|
1231
|
+
return (this.replacePropertyNames(columnName) +
|
|
1400
1232
|
" " +
|
|
1401
1233
|
orderBys[columnName]);
|
|
1402
1234
|
}
|
|
1403
1235
|
else {
|
|
1404
|
-
return (
|
|
1236
|
+
return (this.replacePropertyNames(columnName) +
|
|
1405
1237
|
" " +
|
|
1406
1238
|
orderBys[columnName].order +
|
|
1407
1239
|
" " +
|
|
@@ -1410,14 +1242,14 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
1410
1242
|
})
|
|
1411
1243
|
.join(", "));
|
|
1412
1244
|
return "";
|
|
1413
|
-
}
|
|
1245
|
+
}
|
|
1414
1246
|
/**
|
|
1415
1247
|
* Creates "LIMIT" and "OFFSET" parts of SQL query.
|
|
1416
1248
|
*/
|
|
1417
|
-
|
|
1249
|
+
createLimitOffsetExpression() {
|
|
1418
1250
|
// in the case if nothing is joined in the query builder we don't need to make two requests to get paginated results
|
|
1419
1251
|
// we can use regular limit / offset, that's why we add offset and limit construction here based on skip and take values
|
|
1420
|
-
|
|
1252
|
+
let offset = this.expressionMap.offset, limit = this.expressionMap.limit;
|
|
1421
1253
|
if (!offset &&
|
|
1422
1254
|
!limit &&
|
|
1423
1255
|
this.expressionMap.joinAttributes.length === 0) {
|
|
@@ -1430,7 +1262,7 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
1430
1262
|
// user does not request one we insert a dummy ORDER BY that does nothing and should
|
|
1431
1263
|
// have no effect on the query planner or on the order of the results returned.
|
|
1432
1264
|
// https://dba.stackexchange.com/a/193799
|
|
1433
|
-
|
|
1265
|
+
let prefix = "";
|
|
1434
1266
|
if ((limit || offset) &&
|
|
1435
1267
|
Object.keys(this.expressionMap.allOrderBys).length <= 0) {
|
|
1436
1268
|
prefix = " ORDER BY (SELECT NULL)";
|
|
@@ -1487,7 +1319,7 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
1487
1319
|
return " OFFSET " + offset;
|
|
1488
1320
|
}
|
|
1489
1321
|
return "";
|
|
1490
|
-
}
|
|
1322
|
+
}
|
|
1491
1323
|
/**
|
|
1492
1324
|
* Creates "LOCK" part of SELECT Query after table Clause
|
|
1493
1325
|
* ex.
|
|
@@ -1496,7 +1328,7 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
1496
1328
|
* JOIN ORDER O WITH (NOLOCK)
|
|
1497
1329
|
* ON U.ID=O.OrderID
|
|
1498
1330
|
*/
|
|
1499
|
-
|
|
1331
|
+
createTableLockExpression() {
|
|
1500
1332
|
if (this.connection.driver.options.type === "mssql") {
|
|
1501
1333
|
switch (this.expressionMap.lockMode) {
|
|
1502
1334
|
case "pessimistic_read":
|
|
@@ -1508,13 +1340,13 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
1508
1340
|
}
|
|
1509
1341
|
}
|
|
1510
1342
|
return "";
|
|
1511
|
-
}
|
|
1343
|
+
}
|
|
1512
1344
|
/**
|
|
1513
1345
|
* Creates "LOCK" part of SQL query.
|
|
1514
1346
|
*/
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1347
|
+
createLockExpression() {
|
|
1348
|
+
const driver = this.connection.driver;
|
|
1349
|
+
let lockTablesClause = "";
|
|
1518
1350
|
if (this.expressionMap.lockTables) {
|
|
1519
1351
|
if (!(DriverUtils_1.DriverUtils.isPostgresFamily(driver) ||
|
|
1520
1352
|
driver.options.type === "cockroachdb")) {
|
|
@@ -1525,7 +1357,7 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
1525
1357
|
}
|
|
1526
1358
|
lockTablesClause = " OF " + this.expressionMap.lockTables.join(", ");
|
|
1527
1359
|
}
|
|
1528
|
-
|
|
1360
|
+
let onLockExpression = "";
|
|
1529
1361
|
if (this.expressionMap.onLocked === "nowait") {
|
|
1530
1362
|
onLockExpression = " NOWAIT";
|
|
1531
1363
|
}
|
|
@@ -1615,94 +1447,88 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
1615
1447
|
default:
|
|
1616
1448
|
return "";
|
|
1617
1449
|
}
|
|
1618
|
-
}
|
|
1450
|
+
}
|
|
1619
1451
|
/**
|
|
1620
1452
|
* Creates "HAVING" part of SQL query.
|
|
1621
1453
|
*/
|
|
1622
|
-
|
|
1623
|
-
var _this = this;
|
|
1454
|
+
createHavingExpression() {
|
|
1624
1455
|
if (!this.expressionMap.havings || !this.expressionMap.havings.length)
|
|
1625
1456
|
return "";
|
|
1626
|
-
|
|
1627
|
-
.map(
|
|
1457
|
+
const conditions = this.expressionMap.havings
|
|
1458
|
+
.map((having, index) => {
|
|
1628
1459
|
switch (having.type) {
|
|
1629
1460
|
case "and":
|
|
1630
1461
|
return ((index > 0 ? "AND " : "") +
|
|
1631
|
-
|
|
1462
|
+
this.replacePropertyNames(having.condition));
|
|
1632
1463
|
case "or":
|
|
1633
1464
|
return ((index > 0 ? "OR " : "") +
|
|
1634
|
-
|
|
1465
|
+
this.replacePropertyNames(having.condition));
|
|
1635
1466
|
default:
|
|
1636
|
-
return
|
|
1467
|
+
return this.replacePropertyNames(having.condition);
|
|
1637
1468
|
}
|
|
1638
1469
|
})
|
|
1639
1470
|
.join(" ");
|
|
1640
1471
|
if (!conditions.length)
|
|
1641
1472
|
return "";
|
|
1642
1473
|
return " HAVING " + conditions;
|
|
1643
|
-
}
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
var columns = [];
|
|
1474
|
+
}
|
|
1475
|
+
buildEscapedEntityColumnSelects(aliasName, metadata) {
|
|
1476
|
+
const hasMainAlias = this.expressionMap.selects.some((select) => select.selection === aliasName);
|
|
1477
|
+
const columns = [];
|
|
1648
1478
|
if (hasMainAlias) {
|
|
1649
|
-
columns.push
|
|
1479
|
+
columns.push(...metadata.columns.filter((column) => column.isSelect === true));
|
|
1650
1480
|
}
|
|
1651
|
-
columns.push
|
|
1652
|
-
return
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
});
|
|
1656
|
-
})), false));
|
|
1481
|
+
columns.push(...metadata.columns.filter((column) => {
|
|
1482
|
+
return this.expressionMap.selects.some((select) => select.selection ===
|
|
1483
|
+
aliasName + "." + column.propertyPath);
|
|
1484
|
+
}));
|
|
1657
1485
|
// if user used partial selection and did not select some primary columns which are required to be selected
|
|
1658
1486
|
// we select those primary columns and mark them as "virtual". Later virtual column values will be removed from final entity
|
|
1659
1487
|
// to make entity contain exactly what user selected
|
|
1660
1488
|
if (columns.length === 0)
|
|
1661
1489
|
// however not in the case when nothing (even partial) was selected from this target (for example joins without selection)
|
|
1662
1490
|
return [];
|
|
1663
|
-
|
|
1664
|
-
? metadata.primaryColumns.filter(
|
|
1491
|
+
const nonSelectedPrimaryColumns = this.expressionMap.queryEntity
|
|
1492
|
+
? metadata.primaryColumns.filter((primaryColumn) => columns.indexOf(primaryColumn) === -1)
|
|
1665
1493
|
: [];
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
allColumns.forEach(
|
|
1670
|
-
|
|
1494
|
+
const allColumns = [...columns, ...nonSelectedPrimaryColumns];
|
|
1495
|
+
const finalSelects = [];
|
|
1496
|
+
const escapedAliasName = this.escape(aliasName);
|
|
1497
|
+
allColumns.forEach((column) => {
|
|
1498
|
+
let selectionPath = escapedAliasName + "." + this.escape(column.databaseName);
|
|
1671
1499
|
if (column.isVirtualProperty && column.query) {
|
|
1672
|
-
selectionPath =
|
|
1500
|
+
selectionPath = `(${column.query(escapedAliasName)})`;
|
|
1673
1501
|
}
|
|
1674
|
-
if (
|
|
1502
|
+
if (this.connection.driver.spatialTypes.indexOf(column.type) !== -1) {
|
|
1675
1503
|
//#region @backend
|
|
1676
|
-
if (DriverUtils_1.DriverUtils.isMySQLFamily(
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
selectionPath =
|
|
1504
|
+
if (DriverUtils_1.DriverUtils.isMySQLFamily(this.connection.driver) ||
|
|
1505
|
+
this.connection.driver.options.type === "aurora-mysql") {
|
|
1506
|
+
const useLegacy = this.connection.driver.options.legacySpatialSupport;
|
|
1507
|
+
const asText = useLegacy ? "AsText" : "ST_AsText";
|
|
1508
|
+
selectionPath = `${asText}(${selectionPath})`;
|
|
1681
1509
|
}
|
|
1682
1510
|
//#endregion
|
|
1683
1511
|
//#region @backend
|
|
1684
|
-
if (DriverUtils_1.DriverUtils.isPostgresFamily(
|
|
1512
|
+
if (DriverUtils_1.DriverUtils.isPostgresFamily(this.connection.driver))
|
|
1685
1513
|
if (column.precision) {
|
|
1686
1514
|
// cast to JSON to trigger parsing in the driver
|
|
1687
|
-
selectionPath =
|
|
1515
|
+
selectionPath = `ST_AsGeoJSON(${selectionPath}, ${column.precision})::json`;
|
|
1688
1516
|
}
|
|
1689
1517
|
else {
|
|
1690
|
-
selectionPath =
|
|
1518
|
+
selectionPath = `ST_AsGeoJSON(${selectionPath})::json`;
|
|
1691
1519
|
}
|
|
1692
|
-
if (
|
|
1693
|
-
selectionPath =
|
|
1520
|
+
if (this.connection.driver.options.type === "mssql")
|
|
1521
|
+
selectionPath = `${selectionPath}.ToString()`;
|
|
1694
1522
|
//#endregion
|
|
1695
1523
|
}
|
|
1696
|
-
|
|
1697
|
-
return select.selection === aliasName + "." + column.propertyPath;
|
|
1698
|
-
});
|
|
1524
|
+
const selections = this.expressionMap.selects.filter((select) => select.selection === aliasName + "." + column.propertyPath);
|
|
1699
1525
|
if (selections.length) {
|
|
1700
|
-
selections.forEach(
|
|
1526
|
+
selections.forEach((selection) => {
|
|
1701
1527
|
finalSelects.push({
|
|
1702
1528
|
selection: selectionPath,
|
|
1703
1529
|
aliasName: selection.aliasName
|
|
1704
1530
|
? selection.aliasName
|
|
1705
|
-
: DriverUtils_1.DriverUtils.buildAlias(
|
|
1531
|
+
: DriverUtils_1.DriverUtils.buildAlias(this.connection.driver, aliasName, column.databaseName),
|
|
1706
1532
|
// todo: need to keep in mind that custom selection.aliasName breaks hydrator. fix it later!
|
|
1707
1533
|
virtual: selection.virtual,
|
|
1708
1534
|
});
|
|
@@ -1711,30 +1537,27 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
1711
1537
|
else {
|
|
1712
1538
|
finalSelects.push({
|
|
1713
1539
|
selection: selectionPath,
|
|
1714
|
-
aliasName: DriverUtils_1.DriverUtils.buildAlias(
|
|
1540
|
+
aliasName: DriverUtils_1.DriverUtils.buildAlias(this.connection.driver, aliasName, column.databaseName),
|
|
1715
1541
|
// todo: need to keep in mind that custom selection.aliasName breaks hydrator. fix it later!
|
|
1716
1542
|
virtual: hasMainAlias,
|
|
1717
1543
|
});
|
|
1718
1544
|
}
|
|
1719
1545
|
});
|
|
1720
1546
|
return finalSelects;
|
|
1721
|
-
}
|
|
1722
|
-
|
|
1723
|
-
|
|
1547
|
+
}
|
|
1548
|
+
findEntityColumnSelects(aliasName, metadata) {
|
|
1549
|
+
const mainSelect = this.expressionMap.selects.find((select) => select.selection === aliasName);
|
|
1724
1550
|
if (mainSelect)
|
|
1725
1551
|
return [mainSelect];
|
|
1726
|
-
return this.expressionMap.selects.filter(
|
|
1727
|
-
return metadata.columns.some(
|
|
1728
|
-
return select.selection === aliasName + "." + column.propertyPath;
|
|
1729
|
-
});
|
|
1552
|
+
return this.expressionMap.selects.filter((select) => {
|
|
1553
|
+
return metadata.columns.some((column) => select.selection === aliasName + "." + column.propertyPath);
|
|
1730
1554
|
});
|
|
1731
|
-
}
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
var distinctAlias = this.escape(mainAlias);
|
|
1555
|
+
}
|
|
1556
|
+
computeCountExpression() {
|
|
1557
|
+
const mainAlias = this.expressionMap.mainAlias.name; // todo: will this work with "fromTableName"?
|
|
1558
|
+
const metadata = this.expressionMap.mainAlias.metadata;
|
|
1559
|
+
const primaryColumns = metadata.primaryColumns;
|
|
1560
|
+
const distinctAlias = this.escape(mainAlias);
|
|
1738
1561
|
// If we aren't doing anything that will create a join, we can use a simpler `COUNT` instead
|
|
1739
1562
|
// so we prevent poor query patterns in the most likely cases
|
|
1740
1563
|
if (this.expressionMap.joinAttributes.length === 0 &&
|
|
@@ -1749,9 +1572,7 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
1749
1572
|
// https://www.postgresql.org/docs/9.5/sql-select.html#SQL-DISTINCT
|
|
1750
1573
|
return ("COUNT(DISTINCT(" +
|
|
1751
1574
|
primaryColumns
|
|
1752
|
-
.map(
|
|
1753
|
-
return "".concat(distinctAlias, ".").concat(_this.escape(c.databaseName));
|
|
1754
|
-
})
|
|
1575
|
+
.map((c) => `${distinctAlias}.${this.escape(c.databaseName)}`)
|
|
1755
1576
|
.join(", ") +
|
|
1756
1577
|
"))");
|
|
1757
1578
|
}
|
|
@@ -1760,9 +1581,7 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
1760
1581
|
// https://mariadb.com/kb/en/count-distinct/
|
|
1761
1582
|
return ("COUNT(DISTINCT " +
|
|
1762
1583
|
primaryColumns
|
|
1763
|
-
.map(
|
|
1764
|
-
return "".concat(distinctAlias, ".").concat(_this.escape(c.databaseName));
|
|
1765
|
-
})
|
|
1584
|
+
.map((c) => `${distinctAlias}.${this.escape(c.databaseName)}`)
|
|
1766
1585
|
.join(", ") +
|
|
1767
1586
|
")");
|
|
1768
1587
|
}
|
|
@@ -1771,70 +1590,55 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
1771
1590
|
// distinct counting multiple columns & they don't have the same operator
|
|
1772
1591
|
// characteristic for concatenating, so we gotta use the `CONCAT` function.
|
|
1773
1592
|
// However, If it's exactly 1 column we can omit the `CONCAT` for better performance.
|
|
1774
|
-
|
|
1775
|
-
.map(
|
|
1776
|
-
return "".concat(distinctAlias, ".").concat(_this.escape(primaryColumn.databaseName));
|
|
1777
|
-
})
|
|
1593
|
+
const columnsExpression = primaryColumns
|
|
1594
|
+
.map((primaryColumn) => `${distinctAlias}.${this.escape(primaryColumn.databaseName)}`)
|
|
1778
1595
|
.join(", '|;|', ");
|
|
1779
1596
|
if (primaryColumns.length === 1) {
|
|
1780
|
-
return
|
|
1597
|
+
return `COUNT(DISTINCT(${columnsExpression}))`;
|
|
1781
1598
|
}
|
|
1782
|
-
return
|
|
1599
|
+
return `COUNT(DISTINCT(CONCAT(${columnsExpression})))`;
|
|
1783
1600
|
}
|
|
1784
1601
|
if (this.connection.driver.options.type === "spanner") {
|
|
1785
1602
|
// spanner also has gotta be different from everyone else.
|
|
1786
1603
|
// they do not support concatenation of different column types without casting them to string
|
|
1787
1604
|
if (primaryColumns.length === 1) {
|
|
1788
|
-
return
|
|
1605
|
+
return `COUNT(DISTINCT(${distinctAlias}.${this.escape(primaryColumns[0].databaseName)}))`;
|
|
1789
1606
|
}
|
|
1790
|
-
|
|
1791
|
-
.map(
|
|
1792
|
-
return "CAST(".concat(distinctAlias, ".").concat(_this.escape(primaryColumn.databaseName), " AS STRING)");
|
|
1793
|
-
})
|
|
1607
|
+
const columnsExpression = primaryColumns
|
|
1608
|
+
.map((primaryColumn) => `CAST(${distinctAlias}.${this.escape(primaryColumn.databaseName)} AS STRING)`)
|
|
1794
1609
|
.join(", '|;|', ");
|
|
1795
|
-
return
|
|
1610
|
+
return `COUNT(DISTINCT(CONCAT(${columnsExpression})))`;
|
|
1796
1611
|
}
|
|
1797
1612
|
// If all else fails, fall back to a `COUNT` and `DISTINCT` across all the primary columns concatenated.
|
|
1798
1613
|
// Per the SQL spec, this is the canonical string concatenation mechanism which is most
|
|
1799
1614
|
// likely to work across servers implementing the SQL standard.
|
|
1800
1615
|
// Please note, if there is only one primary column that the concatenation does not occur in this
|
|
1801
1616
|
// query and the query is a standard `COUNT DISTINCT` in that case.
|
|
1802
|
-
return (
|
|
1617
|
+
return (`COUNT(DISTINCT(` +
|
|
1803
1618
|
primaryColumns
|
|
1804
|
-
.map(
|
|
1619
|
+
.map((c) => `${distinctAlias}.${this.escape(c.databaseName)}`)
|
|
1805
1620
|
.join(" || '|;|' || ") +
|
|
1806
1621
|
"))");
|
|
1807
|
-
}
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
case 1:
|
|
1826
|
-
results = _a.sent();
|
|
1827
|
-
if (!results || !results[0] || !results[0]["cnt"])
|
|
1828
|
-
return [2 /*return*/, 0];
|
|
1829
|
-
return [2 /*return*/, parseInt(results[0]["cnt"])];
|
|
1830
|
-
}
|
|
1831
|
-
});
|
|
1832
|
-
});
|
|
1833
|
-
};
|
|
1834
|
-
SelectQueryBuilder.prototype.applyFindOptions = function () {
|
|
1622
|
+
}
|
|
1623
|
+
async executeCountQuery(queryRunner) {
|
|
1624
|
+
const countSql = this.computeCountExpression();
|
|
1625
|
+
const results = await this.clone()
|
|
1626
|
+
.orderBy()
|
|
1627
|
+
.groupBy()
|
|
1628
|
+
.offset(undefined)
|
|
1629
|
+
.limit(undefined)
|
|
1630
|
+
.skip(undefined)
|
|
1631
|
+
.take(undefined)
|
|
1632
|
+
.select(countSql, "cnt")
|
|
1633
|
+
.setOption("disable-global-order")
|
|
1634
|
+
.loadRawResults(queryRunner);
|
|
1635
|
+
if (!results || !results[0] || !results[0]["cnt"])
|
|
1636
|
+
return 0;
|
|
1637
|
+
return parseInt(results[0]["cnt"]);
|
|
1638
|
+
}
|
|
1639
|
+
applyFindOptions() {
|
|
1835
1640
|
// todo: convert relations: string[] to object map to simplify code
|
|
1836
1641
|
// todo: same with selects
|
|
1837
|
-
var _this = this;
|
|
1838
1642
|
if (this.expressionMap.mainAlias.metadata) {
|
|
1839
1643
|
if (this.findOptions.relationLoadStrategy) {
|
|
1840
1644
|
this.expressionMap.relationLoadStrategy =
|
|
@@ -1847,7 +1651,7 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
1847
1651
|
this.withDeleted();
|
|
1848
1652
|
}
|
|
1849
1653
|
if (this.findOptions.select) {
|
|
1850
|
-
|
|
1654
|
+
const select = Array.isArray(this.findOptions.select)
|
|
1851
1655
|
? OrmUtils_1.OrmUtils.propertyPathsToTruthyObject(this.findOptions.select)
|
|
1852
1656
|
: this.findOptions.select;
|
|
1853
1657
|
this.buildSelect(select, this.expressionMap.mainAlias.metadata, this.expressionMap.mainAlias.name);
|
|
@@ -1857,7 +1661,7 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
1857
1661
|
}
|
|
1858
1662
|
this.selects = [];
|
|
1859
1663
|
if (this.findOptions.relations) {
|
|
1860
|
-
|
|
1664
|
+
const relations = Array.isArray(this.findOptions.relations)
|
|
1861
1665
|
? OrmUtils_1.OrmUtils.propertyPathsToTruthyObject(this.findOptions.relations)
|
|
1862
1666
|
: this.findOptions.relations;
|
|
1863
1667
|
this.buildRelations(relations, typeof this.findOptions.select === "object"
|
|
@@ -1886,25 +1690,25 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
1886
1690
|
}
|
|
1887
1691
|
// apply joins
|
|
1888
1692
|
if (this.joins.length) {
|
|
1889
|
-
this.joins.forEach(
|
|
1693
|
+
this.joins.forEach((join) => {
|
|
1890
1694
|
if (join.select && !join.selection) {
|
|
1891
1695
|
// if (join.selection) {
|
|
1892
1696
|
//
|
|
1893
1697
|
// } else {
|
|
1894
1698
|
if (join.type === "inner") {
|
|
1895
|
-
|
|
1699
|
+
this.innerJoinAndSelect(`${join.parentAlias}.${join.relationMetadata.propertyPath}`, join.alias);
|
|
1896
1700
|
}
|
|
1897
1701
|
else {
|
|
1898
|
-
|
|
1702
|
+
this.leftJoinAndSelect(`${join.parentAlias}.${join.relationMetadata.propertyPath}`, join.alias);
|
|
1899
1703
|
}
|
|
1900
1704
|
// }
|
|
1901
1705
|
}
|
|
1902
1706
|
else {
|
|
1903
1707
|
if (join.type === "inner") {
|
|
1904
|
-
|
|
1708
|
+
this.innerJoin(`${join.parentAlias}.${join.relationMetadata.propertyPath}`, join.alias);
|
|
1905
1709
|
}
|
|
1906
1710
|
else {
|
|
1907
|
-
|
|
1711
|
+
this.leftJoin(`${join.parentAlias}.${join.relationMetadata.propertyPath}`, join.alias);
|
|
1908
1712
|
}
|
|
1909
1713
|
}
|
|
1910
1714
|
// if (join.select) {
|
|
@@ -1949,20 +1753,20 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
1949
1753
|
}
|
|
1950
1754
|
if (this.findOptions.join) {
|
|
1951
1755
|
if (this.findOptions.join.leftJoin)
|
|
1952
|
-
Object.keys(this.findOptions.join.leftJoin).forEach(
|
|
1953
|
-
|
|
1756
|
+
Object.keys(this.findOptions.join.leftJoin).forEach((key) => {
|
|
1757
|
+
this.leftJoin(this.findOptions.join.leftJoin[key], key);
|
|
1954
1758
|
});
|
|
1955
1759
|
if (this.findOptions.join.innerJoin)
|
|
1956
|
-
Object.keys(this.findOptions.join.innerJoin).forEach(
|
|
1957
|
-
|
|
1760
|
+
Object.keys(this.findOptions.join.innerJoin).forEach((key) => {
|
|
1761
|
+
this.innerJoin(this.findOptions.join.innerJoin[key], key);
|
|
1958
1762
|
});
|
|
1959
1763
|
if (this.findOptions.join.leftJoinAndSelect)
|
|
1960
|
-
Object.keys(this.findOptions.join.leftJoinAndSelect).forEach(
|
|
1961
|
-
|
|
1764
|
+
Object.keys(this.findOptions.join.leftJoinAndSelect).forEach((key) => {
|
|
1765
|
+
this.leftJoinAndSelect(this.findOptions.join.leftJoinAndSelect[key], key);
|
|
1962
1766
|
});
|
|
1963
1767
|
if (this.findOptions.join.innerJoinAndSelect)
|
|
1964
|
-
Object.keys(this.findOptions.join.innerJoinAndSelect).forEach(
|
|
1965
|
-
|
|
1768
|
+
Object.keys(this.findOptions.join.innerJoinAndSelect).forEach((key) => {
|
|
1769
|
+
this.innerJoinAndSelect(this.findOptions.join.innerJoinAndSelect[key], key);
|
|
1966
1770
|
});
|
|
1967
1771
|
}
|
|
1968
1772
|
if (this.findOptions.lock) {
|
|
@@ -1978,16 +1782,16 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
1978
1782
|
"pessimistic_write_or_fail" ||
|
|
1979
1783
|
this.findOptions.lock.mode === "for_no_key_update" ||
|
|
1980
1784
|
this.findOptions.lock.mode === "for_key_share") {
|
|
1981
|
-
|
|
1982
|
-
? this.findOptions.lock.tables.map(
|
|
1983
|
-
|
|
1785
|
+
const tableNames = this.findOptions.lock.tables
|
|
1786
|
+
? this.findOptions.lock.tables.map((table) => {
|
|
1787
|
+
const tableAlias = this.expressionMap.aliases.find((alias) => {
|
|
1984
1788
|
return (alias.metadata
|
|
1985
1789
|
.tableNameWithoutPrefix === table);
|
|
1986
1790
|
});
|
|
1987
1791
|
if (!tableAlias) {
|
|
1988
|
-
throw new error_1.TypeORMError("
|
|
1792
|
+
throw new error_1.TypeORMError(`"${table}" is not part of this query`);
|
|
1989
1793
|
}
|
|
1990
|
-
return
|
|
1794
|
+
return this.escape(tableAlias.name);
|
|
1991
1795
|
})
|
|
1992
1796
|
: undefined;
|
|
1993
1797
|
this.setLock(this.findOptions.lock.mode, undefined, tableNames);
|
|
@@ -2022,236 +1826,207 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
2022
1826
|
// this.callListeners(false);
|
|
2023
1827
|
// }
|
|
2024
1828
|
}
|
|
2025
|
-
}
|
|
1829
|
+
}
|
|
2026
1830
|
/**
|
|
2027
1831
|
* Executes sql generated by query builder and returns object with raw results and entities created from them.
|
|
2028
1832
|
*/
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
1833
|
+
async executeEntitiesAndRawResults(queryRunner) {
|
|
1834
|
+
if (!this.expressionMap.mainAlias)
|
|
1835
|
+
throw new error_1.TypeORMError(`Alias is not set. Use "from" method to set an alias.`);
|
|
1836
|
+
if ((this.expressionMap.lockMode === "pessimistic_read" ||
|
|
1837
|
+
this.expressionMap.lockMode === "pessimistic_write" ||
|
|
1838
|
+
this.expressionMap.lockMode === "pessimistic_partial_write" ||
|
|
1839
|
+
this.expressionMap.lockMode === "pessimistic_write_or_fail" ||
|
|
1840
|
+
this.expressionMap.lockMode === "for_no_key_update" ||
|
|
1841
|
+
this.expressionMap.lockMode === "for_key_share") &&
|
|
1842
|
+
!queryRunner.isTransactionActive)
|
|
1843
|
+
throw new PessimisticLockTransactionRequiredError_1.PessimisticLockTransactionRequiredError();
|
|
1844
|
+
if (this.expressionMap.lockMode === "optimistic") {
|
|
1845
|
+
const metadata = this.expressionMap.mainAlias.metadata;
|
|
1846
|
+
if (!metadata.versionColumn && !metadata.updateDateColumn)
|
|
1847
|
+
throw new NoVersionOrUpdateDateColumnError_1.NoVersionOrUpdateDateColumnError(metadata.name);
|
|
1848
|
+
}
|
|
1849
|
+
const relationIdLoader = new RelationIdLoader_1.RelationIdLoader(this.connection, queryRunner, this.expressionMap.relationIdAttributes);
|
|
1850
|
+
const relationCountLoader = new RelationCountLoader_1.RelationCountLoader(this.connection, queryRunner, this.expressionMap.relationCountAttributes);
|
|
1851
|
+
const relationIdMetadataTransformer = new RelationIdMetadataToAttributeTransformer_1.RelationIdMetadataToAttributeTransformer(this.expressionMap);
|
|
1852
|
+
relationIdMetadataTransformer.transform();
|
|
1853
|
+
const relationCountMetadataTransformer = new RelationCountMetadataToAttributeTransformer_1.RelationCountMetadataToAttributeTransformer(this.expressionMap);
|
|
1854
|
+
relationCountMetadataTransformer.transform();
|
|
1855
|
+
let rawResults = [], entities = [];
|
|
1856
|
+
// for pagination enabled (e.g. skip and take) its much more complicated - its a special process
|
|
1857
|
+
// where we make two queries to find the data we need
|
|
1858
|
+
// first query find ids in skip and take range
|
|
1859
|
+
// and second query loads the actual data in given ids range
|
|
1860
|
+
if ((this.expressionMap.skip || this.expressionMap.take) &&
|
|
1861
|
+
this.expressionMap.joinAttributes.length > 0) {
|
|
1862
|
+
// we are skipping order by here because its not working in subqueries anyway
|
|
1863
|
+
// to make order by working we need to apply it on a distinct query
|
|
1864
|
+
const [selects, orderBys] = this.createOrderByCombinedWithSelectExpression("distinctAlias");
|
|
1865
|
+
const metadata = this.expressionMap.mainAlias.metadata;
|
|
1866
|
+
const mainAliasName = this.expressionMap.mainAlias.name;
|
|
1867
|
+
const querySelects = metadata.primaryColumns.map((primaryColumn) => {
|
|
1868
|
+
const distinctAlias = this.escape("distinctAlias");
|
|
1869
|
+
const columnAlias = this.escape(DriverUtils_1.DriverUtils.buildAlias(this.connection.driver, mainAliasName, primaryColumn.databaseName));
|
|
1870
|
+
if (!orderBys[columnAlias])
|
|
1871
|
+
// make sure we aren't overriding user-defined order in inverse direction
|
|
1872
|
+
orderBys[columnAlias] = "ASC";
|
|
1873
|
+
const alias = DriverUtils_1.DriverUtils.buildAlias(this.connection.driver, "ids_" + mainAliasName, primaryColumn.databaseName);
|
|
1874
|
+
return `${distinctAlias}.${columnAlias} AS ${this.escape(alias)}`;
|
|
1875
|
+
});
|
|
1876
|
+
rawResults = await new SelectQueryBuilder_1(this.connection, queryRunner)
|
|
1877
|
+
.select(`DISTINCT ${querySelects.join(", ")}`)
|
|
1878
|
+
.addSelect(selects)
|
|
1879
|
+
.from(`(${this.clone().orderBy().getQuery()})`, "distinctAlias")
|
|
1880
|
+
.offset(this.expressionMap.skip)
|
|
1881
|
+
.limit(this.expressionMap.take)
|
|
1882
|
+
.orderBy(orderBys)
|
|
1883
|
+
.cache(this.expressionMap.cache
|
|
1884
|
+
? this.expressionMap.cache
|
|
1885
|
+
: this.expressionMap.cacheId, this.expressionMap.cacheDuration)
|
|
1886
|
+
.setParameters(this.getParameters())
|
|
1887
|
+
.setNativeParameters(this.expressionMap.nativeParameters)
|
|
1888
|
+
.getRawMany();
|
|
1889
|
+
if (rawResults.length > 0) {
|
|
1890
|
+
let condition = "";
|
|
1891
|
+
const parameters = {};
|
|
1892
|
+
if (metadata.hasMultiplePrimaryKeys) {
|
|
1893
|
+
condition = rawResults
|
|
1894
|
+
.map((result, index) => {
|
|
1895
|
+
return metadata.primaryColumns
|
|
1896
|
+
.map((primaryColumn) => {
|
|
1897
|
+
const paramKey = `orm_distinct_ids_${index}_${primaryColumn.databaseName}`;
|
|
1898
|
+
parameters[paramKey] =
|
|
1899
|
+
result[`ids_${mainAliasName}_${primaryColumn.databaseName}`];
|
|
1900
|
+
return `${mainAliasName}.${primaryColumn.propertyPath}=:${paramKey}`;
|
|
1901
|
+
})
|
|
1902
|
+
.join(" AND ");
|
|
1903
|
+
})
|
|
1904
|
+
.join(" OR ");
|
|
1905
|
+
}
|
|
1906
|
+
else {
|
|
1907
|
+
const alias = DriverUtils_1.DriverUtils.buildAlias(this.connection.driver, "ids_" + mainAliasName, metadata.primaryColumns[0].databaseName);
|
|
1908
|
+
const ids = rawResults.map((result) => result[alias]);
|
|
1909
|
+
const areAllNumbers = ids.every((id) => typeof id === "number");
|
|
1910
|
+
if (areAllNumbers) {
|
|
1911
|
+
// fixes #190. if all numbers then its safe to perform query without parameter
|
|
1912
|
+
condition = `${mainAliasName}.${metadata.primaryColumns[0].propertyPath} IN (${ids.join(", ")})`;
|
|
1913
|
+
}
|
|
1914
|
+
else {
|
|
1915
|
+
parameters["orm_distinct_ids"] = ids;
|
|
1916
|
+
condition =
|
|
1917
|
+
mainAliasName +
|
|
1918
|
+
"." +
|
|
1919
|
+
metadata.primaryColumns[0].propertyPath +
|
|
1920
|
+
" IN (:...orm_distinct_ids)";
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
rawResults = await this.clone()
|
|
1924
|
+
.mergeExpressionMap({
|
|
1925
|
+
extraAppendedAndWhereCondition: condition,
|
|
1926
|
+
})
|
|
1927
|
+
.setParameters(parameters)
|
|
1928
|
+
.loadRawResults(queryRunner);
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
else {
|
|
1932
|
+
rawResults = await this.loadRawResults(queryRunner);
|
|
1933
|
+
}
|
|
1934
|
+
if (rawResults.length > 0) {
|
|
1935
|
+
// transform raw results into entities
|
|
1936
|
+
const rawRelationIdResults = await relationIdLoader.load(rawResults);
|
|
1937
|
+
const rawRelationCountResults = await relationCountLoader.load(rawResults);
|
|
1938
|
+
const transformer = new RawSqlResultsToEntityTransformer_1.RawSqlResultsToEntityTransformer(this.expressionMap, this.connection.driver, rawRelationIdResults, rawRelationCountResults, this.queryRunner);
|
|
1939
|
+
entities = transformer.transform(rawResults, this.expressionMap.mainAlias);
|
|
1940
|
+
// broadcast all "after load" events
|
|
1941
|
+
if (this.expressionMap.callListeners === true &&
|
|
1942
|
+
this.expressionMap.mainAlias.hasMetadata) {
|
|
1943
|
+
await queryRunner.broadcaster.broadcast("Load", this.expressionMap.mainAlias.metadata, entities);
|
|
1944
|
+
}
|
|
1945
|
+
}
|
|
1946
|
+
if (this.expressionMap.relationLoadStrategy === "query") {
|
|
1947
|
+
await Promise.all(this.relationMetadatas.map(async (relation) => {
|
|
1948
|
+
const relationTarget = relation.inverseEntityMetadata.target;
|
|
1949
|
+
const relationAlias = relation.inverseEntityMetadata.targetName;
|
|
1950
|
+
const select = Array.isArray(this.findOptions.select)
|
|
1951
|
+
? OrmUtils_1.OrmUtils.propertyPathsToTruthyObject(this.findOptions.select)
|
|
1952
|
+
: this.findOptions.select;
|
|
1953
|
+
const relations = Array.isArray(this.findOptions.relations)
|
|
1954
|
+
? OrmUtils_1.OrmUtils.propertyPathsToTruthyObject(this.findOptions.relations)
|
|
1955
|
+
: this.findOptions.relations;
|
|
1956
|
+
const queryBuilder = this.createQueryBuilder()
|
|
1957
|
+
.select(relationAlias)
|
|
1958
|
+
.from(relationTarget, relationAlias)
|
|
1959
|
+
.setFindOptions({
|
|
1960
|
+
select: select
|
|
1961
|
+
? OrmUtils_1.OrmUtils.deepValue(select, relation.propertyPath)
|
|
1962
|
+
: undefined,
|
|
1963
|
+
order: this.findOptions.order
|
|
1964
|
+
? OrmUtils_1.OrmUtils.deepValue(this.findOptions.order, relation.propertyPath)
|
|
1965
|
+
: undefined,
|
|
1966
|
+
relations: relations
|
|
1967
|
+
? OrmUtils_1.OrmUtils.deepValue(relations, relation.propertyPath)
|
|
1968
|
+
: undefined,
|
|
1969
|
+
withDeleted: this.findOptions.withDeleted,
|
|
1970
|
+
relationLoadStrategy: this.findOptions.relationLoadStrategy,
|
|
1971
|
+
});
|
|
1972
|
+
if (entities.length > 0) {
|
|
1973
|
+
const relatedEntityGroups = await this.connection.relationIdLoader.loadManyToManyRelationIdsAndGroup(relation, entities, undefined, queryBuilder);
|
|
1974
|
+
entities.forEach((entity) => {
|
|
1975
|
+
const relatedEntityGroup = relatedEntityGroups.find((group) => group.entity === entity);
|
|
1976
|
+
if (relatedEntityGroup) {
|
|
1977
|
+
const value = relatedEntityGroup.related === undefined
|
|
1978
|
+
? null
|
|
1979
|
+
: relatedEntityGroup.related;
|
|
1980
|
+
relation.setEntityValue(entity, value);
|
|
2120
1981
|
}
|
|
2121
|
-
|
|
2122
|
-
.mergeExpressionMap({
|
|
2123
|
-
extraAppendedAndWhereCondition: condition,
|
|
2124
|
-
})
|
|
2125
|
-
.setParameters(parameters_1)
|
|
2126
|
-
.loadRawResults(queryRunner)];
|
|
2127
|
-
case 2:
|
|
2128
|
-
rawResults = _b.sent();
|
|
2129
|
-
_b.label = 3;
|
|
2130
|
-
case 3: return [3 /*break*/, 6];
|
|
2131
|
-
case 4: return [4 /*yield*/, this.loadRawResults(queryRunner)];
|
|
2132
|
-
case 5:
|
|
2133
|
-
rawResults = _b.sent();
|
|
2134
|
-
_b.label = 6;
|
|
2135
|
-
case 6:
|
|
2136
|
-
if (!(rawResults.length > 0)) return [3 /*break*/, 10];
|
|
2137
|
-
return [4 /*yield*/, relationIdLoader.load(rawResults)];
|
|
2138
|
-
case 7:
|
|
2139
|
-
rawRelationIdResults = _b.sent();
|
|
2140
|
-
return [4 /*yield*/, relationCountLoader.load(rawResults)];
|
|
2141
|
-
case 8:
|
|
2142
|
-
rawRelationCountResults = _b.sent();
|
|
2143
|
-
transformer = new RawSqlResultsToEntityTransformer_1.RawSqlResultsToEntityTransformer(this.expressionMap, this.connection.driver, rawRelationIdResults, rawRelationCountResults, this.queryRunner);
|
|
2144
|
-
entities = transformer.transform(rawResults, this.expressionMap.mainAlias);
|
|
2145
|
-
if (!(this.expressionMap.callListeners === true &&
|
|
2146
|
-
this.expressionMap.mainAlias.hasMetadata)) return [3 /*break*/, 10];
|
|
2147
|
-
return [4 /*yield*/, queryRunner.broadcaster.broadcast("Load", this.expressionMap.mainAlias.metadata, entities)];
|
|
2148
|
-
case 9:
|
|
2149
|
-
_b.sent();
|
|
2150
|
-
_b.label = 10;
|
|
2151
|
-
case 10:
|
|
2152
|
-
if (!(this.expressionMap.relationLoadStrategy === "query")) return [3 /*break*/, 12];
|
|
2153
|
-
return [4 /*yield*/, Promise.all(this.relationMetadatas.map(function (relation) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
2154
|
-
var relationTarget, relationAlias, select, relations, queryBuilder, relatedEntityGroups_1;
|
|
2155
|
-
return tslib_1.__generator(this, function (_a) {
|
|
2156
|
-
switch (_a.label) {
|
|
2157
|
-
case 0:
|
|
2158
|
-
relationTarget = relation.inverseEntityMetadata.target;
|
|
2159
|
-
relationAlias = relation.inverseEntityMetadata.targetName;
|
|
2160
|
-
select = Array.isArray(this.findOptions.select)
|
|
2161
|
-
? OrmUtils_1.OrmUtils.propertyPathsToTruthyObject(this.findOptions.select)
|
|
2162
|
-
: this.findOptions.select;
|
|
2163
|
-
relations = Array.isArray(this.findOptions.relations)
|
|
2164
|
-
? OrmUtils_1.OrmUtils.propertyPathsToTruthyObject(this.findOptions.relations)
|
|
2165
|
-
: this.findOptions.relations;
|
|
2166
|
-
queryBuilder = this.createQueryBuilder()
|
|
2167
|
-
.select(relationAlias)
|
|
2168
|
-
.from(relationTarget, relationAlias)
|
|
2169
|
-
.setFindOptions({
|
|
2170
|
-
select: select
|
|
2171
|
-
? OrmUtils_1.OrmUtils.deepValue(select, relation.propertyPath)
|
|
2172
|
-
: undefined,
|
|
2173
|
-
order: this.findOptions.order
|
|
2174
|
-
? OrmUtils_1.OrmUtils.deepValue(this.findOptions.order, relation.propertyPath)
|
|
2175
|
-
: undefined,
|
|
2176
|
-
relations: relations
|
|
2177
|
-
? OrmUtils_1.OrmUtils.deepValue(relations, relation.propertyPath)
|
|
2178
|
-
: undefined,
|
|
2179
|
-
withDeleted: this.findOptions.withDeleted,
|
|
2180
|
-
relationLoadStrategy: this.findOptions.relationLoadStrategy,
|
|
2181
|
-
});
|
|
2182
|
-
if (!(entities.length > 0)) return [3 /*break*/, 2];
|
|
2183
|
-
return [4 /*yield*/, this.connection.relationIdLoader.loadManyToManyRelationIdsAndGroup(relation, entities, undefined, queryBuilder)];
|
|
2184
|
-
case 1:
|
|
2185
|
-
relatedEntityGroups_1 = _a.sent();
|
|
2186
|
-
entities.forEach(function (entity) {
|
|
2187
|
-
var relatedEntityGroup = relatedEntityGroups_1.find(function (group) { return group.entity === entity; });
|
|
2188
|
-
if (relatedEntityGroup) {
|
|
2189
|
-
var value = relatedEntityGroup.related === undefined
|
|
2190
|
-
? null
|
|
2191
|
-
: relatedEntityGroup.related;
|
|
2192
|
-
relation.setEntityValue(entity, value);
|
|
2193
|
-
}
|
|
2194
|
-
});
|
|
2195
|
-
_a.label = 2;
|
|
2196
|
-
case 2: return [2 /*return*/];
|
|
2197
|
-
}
|
|
2198
|
-
});
|
|
2199
|
-
}); }))];
|
|
2200
|
-
case 11:
|
|
2201
|
-
_b.sent();
|
|
2202
|
-
_b.label = 12;
|
|
2203
|
-
case 12: return [2 /*return*/, {
|
|
2204
|
-
raw: rawResults,
|
|
2205
|
-
entities: entities,
|
|
2206
|
-
}];
|
|
1982
|
+
});
|
|
2207
1983
|
}
|
|
2208
|
-
});
|
|
2209
|
-
}
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
1984
|
+
}));
|
|
1985
|
+
}
|
|
1986
|
+
return {
|
|
1987
|
+
raw: rawResults,
|
|
1988
|
+
entities: entities,
|
|
1989
|
+
};
|
|
1990
|
+
}
|
|
1991
|
+
createOrderByCombinedWithSelectExpression(parentAlias) {
|
|
2213
1992
|
// if table has a default order then apply it
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
.map(
|
|
1993
|
+
const orderBys = this.expressionMap.allOrderBys;
|
|
1994
|
+
const selectString = Object.keys(orderBys)
|
|
1995
|
+
.map((orderCriteria) => {
|
|
2217
1996
|
if (orderCriteria.indexOf(".") !== -1) {
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
return (
|
|
1997
|
+
const criteriaParts = orderCriteria.split(".");
|
|
1998
|
+
const aliasName = criteriaParts[0];
|
|
1999
|
+
const propertyPath = criteriaParts.slice(1).join(".");
|
|
2000
|
+
const alias = this.expressionMap.findAliasByName(aliasName);
|
|
2001
|
+
const column = alias.metadata.findColumnWithPropertyPath(propertyPath);
|
|
2002
|
+
return (this.escape(parentAlias) +
|
|
2224
2003
|
"." +
|
|
2225
|
-
|
|
2004
|
+
this.escape(DriverUtils_1.DriverUtils.buildAlias(this.connection.driver, aliasName, column.databaseName)));
|
|
2226
2005
|
}
|
|
2227
2006
|
else {
|
|
2228
|
-
if (
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
}))
|
|
2232
|
-
return _this.escape(parentAlias) + "." + orderCriteria;
|
|
2007
|
+
if (this.expressionMap.selects.find((select) => select.selection === orderCriteria ||
|
|
2008
|
+
select.aliasName === orderCriteria))
|
|
2009
|
+
return this.escape(parentAlias) + "." + orderCriteria;
|
|
2233
2010
|
return "";
|
|
2234
2011
|
}
|
|
2235
2012
|
})
|
|
2236
2013
|
.join(", ");
|
|
2237
|
-
|
|
2238
|
-
Object.keys(orderBys).forEach(
|
|
2014
|
+
const orderByObject = {};
|
|
2015
|
+
Object.keys(orderBys).forEach((orderCriteria) => {
|
|
2239
2016
|
if (orderCriteria.indexOf(".") !== -1) {
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
orderByObject[
|
|
2017
|
+
const criteriaParts = orderCriteria.split(".");
|
|
2018
|
+
const aliasName = criteriaParts[0];
|
|
2019
|
+
const propertyPath = criteriaParts.slice(1).join(".");
|
|
2020
|
+
const alias = this.expressionMap.findAliasByName(aliasName);
|
|
2021
|
+
const column = alias.metadata.findColumnWithPropertyPath(propertyPath);
|
|
2022
|
+
orderByObject[this.escape(parentAlias) +
|
|
2246
2023
|
"." +
|
|
2247
|
-
|
|
2024
|
+
this.escape(DriverUtils_1.DriverUtils.buildAlias(this.connection.driver, aliasName, column.databaseName))] = orderBys[orderCriteria];
|
|
2248
2025
|
}
|
|
2249
2026
|
else {
|
|
2250
|
-
if (
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
})) {
|
|
2254
|
-
orderByObject[_this.escape(parentAlias) + "." + orderCriteria] = orderBys[orderCriteria];
|
|
2027
|
+
if (this.expressionMap.selects.find((select) => select.selection === orderCriteria ||
|
|
2028
|
+
select.aliasName === orderCriteria)) {
|
|
2029
|
+
orderByObject[this.escape(parentAlias) + "." + orderCriteria] = orderBys[orderCriteria];
|
|
2255
2030
|
}
|
|
2256
2031
|
else {
|
|
2257
2032
|
orderByObject[orderCriteria] = orderBys[orderCriteria];
|
|
@@ -2259,111 +2034,93 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
2259
2034
|
}
|
|
2260
2035
|
});
|
|
2261
2036
|
return [selectString, orderByObject];
|
|
2262
|
-
}
|
|
2037
|
+
}
|
|
2263
2038
|
/**
|
|
2264
2039
|
* Loads raw results from the database.
|
|
2265
2040
|
*/
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
cacheOptions.duration ||
|
|
2289
|
-
1000,
|
|
2290
|
-
}, queryRunner)];
|
|
2291
|
-
case 2:
|
|
2292
|
-
savedQueryResultCacheOptions =
|
|
2293
|
-
_b.sent();
|
|
2294
|
-
if (savedQueryResultCacheOptions &&
|
|
2295
|
-
!this.connection.queryResultCache.isExpired(savedQueryResultCacheOptions)) {
|
|
2296
|
-
return [2 /*return*/, JSON.parse(savedQueryResultCacheOptions.result)];
|
|
2297
|
-
}
|
|
2298
|
-
return [3 /*break*/, 4];
|
|
2299
|
-
case 3:
|
|
2300
|
-
error_7 = _b.sent();
|
|
2301
|
-
if (!cacheOptions.ignoreErrors) {
|
|
2302
|
-
throw error_7;
|
|
2303
|
-
}
|
|
2304
|
-
cacheError = true;
|
|
2305
|
-
return [3 /*break*/, 4];
|
|
2306
|
-
case 4: return [4 /*yield*/, queryRunner.query(sql, parameters, true)];
|
|
2307
|
-
case 5:
|
|
2308
|
-
results = _b.sent();
|
|
2309
|
-
if (!(!cacheError &&
|
|
2310
|
-
this.connection.queryResultCache &&
|
|
2311
|
-
(this.expressionMap.cache || cacheOptions.alwaysEnabled))) return [3 /*break*/, 9];
|
|
2312
|
-
_b.label = 6;
|
|
2313
|
-
case 6:
|
|
2314
|
-
_b.trys.push([6, 8, , 9]);
|
|
2315
|
-
return [4 /*yield*/, this.connection.queryResultCache.storeInCache({
|
|
2316
|
-
identifier: this.expressionMap.cacheId,
|
|
2317
|
-
query: queryId,
|
|
2318
|
-
time: new Date().getTime(),
|
|
2319
|
-
duration: this.expressionMap.cacheDuration ||
|
|
2320
|
-
cacheOptions.duration ||
|
|
2321
|
-
1000,
|
|
2322
|
-
result: JSON.stringify(results.records),
|
|
2323
|
-
}, savedQueryResultCacheOptions, queryRunner)];
|
|
2324
|
-
case 7:
|
|
2325
|
-
_b.sent();
|
|
2326
|
-
return [3 /*break*/, 9];
|
|
2327
|
-
case 8:
|
|
2328
|
-
error_8 = _b.sent();
|
|
2329
|
-
if (!cacheOptions.ignoreErrors) {
|
|
2330
|
-
throw error_8;
|
|
2331
|
-
}
|
|
2332
|
-
return [3 /*break*/, 9];
|
|
2333
|
-
case 9: return [2 /*return*/, results.records];
|
|
2041
|
+
async loadRawResults(queryRunner) {
|
|
2042
|
+
const [sql, parameters] = this.getQueryAndParameters();
|
|
2043
|
+
const queryId = sql + " -- PARAMETERS: " + JSON.stringify(parameters);
|
|
2044
|
+
const cacheOptions = typeof this.connection.options.cache === "object"
|
|
2045
|
+
? this.connection.options.cache
|
|
2046
|
+
: {};
|
|
2047
|
+
let savedQueryResultCacheOptions = undefined;
|
|
2048
|
+
let cacheError = false;
|
|
2049
|
+
if (this.connection.queryResultCache &&
|
|
2050
|
+
(this.expressionMap.cache || cacheOptions.alwaysEnabled)) {
|
|
2051
|
+
try {
|
|
2052
|
+
savedQueryResultCacheOptions =
|
|
2053
|
+
await this.connection.queryResultCache.getFromCache({
|
|
2054
|
+
identifier: this.expressionMap.cacheId,
|
|
2055
|
+
query: queryId,
|
|
2056
|
+
duration: this.expressionMap.cacheDuration ||
|
|
2057
|
+
cacheOptions.duration ||
|
|
2058
|
+
1000,
|
|
2059
|
+
}, queryRunner);
|
|
2060
|
+
if (savedQueryResultCacheOptions &&
|
|
2061
|
+
!this.connection.queryResultCache.isExpired(savedQueryResultCacheOptions)) {
|
|
2062
|
+
return JSON.parse(savedQueryResultCacheOptions.result);
|
|
2334
2063
|
}
|
|
2335
|
-
}
|
|
2336
|
-
|
|
2337
|
-
|
|
2064
|
+
}
|
|
2065
|
+
catch (error) {
|
|
2066
|
+
if (!cacheOptions.ignoreErrors) {
|
|
2067
|
+
throw error;
|
|
2068
|
+
}
|
|
2069
|
+
cacheError = true;
|
|
2070
|
+
}
|
|
2071
|
+
}
|
|
2072
|
+
const results = await queryRunner.query(sql, parameters, true);
|
|
2073
|
+
if (!cacheError &&
|
|
2074
|
+
this.connection.queryResultCache &&
|
|
2075
|
+
(this.expressionMap.cache || cacheOptions.alwaysEnabled)) {
|
|
2076
|
+
try {
|
|
2077
|
+
await this.connection.queryResultCache.storeInCache({
|
|
2078
|
+
identifier: this.expressionMap.cacheId,
|
|
2079
|
+
query: queryId,
|
|
2080
|
+
time: new Date().getTime(),
|
|
2081
|
+
duration: this.expressionMap.cacheDuration ||
|
|
2082
|
+
cacheOptions.duration ||
|
|
2083
|
+
1000,
|
|
2084
|
+
result: JSON.stringify(results.records),
|
|
2085
|
+
}, savedQueryResultCacheOptions, queryRunner);
|
|
2086
|
+
}
|
|
2087
|
+
catch (error) {
|
|
2088
|
+
if (!cacheOptions.ignoreErrors) {
|
|
2089
|
+
throw error;
|
|
2090
|
+
}
|
|
2091
|
+
}
|
|
2092
|
+
}
|
|
2093
|
+
return results.records;
|
|
2094
|
+
}
|
|
2338
2095
|
/**
|
|
2339
2096
|
* Merges into expression map given expression map properties.
|
|
2340
2097
|
*/
|
|
2341
|
-
|
|
2098
|
+
mergeExpressionMap(expressionMap) {
|
|
2342
2099
|
ObjectUtils_1.ObjectUtils.assign(this.expressionMap, expressionMap);
|
|
2343
2100
|
return this;
|
|
2344
|
-
}
|
|
2101
|
+
}
|
|
2345
2102
|
/**
|
|
2346
2103
|
* Normalizes a give number - converts to int if possible.
|
|
2347
2104
|
*/
|
|
2348
|
-
|
|
2105
|
+
normalizeNumber(num) {
|
|
2349
2106
|
if (typeof num === "number" || num === undefined || num === null)
|
|
2350
2107
|
return num;
|
|
2351
2108
|
return Number(num);
|
|
2352
|
-
}
|
|
2109
|
+
}
|
|
2353
2110
|
/**
|
|
2354
2111
|
* Creates a query builder used to execute sql queries inside this query builder.
|
|
2355
2112
|
*/
|
|
2356
|
-
|
|
2113
|
+
obtainQueryRunner() {
|
|
2357
2114
|
return this.queryRunner || this.connection.createQueryRunner("slave");
|
|
2358
|
-
}
|
|
2359
|
-
|
|
2360
|
-
for (
|
|
2115
|
+
}
|
|
2116
|
+
buildSelect(select, metadata, alias, embedPrefix) {
|
|
2117
|
+
for (let key in select) {
|
|
2361
2118
|
if (select[key] === undefined || select[key] === false)
|
|
2362
2119
|
continue;
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2120
|
+
const propertyPath = embedPrefix ? embedPrefix + "." + key : key;
|
|
2121
|
+
const column = metadata.findColumnWithPropertyPathStrict(propertyPath);
|
|
2122
|
+
const embed = metadata.findEmbeddedWithPropertyPath(propertyPath);
|
|
2123
|
+
const relation = metadata.findRelationWithPropertyPath(propertyPath);
|
|
2367
2124
|
if (!embed && !column && !relation)
|
|
2368
2125
|
throw new EntityPropertyNotFoundError_1.EntityPropertyNotFoundError(propertyPath, metadata);
|
|
2369
2126
|
if (column) {
|
|
@@ -2388,36 +2145,35 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
2388
2145
|
// this.buildOrder(select[key] as FindOptionsOrder<any>, relation.inverseEntityMetadata, joinAlias);
|
|
2389
2146
|
}
|
|
2390
2147
|
}
|
|
2391
|
-
}
|
|
2392
|
-
|
|
2393
|
-
var _this = this;
|
|
2148
|
+
}
|
|
2149
|
+
buildRelations(relations, selection, metadata, alias, embedPrefix) {
|
|
2394
2150
|
if (!relations)
|
|
2395
2151
|
return;
|
|
2396
|
-
Object.keys(relations).forEach(
|
|
2397
|
-
|
|
2398
|
-
|
|
2152
|
+
Object.keys(relations).forEach((relationName) => {
|
|
2153
|
+
const relationValue = relations[relationName];
|
|
2154
|
+
const propertyPath = embedPrefix
|
|
2399
2155
|
? embedPrefix + "." + relationName
|
|
2400
2156
|
: relationName;
|
|
2401
|
-
|
|
2402
|
-
|
|
2157
|
+
const embed = metadata.findEmbeddedWithPropertyPath(propertyPath);
|
|
2158
|
+
const relation = metadata.findRelationWithPropertyPath(propertyPath);
|
|
2403
2159
|
if (!embed && !relation)
|
|
2404
2160
|
throw new EntityPropertyNotFoundError_1.EntityPropertyNotFoundError(propertyPath, metadata);
|
|
2405
2161
|
if (embed) {
|
|
2406
|
-
|
|
2162
|
+
this.buildRelations(relationValue, typeof selection === "object"
|
|
2407
2163
|
? OrmUtils_1.OrmUtils.deepValue(selection, embed.propertyPath)
|
|
2408
2164
|
: undefined, metadata, alias, propertyPath);
|
|
2409
2165
|
}
|
|
2410
2166
|
else if (relation) {
|
|
2411
|
-
|
|
2412
|
-
joinAlias = DriverUtils_1.DriverUtils.buildAlias(
|
|
2167
|
+
let joinAlias = alias + "_" + propertyPath.replace(".", "_");
|
|
2168
|
+
joinAlias = DriverUtils_1.DriverUtils.buildAlias(this.connection.driver, { joiner: "__" }, alias, joinAlias);
|
|
2413
2169
|
if (relationValue === true ||
|
|
2414
2170
|
typeof relationValue === "object") {
|
|
2415
|
-
if (
|
|
2416
|
-
|
|
2171
|
+
if (this.expressionMap.relationLoadStrategy === "query") {
|
|
2172
|
+
this.relationMetadatas.push(relation);
|
|
2417
2173
|
}
|
|
2418
2174
|
else {
|
|
2419
2175
|
// join
|
|
2420
|
-
|
|
2176
|
+
this.joins.push({
|
|
2421
2177
|
type: "left",
|
|
2422
2178
|
select: true,
|
|
2423
2179
|
selection: selection &&
|
|
@@ -2430,86 +2186,85 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
2430
2186
|
});
|
|
2431
2187
|
if (selection &&
|
|
2432
2188
|
typeof selection[relationName] === "object") {
|
|
2433
|
-
|
|
2189
|
+
this.buildSelect(// @ts-ignore
|
|
2434
2190
|
selection[relationName], relation.inverseEntityMetadata, joinAlias);
|
|
2435
2191
|
}
|
|
2436
2192
|
}
|
|
2437
2193
|
}
|
|
2438
2194
|
if (typeof relationValue === "object" &&
|
|
2439
|
-
|
|
2440
|
-
|
|
2195
|
+
this.expressionMap.relationLoadStrategy === "join") {
|
|
2196
|
+
this.buildRelations(relationValue, typeof selection === "object"
|
|
2441
2197
|
? OrmUtils_1.OrmUtils.deepValue(selection, relation.propertyPath)
|
|
2442
2198
|
: undefined, relation.inverseEntityMetadata, joinAlias, undefined);
|
|
2443
2199
|
}
|
|
2444
2200
|
}
|
|
2445
2201
|
});
|
|
2446
|
-
}
|
|
2447
|
-
|
|
2448
|
-
var _this = this;
|
|
2202
|
+
}
|
|
2203
|
+
buildEagerRelations(relations, selection, metadata, alias, embedPrefix) {
|
|
2449
2204
|
if (!relations)
|
|
2450
2205
|
return;
|
|
2451
|
-
Object.keys(relations).forEach(
|
|
2452
|
-
|
|
2453
|
-
|
|
2206
|
+
Object.keys(relations).forEach((relationName) => {
|
|
2207
|
+
const relationValue = relations[relationName];
|
|
2208
|
+
const propertyPath = embedPrefix
|
|
2454
2209
|
? embedPrefix + "." + relationName
|
|
2455
2210
|
: relationName;
|
|
2456
|
-
|
|
2457
|
-
|
|
2211
|
+
const embed = metadata.findEmbeddedWithPropertyPath(propertyPath);
|
|
2212
|
+
const relation = metadata.findRelationWithPropertyPath(propertyPath);
|
|
2458
2213
|
if (!embed && !relation)
|
|
2459
2214
|
throw new EntityPropertyNotFoundError_1.EntityPropertyNotFoundError(propertyPath, metadata);
|
|
2460
2215
|
if (embed) {
|
|
2461
|
-
|
|
2216
|
+
this.buildEagerRelations(relationValue, typeof selection === "object"
|
|
2462
2217
|
? OrmUtils_1.OrmUtils.deepValue(selection, embed.propertyPath)
|
|
2463
2218
|
: undefined, metadata, alias, propertyPath);
|
|
2464
2219
|
}
|
|
2465
2220
|
else if (relation) {
|
|
2466
|
-
|
|
2467
|
-
|
|
2221
|
+
let joinAlias = alias + "_" + propertyPath.replace(".", "_");
|
|
2222
|
+
joinAlias = DriverUtils_1.DriverUtils.buildAlias(this.connection.driver, { joiner: "__" }, alias, joinAlias);
|
|
2468
2223
|
if (relationValue === true ||
|
|
2469
2224
|
typeof relationValue === "object") {
|
|
2470
|
-
relation.inverseEntityMetadata.eagerRelations.forEach(
|
|
2471
|
-
|
|
2225
|
+
relation.inverseEntityMetadata.eagerRelations.forEach((eagerRelation) => {
|
|
2226
|
+
let eagerRelationJoinAlias = joinAlias +
|
|
2472
2227
|
"_" +
|
|
2473
2228
|
eagerRelation.propertyPath.replace(".", "_");
|
|
2474
|
-
eagerRelationJoinAlias = DriverUtils_1.DriverUtils.buildAlias(
|
|
2475
|
-
|
|
2229
|
+
eagerRelationJoinAlias = DriverUtils_1.DriverUtils.buildAlias(this.connection.driver, { joiner: "__" }, joinAlias, eagerRelationJoinAlias);
|
|
2230
|
+
const existJoin = this.joins.find((join) => join.alias === eagerRelationJoinAlias);
|
|
2476
2231
|
if (!existJoin) {
|
|
2477
|
-
|
|
2232
|
+
this.joins.push({
|
|
2478
2233
|
type: "left",
|
|
2479
2234
|
select: true,
|
|
2480
2235
|
alias: eagerRelationJoinAlias,
|
|
2481
|
-
parentAlias:
|
|
2236
|
+
parentAlias: joinAlias,
|
|
2482
2237
|
selection: undefined,
|
|
2483
2238
|
relationMetadata: eagerRelation,
|
|
2484
2239
|
});
|
|
2485
2240
|
}
|
|
2486
2241
|
if (selection &&
|
|
2487
2242
|
typeof selection[relationName] === "object") {
|
|
2488
|
-
|
|
2489
|
-
selection[relationName], relation.inverseEntityMetadata,
|
|
2243
|
+
this.buildSelect(// @ts-ignore
|
|
2244
|
+
selection[relationName], relation.inverseEntityMetadata, joinAlias);
|
|
2490
2245
|
}
|
|
2491
2246
|
});
|
|
2492
2247
|
}
|
|
2493
2248
|
if (typeof relationValue === "object") {
|
|
2494
|
-
|
|
2249
|
+
this.buildEagerRelations(relationValue, typeof selection === "object"
|
|
2495
2250
|
? OrmUtils_1.OrmUtils.deepValue(selection, relation.propertyPath)
|
|
2496
|
-
: undefined, relation.inverseEntityMetadata,
|
|
2251
|
+
: undefined, relation.inverseEntityMetadata, joinAlias, undefined);
|
|
2497
2252
|
}
|
|
2498
2253
|
}
|
|
2499
2254
|
});
|
|
2500
|
-
}
|
|
2501
|
-
|
|
2502
|
-
|
|
2255
|
+
}
|
|
2256
|
+
buildOrder(order, metadata, alias, embedPrefix) {
|
|
2257
|
+
for (let key in order) {
|
|
2503
2258
|
if (order[key] === undefined)
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2259
|
+
continue;
|
|
2260
|
+
const propertyPath = embedPrefix ? embedPrefix + "." + key : key;
|
|
2261
|
+
const column = metadata.findColumnWithPropertyPathStrict(propertyPath);
|
|
2262
|
+
const embed = metadata.findEmbeddedWithPropertyPath(propertyPath);
|
|
2263
|
+
const relation = metadata.findRelationWithPropertyPath(propertyPath);
|
|
2509
2264
|
if (!embed && !column && !relation)
|
|
2510
2265
|
throw new EntityPropertyNotFoundError_1.EntityPropertyNotFoundError(propertyPath, metadata);
|
|
2511
2266
|
if (column) {
|
|
2512
|
-
|
|
2267
|
+
let direction = typeof order[key] === "object"
|
|
2513
2268
|
? order[key].direction
|
|
2514
2269
|
: order[key];
|
|
2515
2270
|
direction =
|
|
@@ -2518,93 +2273,88 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
2518
2273
|
direction === -1
|
|
2519
2274
|
? "DESC"
|
|
2520
2275
|
: "ASC";
|
|
2521
|
-
|
|
2276
|
+
let nulls = typeof order[key] === "object"
|
|
2522
2277
|
? order[key].nulls
|
|
2523
2278
|
: undefined;
|
|
2524
2279
|
nulls =
|
|
2525
|
-
|
|
2280
|
+
nulls?.toLowerCase() === "first"
|
|
2526
2281
|
? "NULLS FIRST"
|
|
2527
|
-
:
|
|
2282
|
+
: nulls?.toLowerCase() === "last"
|
|
2528
2283
|
? "NULLS LAST"
|
|
2529
2284
|
: undefined;
|
|
2530
|
-
|
|
2285
|
+
let aliasPath = `${alias}.${propertyPath}`;
|
|
2531
2286
|
if (column.isVirtualProperty && column.query) {
|
|
2532
|
-
|
|
2287
|
+
const selection = this.expressionMap.selects.find((s) => s.selection === aliasPath);
|
|
2533
2288
|
if (selection) {
|
|
2534
2289
|
// this is not building correctly now???
|
|
2535
|
-
|
|
2536
|
-
selection.aliasName =
|
|
2290
|
+
aliasPath = DriverUtils_1.DriverUtils.buildAlias(this.connection.driver, alias, column.databaseName);
|
|
2291
|
+
selection.aliasName = aliasPath;
|
|
2537
2292
|
}
|
|
2538
2293
|
else {
|
|
2539
|
-
|
|
2294
|
+
aliasPath = `(${column.query(alias)})`;
|
|
2540
2295
|
}
|
|
2541
2296
|
}
|
|
2542
|
-
|
|
2297
|
+
this.addOrderBy(aliasPath, direction, nulls);
|
|
2543
2298
|
// this.orderBys.push({ alias: alias + "." + propertyPath, direction, nulls });
|
|
2544
2299
|
}
|
|
2545
2300
|
else if (embed) {
|
|
2546
|
-
|
|
2301
|
+
this.buildOrder(order[key], metadata, alias, propertyPath);
|
|
2547
2302
|
}
|
|
2548
2303
|
else if (relation) {
|
|
2549
|
-
|
|
2550
|
-
|
|
2304
|
+
let joinAlias = alias + "_" + propertyPath.replace(".", "_");
|
|
2305
|
+
joinAlias = DriverUtils_1.DriverUtils.buildAlias(this.connection.driver, { joiner: "__" }, alias, joinAlias);
|
|
2551
2306
|
// console.log("joinAlias", joinAlias, joinAlias.length, this.connection.driver.maxAliasLength)
|
|
2552
2307
|
// todo: use expressionMap.joinAttributes, and create a new one using
|
|
2553
2308
|
// const joinAttribute = new JoinAttribute(this.connection, this.expressionMap);
|
|
2554
|
-
|
|
2309
|
+
const existJoin = this.joins.find((join) => join.alias === joinAlias);
|
|
2555
2310
|
if (!existJoin) {
|
|
2556
|
-
|
|
2311
|
+
this.joins.push({
|
|
2557
2312
|
type: "left",
|
|
2558
2313
|
select: false,
|
|
2559
|
-
alias:
|
|
2314
|
+
alias: joinAlias,
|
|
2560
2315
|
parentAlias: alias,
|
|
2561
2316
|
selection: undefined,
|
|
2562
2317
|
relationMetadata: relation,
|
|
2563
2318
|
});
|
|
2564
2319
|
}
|
|
2565
|
-
|
|
2320
|
+
this.buildOrder(order[key], relation.inverseEntityMetadata, joinAlias);
|
|
2566
2321
|
}
|
|
2567
|
-
}
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
}
|
|
2572
|
-
};
|
|
2573
|
-
SelectQueryBuilder.prototype.buildWhere = function (where, metadata, alias, embedPrefix) {
|
|
2574
|
-
var _this = this;
|
|
2575
|
-
var condition = "";
|
|
2322
|
+
}
|
|
2323
|
+
}
|
|
2324
|
+
buildWhere(where, metadata, alias, embedPrefix) {
|
|
2325
|
+
let condition = "";
|
|
2576
2326
|
// let parameterIndex = Object.keys(this.expressionMap.nativeParameters).length;
|
|
2577
2327
|
if (Array.isArray(where)) {
|
|
2578
2328
|
condition =
|
|
2579
2329
|
"(" +
|
|
2580
2330
|
where
|
|
2581
|
-
.map(
|
|
2582
|
-
return
|
|
2331
|
+
.map((whereItem) => {
|
|
2332
|
+
return this.buildWhere(whereItem, metadata, alias, embedPrefix);
|
|
2583
2333
|
})
|
|
2584
|
-
.filter(
|
|
2585
|
-
.map(
|
|
2334
|
+
.filter((condition) => !!condition)
|
|
2335
|
+
.map((condition) => "(" + condition + ")")
|
|
2586
2336
|
.join(" OR ") +
|
|
2587
2337
|
")";
|
|
2588
2338
|
}
|
|
2589
2339
|
else {
|
|
2590
|
-
|
|
2591
|
-
|
|
2340
|
+
let andConditions = [];
|
|
2341
|
+
for (let key in where) {
|
|
2592
2342
|
if (where[key] === undefined || where[key] === null)
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2343
|
+
continue;
|
|
2344
|
+
const propertyPath = embedPrefix ? embedPrefix + "." + key : key;
|
|
2345
|
+
const column = metadata.findColumnWithPropertyPathStrict(propertyPath);
|
|
2346
|
+
const embed = metadata.findEmbeddedWithPropertyPath(propertyPath);
|
|
2347
|
+
const relation = metadata.findRelationWithPropertyPath(propertyPath);
|
|
2598
2348
|
if (!embed && !column && !relation)
|
|
2599
2349
|
throw new EntityPropertyNotFoundError_1.EntityPropertyNotFoundError(propertyPath, metadata);
|
|
2600
2350
|
if (column) {
|
|
2601
|
-
|
|
2351
|
+
let aliasPath = `${alias}.${propertyPath}`;
|
|
2602
2352
|
if (column.isVirtualProperty && column.query) {
|
|
2603
|
-
aliasPath =
|
|
2353
|
+
aliasPath = `(${column.query(alias)})`;
|
|
2604
2354
|
}
|
|
2605
2355
|
// const parameterName = alias + "_" + propertyPath.split(".").join("_") + "_" + parameterIndex;
|
|
2606
2356
|
// todo: we need to handle other operators as well?
|
|
2607
|
-
|
|
2357
|
+
let parameterValue = where[key];
|
|
2608
2358
|
if (InstanceChecker_1.InstanceChecker.isEqualOperator(where[key])) {
|
|
2609
2359
|
parameterValue = where[key].value;
|
|
2610
2360
|
}
|
|
@@ -2642,37 +2392,37 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
2642
2392
|
// const parameter = this.connection.driver.createParameter(parameterName, parameterIndex - 1);
|
|
2643
2393
|
// andConditions.push(`${aliasPath} = ${parameter}`);
|
|
2644
2394
|
// }
|
|
2645
|
-
andConditions.push(
|
|
2395
|
+
andConditions.push(this.createWhereConditionExpression(this.getWherePredicateCondition(aliasPath, parameterValue)));
|
|
2646
2396
|
// this.conditions.push(`${alias}.${propertyPath} = :${paramName}`);
|
|
2647
2397
|
// this.expressionMap.parameters[paramName] = where[key]; // todo: handle functions and other edge cases
|
|
2648
2398
|
}
|
|
2649
2399
|
else if (embed) {
|
|
2650
|
-
|
|
2651
|
-
if (
|
|
2652
|
-
andConditions.push(
|
|
2400
|
+
const condition = this.buildWhere(where[key], metadata, alias, propertyPath);
|
|
2401
|
+
if (condition)
|
|
2402
|
+
andConditions.push(condition);
|
|
2653
2403
|
}
|
|
2654
2404
|
else if (relation) {
|
|
2655
2405
|
// if all properties of where are undefined we don't need to join anything
|
|
2656
2406
|
// this can happen when user defines map with conditional queries inside
|
|
2657
2407
|
if (typeof where[key] === "object") {
|
|
2658
|
-
|
|
2408
|
+
const allAllUndefined = Object.keys(where[key]).every((k) => where[key][k] === undefined);
|
|
2659
2409
|
if (allAllUndefined) {
|
|
2660
|
-
|
|
2410
|
+
continue;
|
|
2661
2411
|
}
|
|
2662
2412
|
}
|
|
2663
2413
|
if (InstanceChecker_1.InstanceChecker.isFindOperator(where[key])) {
|
|
2664
2414
|
if (where[key].type === "moreThan" ||
|
|
2665
2415
|
where[key].type === "lessThan") {
|
|
2666
|
-
|
|
2416
|
+
const sqlOperator = where[key].type === "moreThan" ? ">" : "<";
|
|
2667
2417
|
// basically relation count functionality
|
|
2668
|
-
|
|
2418
|
+
const qb = this.subQuery();
|
|
2669
2419
|
if (relation.isManyToManyOwner) {
|
|
2670
2420
|
qb.select("COUNT(*)")
|
|
2671
2421
|
.from(relation.joinTableName, relation.joinTableName)
|
|
2672
2422
|
.where(relation.joinColumns
|
|
2673
|
-
.map(
|
|
2674
|
-
return
|
|
2675
|
-
.propertyName
|
|
2423
|
+
.map((column) => {
|
|
2424
|
+
return `${relation.joinTableName}.${column.propertyName} = ${alias}.${column.referencedColumn
|
|
2425
|
+
.propertyName}`;
|
|
2676
2426
|
})
|
|
2677
2427
|
.join(" AND "));
|
|
2678
2428
|
}
|
|
@@ -2680,10 +2430,10 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
2680
2430
|
qb.select("COUNT(*)")
|
|
2681
2431
|
.from(relation.inverseRelation.joinTableName, relation.inverseRelation.joinTableName)
|
|
2682
2432
|
.where(relation
|
|
2683
|
-
.inverseRelation.inverseJoinColumns.map(
|
|
2684
|
-
return
|
|
2685
|
-
.joinTableName
|
|
2686
|
-
.propertyName
|
|
2433
|
+
.inverseRelation.inverseJoinColumns.map((column) => {
|
|
2434
|
+
return `${relation.inverseRelation
|
|
2435
|
+
.joinTableName}.${column.propertyName} = ${alias}.${column.referencedColumn
|
|
2436
|
+
.propertyName}`;
|
|
2687
2437
|
})
|
|
2688
2438
|
.join(" AND "));
|
|
2689
2439
|
}
|
|
@@ -2692,21 +2442,21 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
2692
2442
|
.from(relation.inverseEntityMetadata.target, relation.inverseEntityMetadata
|
|
2693
2443
|
.tableName)
|
|
2694
2444
|
.where(relation
|
|
2695
|
-
.inverseRelation.joinColumns.map(
|
|
2696
|
-
return
|
|
2445
|
+
.inverseRelation.joinColumns.map((column) => {
|
|
2446
|
+
return `${relation
|
|
2697
2447
|
.inverseEntityMetadata
|
|
2698
|
-
.tableName
|
|
2699
|
-
.propertyName
|
|
2448
|
+
.tableName}.${column.propertyName} = ${alias}.${column.referencedColumn
|
|
2449
|
+
.propertyName}`;
|
|
2700
2450
|
})
|
|
2701
2451
|
.join(" AND "));
|
|
2702
2452
|
}
|
|
2703
2453
|
else {
|
|
2704
|
-
throw new Error(
|
|
2454
|
+
throw new Error(`This relation isn't supported by given find operator`);
|
|
2705
2455
|
}
|
|
2706
2456
|
// this
|
|
2707
2457
|
// .addSelect(qb.getSql(), relation.propertyAliasName + "_cnt")
|
|
2708
2458
|
// .andWhere(this.escape(relation.propertyAliasName + "_cnt") + " " + sqlOperator + " " + parseInt(where[key].value));
|
|
2709
|
-
|
|
2459
|
+
this.andWhere(qb.getSql() +
|
|
2710
2460
|
" " +
|
|
2711
2461
|
sqlOperator +
|
|
2712
2462
|
" " +
|
|
@@ -2716,27 +2466,27 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
2716
2466
|
if (relation.isManyToOne ||
|
|
2717
2467
|
(relation.isOneToOne &&
|
|
2718
2468
|
relation.isOneToOneOwner)) {
|
|
2719
|
-
|
|
2720
|
-
andConditions.push(
|
|
2469
|
+
const aliasPath = `${alias}.${propertyPath}`;
|
|
2470
|
+
andConditions.push(this.createWhereConditionExpression(this.getWherePredicateCondition(aliasPath, where[key])));
|
|
2721
2471
|
}
|
|
2722
2472
|
else {
|
|
2723
|
-
throw new Error(
|
|
2473
|
+
throw new Error(`This relation isn't supported by given find operator`);
|
|
2724
2474
|
}
|
|
2725
2475
|
}
|
|
2726
2476
|
}
|
|
2727
2477
|
else {
|
|
2728
2478
|
// const joinAlias = alias + "_" + relation.propertyName;
|
|
2729
|
-
|
|
2479
|
+
let joinAlias = alias +
|
|
2730
2480
|
"_" +
|
|
2731
2481
|
relation.propertyPath.replace(".", "_");
|
|
2732
|
-
|
|
2733
|
-
|
|
2482
|
+
joinAlias = DriverUtils_1.DriverUtils.buildAlias(this.connection.driver, { joiner: "__" }, alias, joinAlias);
|
|
2483
|
+
const existJoin = this.joins.find((join) => join.alias === joinAlias);
|
|
2734
2484
|
if (!existJoin) {
|
|
2735
|
-
|
|
2485
|
+
this.joins.push({
|
|
2736
2486
|
type: "inner",
|
|
2737
2487
|
select: false,
|
|
2738
2488
|
selection: undefined,
|
|
2739
|
-
alias:
|
|
2489
|
+
alias: joinAlias,
|
|
2740
2490
|
parentAlias: alias,
|
|
2741
2491
|
relationMetadata: relation,
|
|
2742
2492
|
});
|
|
@@ -2745,27 +2495,21 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
2745
2495
|
if (existJoin.type === "left")
|
|
2746
2496
|
existJoin.type = "inner";
|
|
2747
2497
|
}
|
|
2748
|
-
|
|
2749
|
-
if (
|
|
2750
|
-
andConditions.push(
|
|
2498
|
+
const condition = this.buildWhere(where[key], relation.inverseEntityMetadata, joinAlias);
|
|
2499
|
+
if (condition) {
|
|
2500
|
+
andConditions.push(condition);
|
|
2751
2501
|
// parameterIndex = Object.keys(this.expressionMap.nativeParameters).length;
|
|
2752
2502
|
}
|
|
2753
2503
|
}
|
|
2754
2504
|
}
|
|
2755
|
-
};
|
|
2756
|
-
var this_2 = this;
|
|
2757
|
-
for (var key in where) {
|
|
2758
|
-
_loop_2(key);
|
|
2759
2505
|
}
|
|
2760
2506
|
condition = andConditions.join(" AND ");
|
|
2761
2507
|
}
|
|
2762
2508
|
return condition;
|
|
2763
|
-
}
|
|
2764
|
-
|
|
2765
|
-
SelectQueryBuilder = SelectQueryBuilder_1 = tslib_1.__decorate([
|
|
2766
|
-
typescript_class_helpers_1.CLASS.NAME('SelectQueryBuilder')
|
|
2767
|
-
], SelectQueryBuilder);
|
|
2768
|
-
return SelectQueryBuilder;
|
|
2769
|
-
}(QueryBuilder_1.QueryBuilder));
|
|
2509
|
+
}
|
|
2510
|
+
};
|
|
2770
2511
|
exports.SelectQueryBuilder = SelectQueryBuilder;
|
|
2512
|
+
exports.SelectQueryBuilder = SelectQueryBuilder = SelectQueryBuilder_1 = __decorate([
|
|
2513
|
+
typescript_class_helpers_1.CLASS.NAME('SelectQueryBuilder')
|
|
2514
|
+
], SelectQueryBuilder);
|
|
2771
2515
|
//# sourceMappingURL=SelectQueryBuilder.js.map
|