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,33 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AbstractSqliteQueryRunner = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var InstanceChecker_1 = require("../../util/InstanceChecker");
|
|
4
|
+
const TransactionNotStartedError_1 = require("../../error/TransactionNotStartedError");
|
|
5
|
+
const TableColumn_1 = require("../../schema-builder/table/TableColumn");
|
|
6
|
+
const Table_1 = require("../../schema-builder/table/Table");
|
|
7
|
+
const TableIndex_1 = require("../../schema-builder/table/TableIndex");
|
|
8
|
+
const TableForeignKey_1 = require("../../schema-builder/table/TableForeignKey");
|
|
9
|
+
const View_1 = require("../../schema-builder/view/View");
|
|
10
|
+
const Query_1 = require("../Query");
|
|
11
|
+
const TableUnique_1 = require("../../schema-builder/table/TableUnique");
|
|
12
|
+
const BaseQueryRunner_1 = require("../../query-runner/BaseQueryRunner");
|
|
13
|
+
const OrmUtils_1 = require("../../util/OrmUtils");
|
|
14
|
+
const TableCheck_1 = require("../../schema-builder/table/TableCheck");
|
|
15
|
+
const error_1 = require("../../error");
|
|
16
|
+
const MetadataTableType_1 = require("../types/MetadataTableType");
|
|
17
|
+
const InstanceChecker_1 = require("../../util/InstanceChecker");
|
|
19
18
|
/**
|
|
20
19
|
* Runs queries on a single sqlite database connection.
|
|
21
20
|
*/
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
class AbstractSqliteQueryRunner extends BaseQueryRunner_1.BaseQueryRunner {
|
|
22
|
+
// -------------------------------------------------------------------------
|
|
23
|
+
// Public Implemented Properties
|
|
24
|
+
// -------------------------------------------------------------------------
|
|
25
|
+
/**
|
|
26
|
+
* Database driver used by connection.
|
|
27
|
+
*/
|
|
28
|
+
driver;
|
|
29
|
+
transactionPromise = null;
|
|
24
30
|
// -------------------------------------------------------------------------
|
|
25
31
|
// Constructor
|
|
26
32
|
// -------------------------------------------------------------------------
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
_this.transactionPromise = null;
|
|
30
|
-
return _this;
|
|
33
|
+
constructor() {
|
|
34
|
+
super();
|
|
31
35
|
}
|
|
32
36
|
// -------------------------------------------------------------------------
|
|
33
37
|
// Public Methods
|
|
@@ -36,2030 +40,1211 @@ var AbstractSqliteQueryRunner = /** @class */ (function (_super) {
|
|
|
36
40
|
* Creates/uses database connection from the connection pool to perform further operations.
|
|
37
41
|
* Returns obtained database connection.
|
|
38
42
|
*/
|
|
39
|
-
|
|
43
|
+
connect() {
|
|
40
44
|
return Promise.resolve(this.driver.databaseConnection);
|
|
41
|
-
}
|
|
45
|
+
}
|
|
42
46
|
/**
|
|
43
47
|
* Releases used database connection.
|
|
44
48
|
* We just clear loaded tables and sql in memory, because sqlite do not support multiple connections thus query runners.
|
|
45
49
|
*/
|
|
46
|
-
|
|
50
|
+
release() {
|
|
47
51
|
this.loadedTables = [];
|
|
48
52
|
this.clearSqlMemory();
|
|
49
53
|
return Promise.resolve();
|
|
50
|
-
}
|
|
54
|
+
}
|
|
51
55
|
/**
|
|
52
56
|
* Starts transaction.
|
|
53
57
|
*/
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return [3 /*break*/, 4];
|
|
77
|
-
case 3:
|
|
78
|
-
err_1 = _a.sent();
|
|
79
|
-
this.isTransactionActive = false;
|
|
80
|
-
throw err_1;
|
|
81
|
-
case 4:
|
|
82
|
-
if (!(this.transactionDepth === 0)) return [3 /*break*/, 10];
|
|
83
|
-
if (!isolationLevel) return [3 /*break*/, 8];
|
|
84
|
-
if (!(isolationLevel === "READ UNCOMMITTED")) return [3 /*break*/, 6];
|
|
85
|
-
return [4 /*yield*/, this.query("PRAGMA read_uncommitted = true")];
|
|
86
|
-
case 5:
|
|
87
|
-
_a.sent();
|
|
88
|
-
return [3 /*break*/, 8];
|
|
89
|
-
case 6: return [4 /*yield*/, this.query("PRAGMA read_uncommitted = false")];
|
|
90
|
-
case 7:
|
|
91
|
-
_a.sent();
|
|
92
|
-
_a.label = 8;
|
|
93
|
-
case 8: return [4 /*yield*/, this.query("BEGIN TRANSACTION")];
|
|
94
|
-
case 9:
|
|
95
|
-
_a.sent();
|
|
96
|
-
return [3 /*break*/, 12];
|
|
97
|
-
case 10: return [4 /*yield*/, this.query("SAVEPOINT typeorm_".concat(this.transactionDepth))];
|
|
98
|
-
case 11:
|
|
99
|
-
_a.sent();
|
|
100
|
-
_a.label = 12;
|
|
101
|
-
case 12:
|
|
102
|
-
this.transactionDepth += 1;
|
|
103
|
-
return [4 /*yield*/, this.broadcaster.broadcast("AfterTransactionStart")];
|
|
104
|
-
case 13:
|
|
105
|
-
_a.sent();
|
|
106
|
-
return [2 /*return*/];
|
|
58
|
+
async startTransaction(isolationLevel) {
|
|
59
|
+
if (this.driver.transactionSupport === "none")
|
|
60
|
+
throw new error_1.TypeORMError(`Transactions aren't supported by ${this.connection.driver.options.type}.`);
|
|
61
|
+
if (this.isTransactionActive &&
|
|
62
|
+
this.driver.transactionSupport === "simple")
|
|
63
|
+
throw new error_1.TransactionAlreadyStartedError();
|
|
64
|
+
if (isolationLevel &&
|
|
65
|
+
isolationLevel !== "READ UNCOMMITTED" &&
|
|
66
|
+
isolationLevel !== "SERIALIZABLE")
|
|
67
|
+
throw new error_1.TypeORMError(`SQLite only supports SERIALIZABLE and READ UNCOMMITTED isolation`);
|
|
68
|
+
this.isTransactionActive = true;
|
|
69
|
+
try {
|
|
70
|
+
await this.broadcaster.broadcast("BeforeTransactionStart");
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
this.isTransactionActive = false;
|
|
74
|
+
throw err;
|
|
75
|
+
}
|
|
76
|
+
if (this.transactionDepth === 0) {
|
|
77
|
+
if (isolationLevel) {
|
|
78
|
+
if (isolationLevel === "READ UNCOMMITTED") {
|
|
79
|
+
await this.query("PRAGMA read_uncommitted = true");
|
|
107
80
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
81
|
+
else {
|
|
82
|
+
await this.query("PRAGMA read_uncommitted = false");
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
await this.query("BEGIN TRANSACTION");
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
await this.query(`SAVEPOINT typeorm_${this.transactionDepth}`);
|
|
89
|
+
}
|
|
90
|
+
this.transactionDepth += 1;
|
|
91
|
+
await this.broadcaster.broadcast("AfterTransactionStart");
|
|
92
|
+
}
|
|
111
93
|
/**
|
|
112
94
|
* Commits transaction.
|
|
113
95
|
* Error will be thrown if transaction was not started.
|
|
114
96
|
*/
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
return [3 /*break*/, 5];
|
|
130
|
-
case 3: return [4 /*yield*/, this.query("COMMIT")];
|
|
131
|
-
case 4:
|
|
132
|
-
_a.sent();
|
|
133
|
-
this.isTransactionActive = false;
|
|
134
|
-
_a.label = 5;
|
|
135
|
-
case 5:
|
|
136
|
-
this.transactionDepth -= 1;
|
|
137
|
-
return [4 /*yield*/, this.broadcaster.broadcast("AfterTransactionCommit")];
|
|
138
|
-
case 6:
|
|
139
|
-
_a.sent();
|
|
140
|
-
return [2 /*return*/];
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
};
|
|
97
|
+
async commitTransaction() {
|
|
98
|
+
if (!this.isTransactionActive)
|
|
99
|
+
throw new TransactionNotStartedError_1.TransactionNotStartedError();
|
|
100
|
+
await this.broadcaster.broadcast("BeforeTransactionCommit");
|
|
101
|
+
if (this.transactionDepth > 1) {
|
|
102
|
+
await this.query(`RELEASE SAVEPOINT typeorm_${this.transactionDepth - 1}`);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
await this.query("COMMIT");
|
|
106
|
+
this.isTransactionActive = false;
|
|
107
|
+
}
|
|
108
|
+
this.transactionDepth -= 1;
|
|
109
|
+
await this.broadcaster.broadcast("AfterTransactionCommit");
|
|
110
|
+
}
|
|
145
111
|
/**
|
|
146
112
|
* Rollbacks transaction.
|
|
147
113
|
* Error will be thrown if transaction was not started.
|
|
148
114
|
*/
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
return [3 /*break*/, 5];
|
|
164
|
-
case 3: return [4 /*yield*/, this.query("ROLLBACK")];
|
|
165
|
-
case 4:
|
|
166
|
-
_a.sent();
|
|
167
|
-
this.isTransactionActive = false;
|
|
168
|
-
_a.label = 5;
|
|
169
|
-
case 5:
|
|
170
|
-
this.transactionDepth -= 1;
|
|
171
|
-
return [4 /*yield*/, this.broadcaster.broadcast("AfterTransactionRollback")];
|
|
172
|
-
case 6:
|
|
173
|
-
_a.sent();
|
|
174
|
-
return [2 /*return*/];
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
};
|
|
115
|
+
async rollbackTransaction() {
|
|
116
|
+
if (!this.isTransactionActive)
|
|
117
|
+
throw new TransactionNotStartedError_1.TransactionNotStartedError();
|
|
118
|
+
await this.broadcaster.broadcast("BeforeTransactionRollback");
|
|
119
|
+
if (this.transactionDepth > 1) {
|
|
120
|
+
await this.query(`ROLLBACK TO SAVEPOINT typeorm_${this.transactionDepth - 1}`);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
await this.query("ROLLBACK");
|
|
124
|
+
this.isTransactionActive = false;
|
|
125
|
+
}
|
|
126
|
+
this.transactionDepth -= 1;
|
|
127
|
+
await this.broadcaster.broadcast("AfterTransactionRollback");
|
|
128
|
+
}
|
|
179
129
|
/**
|
|
180
130
|
* Returns raw data stream.
|
|
181
131
|
*/
|
|
182
|
-
|
|
183
|
-
throw new error_1.TypeORMError(
|
|
184
|
-
}
|
|
132
|
+
stream(query, parameters, onEnd, onError) {
|
|
133
|
+
throw new error_1.TypeORMError(`Stream is not supported by sqlite driver.`);
|
|
134
|
+
}
|
|
185
135
|
/**
|
|
186
136
|
* Returns all available database names including system databases.
|
|
187
137
|
*/
|
|
188
|
-
|
|
189
|
-
return
|
|
190
|
-
|
|
191
|
-
return [2 /*return*/, Promise.resolve([])];
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
};
|
|
138
|
+
async getDatabases() {
|
|
139
|
+
return Promise.resolve([]);
|
|
140
|
+
}
|
|
195
141
|
/**
|
|
196
142
|
* Returns all available schema names including system schemas.
|
|
197
143
|
* If database parameter specified, returns schemas of that database.
|
|
198
144
|
*/
|
|
199
|
-
|
|
200
|
-
return
|
|
201
|
-
|
|
202
|
-
return [2 /*return*/, Promise.resolve([])];
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
};
|
|
145
|
+
async getSchemas(database) {
|
|
146
|
+
return Promise.resolve([]);
|
|
147
|
+
}
|
|
206
148
|
/**
|
|
207
149
|
* Checks if database with the given name exist.
|
|
208
150
|
*/
|
|
209
|
-
|
|
210
|
-
return
|
|
211
|
-
|
|
212
|
-
return [2 /*return*/, Promise.resolve(false)];
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
};
|
|
151
|
+
async hasDatabase(database) {
|
|
152
|
+
return Promise.resolve(false);
|
|
153
|
+
}
|
|
216
154
|
/**
|
|
217
155
|
* Loads currently using database
|
|
218
156
|
*/
|
|
219
|
-
|
|
220
|
-
return
|
|
221
|
-
|
|
222
|
-
return [2 /*return*/, Promise.resolve(undefined)];
|
|
223
|
-
});
|
|
224
|
-
});
|
|
225
|
-
};
|
|
157
|
+
async getCurrentDatabase() {
|
|
158
|
+
return Promise.resolve(undefined);
|
|
159
|
+
}
|
|
226
160
|
/**
|
|
227
161
|
* Checks if schema with the given name exist.
|
|
228
162
|
*/
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
throw new error_1.TypeORMError("This driver does not support table schemas");
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
};
|
|
163
|
+
async hasSchema(schema) {
|
|
164
|
+
throw new error_1.TypeORMError(`This driver does not support table schemas`);
|
|
165
|
+
}
|
|
236
166
|
/**
|
|
237
167
|
* Loads currently using database schema
|
|
238
168
|
*/
|
|
239
|
-
|
|
240
|
-
return
|
|
241
|
-
|
|
242
|
-
return [2 /*return*/, Promise.resolve(undefined)];
|
|
243
|
-
});
|
|
244
|
-
});
|
|
245
|
-
};
|
|
169
|
+
async getCurrentSchema() {
|
|
170
|
+
return Promise.resolve(undefined);
|
|
171
|
+
}
|
|
246
172
|
/**
|
|
247
173
|
* Checks if table with the given name exist in the database.
|
|
248
174
|
*/
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
: tableOrName;
|
|
258
|
-
sql = "SELECT * FROM \"sqlite_master\" WHERE \"type\" = 'table' AND \"name\" = '".concat(tableName, "'");
|
|
259
|
-
return [4 /*yield*/, this.query(sql)];
|
|
260
|
-
case 1:
|
|
261
|
-
result = _a.sent();
|
|
262
|
-
return [2 /*return*/, result.length ? true : false];
|
|
263
|
-
}
|
|
264
|
-
});
|
|
265
|
-
});
|
|
266
|
-
};
|
|
175
|
+
async hasTable(tableOrName) {
|
|
176
|
+
const tableName = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
177
|
+
? tableOrName.name
|
|
178
|
+
: tableOrName;
|
|
179
|
+
const sql = `SELECT * FROM "sqlite_master" WHERE "type" = 'table' AND "name" = '${tableName}'`;
|
|
180
|
+
const result = await this.query(sql);
|
|
181
|
+
return result.length ? true : false;
|
|
182
|
+
}
|
|
267
183
|
/**
|
|
268
184
|
* Checks if column with the given name exist in the given table.
|
|
269
185
|
*/
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
: tableOrName;
|
|
279
|
-
sql = "PRAGMA table_xinfo(".concat(this.escapePath(tableName), ")");
|
|
280
|
-
return [4 /*yield*/, this.query(sql)];
|
|
281
|
-
case 1:
|
|
282
|
-
columns = _a.sent();
|
|
283
|
-
return [2 /*return*/, !!columns.find(function (column) { return column["name"] === columnName; })];
|
|
284
|
-
}
|
|
285
|
-
});
|
|
286
|
-
});
|
|
287
|
-
};
|
|
186
|
+
async hasColumn(tableOrName, columnName) {
|
|
187
|
+
const tableName = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
188
|
+
? tableOrName.name
|
|
189
|
+
: tableOrName;
|
|
190
|
+
const sql = `PRAGMA table_xinfo(${this.escapePath(tableName)})`;
|
|
191
|
+
const columns = await this.query(sql);
|
|
192
|
+
return !!columns.find((column) => column["name"] === columnName);
|
|
193
|
+
}
|
|
288
194
|
/**
|
|
289
195
|
* Creates a new database.
|
|
290
196
|
*/
|
|
291
|
-
|
|
292
|
-
return
|
|
293
|
-
|
|
294
|
-
return [2 /*return*/, Promise.resolve()];
|
|
295
|
-
});
|
|
296
|
-
});
|
|
297
|
-
};
|
|
197
|
+
async createDatabase(database, ifNotExist) {
|
|
198
|
+
return Promise.resolve();
|
|
199
|
+
}
|
|
298
200
|
/**
|
|
299
201
|
* Drops database.
|
|
300
202
|
*/
|
|
301
|
-
|
|
302
|
-
return
|
|
303
|
-
|
|
304
|
-
return [2 /*return*/, Promise.resolve()];
|
|
305
|
-
});
|
|
306
|
-
});
|
|
307
|
-
};
|
|
203
|
+
async dropDatabase(database, ifExist) {
|
|
204
|
+
return Promise.resolve();
|
|
205
|
+
}
|
|
308
206
|
/**
|
|
309
207
|
* Creates a new table schema.
|
|
310
208
|
*/
|
|
311
|
-
|
|
312
|
-
return
|
|
313
|
-
|
|
314
|
-
return [2 /*return*/, Promise.resolve()];
|
|
315
|
-
});
|
|
316
|
-
});
|
|
317
|
-
};
|
|
209
|
+
async createSchema(schemaPath, ifNotExist) {
|
|
210
|
+
return Promise.resolve();
|
|
211
|
+
}
|
|
318
212
|
/**
|
|
319
213
|
* Drops table schema.
|
|
320
214
|
*/
|
|
321
|
-
|
|
322
|
-
return
|
|
323
|
-
|
|
324
|
-
return [2 /*return*/, Promise.resolve()];
|
|
325
|
-
});
|
|
326
|
-
});
|
|
327
|
-
};
|
|
215
|
+
async dropSchema(schemaPath, ifExist) {
|
|
216
|
+
return Promise.resolve();
|
|
217
|
+
}
|
|
328
218
|
/**
|
|
329
219
|
* Creates a new table.
|
|
330
220
|
*/
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
if (
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
if (isTableExist)
|
|
349
|
-
return [2 /*return*/, Promise.resolve()];
|
|
350
|
-
_b.label = 2;
|
|
351
|
-
case 2:
|
|
352
|
-
upQueries.push(this.createTableSql(table, createForeignKeys));
|
|
353
|
-
downQueries.push(this.dropTableSql(table));
|
|
354
|
-
if (createIndices) {
|
|
355
|
-
table.indices.forEach(function (index) {
|
|
356
|
-
// new index may be passed without name. In this case we generate index name manually.
|
|
357
|
-
if (!index.name)
|
|
358
|
-
index.name = _this.connection.namingStrategy.indexName(table, index.columnNames, index.where);
|
|
359
|
-
upQueries.push(_this.createIndexSql(table, index));
|
|
360
|
-
downQueries.push(_this.dropIndexSql(index));
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
generatedColumns = table.columns.filter(function (column) { return column.generatedType && column.asExpression; });
|
|
364
|
-
try {
|
|
365
|
-
for (generatedColumns_1 = tslib_1.__values(generatedColumns), generatedColumns_1_1 = generatedColumns_1.next(); !generatedColumns_1_1.done; generatedColumns_1_1 = generatedColumns_1.next()) {
|
|
366
|
-
column = generatedColumns_1_1.value;
|
|
367
|
-
insertQuery = this.insertTypeormMetadataSql({
|
|
368
|
-
table: table.name,
|
|
369
|
-
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
370
|
-
name: column.name,
|
|
371
|
-
value: column.asExpression,
|
|
372
|
-
});
|
|
373
|
-
deleteQuery = this.deleteTypeormMetadataSql({
|
|
374
|
-
table: table.name,
|
|
375
|
-
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
376
|
-
name: column.name,
|
|
377
|
-
});
|
|
378
|
-
upQueries.push(insertQuery);
|
|
379
|
-
downQueries.push(deleteQuery);
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
383
|
-
finally {
|
|
384
|
-
try {
|
|
385
|
-
if (generatedColumns_1_1 && !generatedColumns_1_1.done && (_a = generatedColumns_1.return)) _a.call(generatedColumns_1);
|
|
386
|
-
}
|
|
387
|
-
finally { if (e_1) throw e_1.error; }
|
|
388
|
-
}
|
|
389
|
-
return [4 /*yield*/, this.executeQueries(upQueries, downQueries)];
|
|
390
|
-
case 3:
|
|
391
|
-
_b.sent();
|
|
392
|
-
return [2 /*return*/];
|
|
393
|
-
}
|
|
221
|
+
async createTable(table, ifNotExist = false, createForeignKeys = true, createIndices = true) {
|
|
222
|
+
const upQueries = [];
|
|
223
|
+
const downQueries = [];
|
|
224
|
+
if (ifNotExist) {
|
|
225
|
+
const isTableExist = await this.hasTable(table);
|
|
226
|
+
if (isTableExist)
|
|
227
|
+
return Promise.resolve();
|
|
228
|
+
}
|
|
229
|
+
upQueries.push(this.createTableSql(table, createForeignKeys));
|
|
230
|
+
downQueries.push(this.dropTableSql(table));
|
|
231
|
+
if (createIndices) {
|
|
232
|
+
table.indices.forEach((index) => {
|
|
233
|
+
// new index may be passed without name. In this case we generate index name manually.
|
|
234
|
+
if (!index.name)
|
|
235
|
+
index.name = this.connection.namingStrategy.indexName(table, index.columnNames, index.where);
|
|
236
|
+
upQueries.push(this.createIndexSql(table, index));
|
|
237
|
+
downQueries.push(this.dropIndexSql(index));
|
|
394
238
|
});
|
|
395
|
-
}
|
|
396
|
-
|
|
239
|
+
}
|
|
240
|
+
// if table have column with generated type, we must add the expression to the metadata table
|
|
241
|
+
const generatedColumns = table.columns.filter((column) => column.generatedType && column.asExpression);
|
|
242
|
+
for (const column of generatedColumns) {
|
|
243
|
+
const insertQuery = this.insertTypeormMetadataSql({
|
|
244
|
+
table: table.name,
|
|
245
|
+
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
246
|
+
name: column.name,
|
|
247
|
+
value: column.asExpression,
|
|
248
|
+
});
|
|
249
|
+
const deleteQuery = this.deleteTypeormMetadataSql({
|
|
250
|
+
table: table.name,
|
|
251
|
+
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
252
|
+
name: column.name,
|
|
253
|
+
});
|
|
254
|
+
upQueries.push(insertQuery);
|
|
255
|
+
downQueries.push(deleteQuery);
|
|
256
|
+
}
|
|
257
|
+
await this.executeQueries(upQueries, downQueries);
|
|
258
|
+
}
|
|
397
259
|
/**
|
|
398
260
|
* Drops the table.
|
|
399
261
|
*/
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
case 2:
|
|
418
|
-
createForeignKeys = dropForeignKeys;
|
|
419
|
-
if (!InstanceChecker_1.InstanceChecker.isTable(tableOrName)) return [3 /*break*/, 3];
|
|
420
|
-
_a = tableOrName;
|
|
421
|
-
return [3 /*break*/, 5];
|
|
422
|
-
case 3: return [4 /*yield*/, this.getCachedTable(tableOrName)];
|
|
423
|
-
case 4:
|
|
424
|
-
_a = _c.sent();
|
|
425
|
-
_c.label = 5;
|
|
426
|
-
case 5:
|
|
427
|
-
table = _a;
|
|
428
|
-
upQueries = [];
|
|
429
|
-
downQueries = [];
|
|
430
|
-
if (dropIndices) {
|
|
431
|
-
table.indices.forEach(function (index) {
|
|
432
|
-
upQueries.push(_this.dropIndexSql(index));
|
|
433
|
-
downQueries.push(_this.createIndexSql(table, index));
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
|
-
upQueries.push(this.dropTableSql(table, ifExist));
|
|
437
|
-
downQueries.push(this.createTableSql(table, createForeignKeys));
|
|
438
|
-
generatedColumns = table.columns.filter(function (column) { return column.generatedType && column.asExpression; });
|
|
439
|
-
try {
|
|
440
|
-
for (generatedColumns_2 = tslib_1.__values(generatedColumns), generatedColumns_2_1 = generatedColumns_2.next(); !generatedColumns_2_1.done; generatedColumns_2_1 = generatedColumns_2.next()) {
|
|
441
|
-
column = generatedColumns_2_1.value;
|
|
442
|
-
deleteQuery = this.deleteTypeormMetadataSql({
|
|
443
|
-
table: table.name,
|
|
444
|
-
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
445
|
-
name: column.name,
|
|
446
|
-
});
|
|
447
|
-
insertQuery = this.insertTypeormMetadataSql({
|
|
448
|
-
table: table.name,
|
|
449
|
-
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
450
|
-
name: column.name,
|
|
451
|
-
value: column.asExpression,
|
|
452
|
-
});
|
|
453
|
-
upQueries.push(deleteQuery);
|
|
454
|
-
downQueries.push(insertQuery);
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
458
|
-
finally {
|
|
459
|
-
try {
|
|
460
|
-
if (generatedColumns_2_1 && !generatedColumns_2_1.done && (_b = generatedColumns_2.return)) _b.call(generatedColumns_2);
|
|
461
|
-
}
|
|
462
|
-
finally { if (e_2) throw e_2.error; }
|
|
463
|
-
}
|
|
464
|
-
return [4 /*yield*/, this.executeQueries(upQueries, downQueries)];
|
|
465
|
-
case 6:
|
|
466
|
-
_c.sent();
|
|
467
|
-
return [2 /*return*/];
|
|
468
|
-
}
|
|
262
|
+
async dropTable(tableOrName, ifExist, dropForeignKeys = true, dropIndices = true) {
|
|
263
|
+
if (ifExist) {
|
|
264
|
+
const isTableExist = await this.hasTable(tableOrName);
|
|
265
|
+
if (!isTableExist)
|
|
266
|
+
return Promise.resolve();
|
|
267
|
+
}
|
|
268
|
+
// if dropTable called with dropForeignKeys = true, we must create foreign keys in down query.
|
|
269
|
+
const createForeignKeys = dropForeignKeys;
|
|
270
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
271
|
+
? tableOrName
|
|
272
|
+
: await this.getCachedTable(tableOrName);
|
|
273
|
+
const upQueries = [];
|
|
274
|
+
const downQueries = [];
|
|
275
|
+
if (dropIndices) {
|
|
276
|
+
table.indices.forEach((index) => {
|
|
277
|
+
upQueries.push(this.dropIndexSql(index));
|
|
278
|
+
downQueries.push(this.createIndexSql(table, index));
|
|
469
279
|
});
|
|
470
|
-
}
|
|
471
|
-
|
|
280
|
+
}
|
|
281
|
+
upQueries.push(this.dropTableSql(table, ifExist));
|
|
282
|
+
downQueries.push(this.createTableSql(table, createForeignKeys));
|
|
283
|
+
// if table had columns with generated type, we must remove the expression from the metadata table
|
|
284
|
+
const generatedColumns = table.columns.filter((column) => column.generatedType && column.asExpression);
|
|
285
|
+
for (const column of generatedColumns) {
|
|
286
|
+
const deleteQuery = this.deleteTypeormMetadataSql({
|
|
287
|
+
table: table.name,
|
|
288
|
+
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
289
|
+
name: column.name,
|
|
290
|
+
});
|
|
291
|
+
const insertQuery = this.insertTypeormMetadataSql({
|
|
292
|
+
table: table.name,
|
|
293
|
+
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
294
|
+
name: column.name,
|
|
295
|
+
value: column.asExpression,
|
|
296
|
+
});
|
|
297
|
+
upQueries.push(deleteQuery);
|
|
298
|
+
downQueries.push(insertQuery);
|
|
299
|
+
}
|
|
300
|
+
await this.executeQueries(upQueries, downQueries);
|
|
301
|
+
}
|
|
472
302
|
/**
|
|
473
303
|
* Creates a new view.
|
|
474
304
|
*/
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
upQueries.push(this.insertViewDefinitionSql(view));
|
|
487
|
-
downQueries.push(this.dropViewSql(view));
|
|
488
|
-
if (syncWithMetadata)
|
|
489
|
-
downQueries.push(this.deleteViewDefinitionSql(view));
|
|
490
|
-
return [4 /*yield*/, this.executeQueries(upQueries, downQueries)];
|
|
491
|
-
case 1:
|
|
492
|
-
_a.sent();
|
|
493
|
-
return [2 /*return*/];
|
|
494
|
-
}
|
|
495
|
-
});
|
|
496
|
-
});
|
|
497
|
-
};
|
|
305
|
+
async createView(view, syncWithMetadata = false) {
|
|
306
|
+
const upQueries = [];
|
|
307
|
+
const downQueries = [];
|
|
308
|
+
upQueries.push(this.createViewSql(view));
|
|
309
|
+
if (syncWithMetadata)
|
|
310
|
+
upQueries.push(this.insertViewDefinitionSql(view));
|
|
311
|
+
downQueries.push(this.dropViewSql(view));
|
|
312
|
+
if (syncWithMetadata)
|
|
313
|
+
downQueries.push(this.deleteViewDefinitionSql(view));
|
|
314
|
+
await this.executeQueries(upQueries, downQueries);
|
|
315
|
+
}
|
|
498
316
|
/**
|
|
499
317
|
* Drops the view.
|
|
500
318
|
*/
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
downQueries = [];
|
|
513
|
-
upQueries.push(this.deleteViewDefinitionSql(view));
|
|
514
|
-
upQueries.push(this.dropViewSql(view));
|
|
515
|
-
downQueries.push(this.insertViewDefinitionSql(view));
|
|
516
|
-
downQueries.push(this.createViewSql(view));
|
|
517
|
-
return [4 /*yield*/, this.executeQueries(upQueries, downQueries)];
|
|
518
|
-
case 2:
|
|
519
|
-
_a.sent();
|
|
520
|
-
return [2 /*return*/];
|
|
521
|
-
}
|
|
522
|
-
});
|
|
523
|
-
});
|
|
524
|
-
};
|
|
319
|
+
async dropView(target) {
|
|
320
|
+
const viewName = InstanceChecker_1.InstanceChecker.isView(target) ? target.name : target;
|
|
321
|
+
const view = await this.getCachedView(viewName);
|
|
322
|
+
const upQueries = [];
|
|
323
|
+
const downQueries = [];
|
|
324
|
+
upQueries.push(this.deleteViewDefinitionSql(view));
|
|
325
|
+
upQueries.push(this.dropViewSql(view));
|
|
326
|
+
downQueries.push(this.insertViewDefinitionSql(view));
|
|
327
|
+
downQueries.push(this.createViewSql(view));
|
|
328
|
+
await this.executeQueries(upQueries, downQueries);
|
|
329
|
+
}
|
|
525
330
|
/**
|
|
526
331
|
* Renames the given table.
|
|
527
332
|
*/
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
// rename foreign key constraints
|
|
562
|
-
newTable.foreignKeys.forEach(function (foreignKey) {
|
|
563
|
-
var oldForeignKeyName = _this.connection.namingStrategy.foreignKeyName(oldTable, foreignKey.columnNames, _this.getTablePath(foreignKey), foreignKey.referencedColumnNames);
|
|
564
|
-
// Skip renaming if foreign key has user defined constraint name
|
|
565
|
-
if (foreignKey.name !== oldForeignKeyName)
|
|
566
|
-
return;
|
|
567
|
-
foreignKey.name = _this.connection.namingStrategy.foreignKeyName(newTable, foreignKey.columnNames, _this.getTablePath(foreignKey), foreignKey.referencedColumnNames);
|
|
568
|
-
});
|
|
569
|
-
// rename indices
|
|
570
|
-
newTable.indices.forEach(function (index) {
|
|
571
|
-
var oldIndexName = _this.connection.namingStrategy.indexName(oldTable, index.columnNames, index.where);
|
|
572
|
-
// Skip renaming if Index has user defined constraint name
|
|
573
|
-
if (index.name !== oldIndexName)
|
|
574
|
-
return;
|
|
575
|
-
index.name = _this.connection.namingStrategy.indexName(newTable, index.columnNames, index.where);
|
|
576
|
-
});
|
|
577
|
-
// rename old table;
|
|
578
|
-
oldTable.name = newTable.name;
|
|
579
|
-
// recreate table with new constraint names
|
|
580
|
-
return [4 /*yield*/, this.recreateTable(newTable, oldTable)];
|
|
581
|
-
case 5:
|
|
582
|
-
// recreate table with new constraint names
|
|
583
|
-
_b.sent();
|
|
584
|
-
return [2 /*return*/];
|
|
585
|
-
}
|
|
586
|
-
});
|
|
333
|
+
async renameTable(oldTableOrName, newTableName) {
|
|
334
|
+
const oldTable = InstanceChecker_1.InstanceChecker.isTable(oldTableOrName)
|
|
335
|
+
? oldTableOrName
|
|
336
|
+
: await this.getCachedTable(oldTableOrName);
|
|
337
|
+
const newTable = oldTable.clone();
|
|
338
|
+
newTable.name = newTableName;
|
|
339
|
+
// rename table
|
|
340
|
+
const up = new Query_1.Query(`ALTER TABLE ${this.escapePath(oldTable.name)} RENAME TO ${this.escapePath(newTableName)}`);
|
|
341
|
+
const down = new Query_1.Query(`ALTER TABLE ${this.escapePath(newTableName)} RENAME TO ${this.escapePath(oldTable.name)}`);
|
|
342
|
+
await this.executeQueries(up, down);
|
|
343
|
+
// rename unique constraints
|
|
344
|
+
newTable.uniques.forEach((unique) => {
|
|
345
|
+
const oldUniqueName = this.connection.namingStrategy.uniqueConstraintName(oldTable, unique.columnNames);
|
|
346
|
+
// Skip renaming if Unique has user defined constraint name
|
|
347
|
+
if (unique.name !== oldUniqueName)
|
|
348
|
+
return;
|
|
349
|
+
unique.name = this.connection.namingStrategy.uniqueConstraintName(newTable, unique.columnNames);
|
|
350
|
+
});
|
|
351
|
+
// rename foreign key constraints
|
|
352
|
+
newTable.foreignKeys.forEach((foreignKey) => {
|
|
353
|
+
const oldForeignKeyName = this.connection.namingStrategy.foreignKeyName(oldTable, foreignKey.columnNames, this.getTablePath(foreignKey), foreignKey.referencedColumnNames);
|
|
354
|
+
// Skip renaming if foreign key has user defined constraint name
|
|
355
|
+
if (foreignKey.name !== oldForeignKeyName)
|
|
356
|
+
return;
|
|
357
|
+
foreignKey.name = this.connection.namingStrategy.foreignKeyName(newTable, foreignKey.columnNames, this.getTablePath(foreignKey), foreignKey.referencedColumnNames);
|
|
358
|
+
});
|
|
359
|
+
// rename indices
|
|
360
|
+
newTable.indices.forEach((index) => {
|
|
361
|
+
const oldIndexName = this.connection.namingStrategy.indexName(oldTable, index.columnNames, index.where);
|
|
362
|
+
// Skip renaming if Index has user defined constraint name
|
|
363
|
+
if (index.name !== oldIndexName)
|
|
364
|
+
return;
|
|
365
|
+
index.name = this.connection.namingStrategy.indexName(newTable, index.columnNames, index.where);
|
|
587
366
|
});
|
|
588
|
-
|
|
367
|
+
// rename old table;
|
|
368
|
+
oldTable.name = newTable.name;
|
|
369
|
+
// recreate table with new constraint names
|
|
370
|
+
await this.recreateTable(newTable, oldTable);
|
|
371
|
+
}
|
|
589
372
|
/**
|
|
590
373
|
* Creates a new column from the column in the table.
|
|
591
374
|
*/
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
if (!InstanceChecker_1.InstanceChecker.isTable(tableOrName)) return [3 /*break*/, 1];
|
|
599
|
-
_a = tableOrName;
|
|
600
|
-
return [3 /*break*/, 3];
|
|
601
|
-
case 1: return [4 /*yield*/, this.getCachedTable(tableOrName)];
|
|
602
|
-
case 2:
|
|
603
|
-
_a = _b.sent();
|
|
604
|
-
_b.label = 3;
|
|
605
|
-
case 3:
|
|
606
|
-
table = _a;
|
|
607
|
-
return [2 /*return*/, this.addColumns(table, [column])];
|
|
608
|
-
}
|
|
609
|
-
});
|
|
610
|
-
});
|
|
611
|
-
};
|
|
375
|
+
async addColumn(tableOrName, column) {
|
|
376
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
377
|
+
? tableOrName
|
|
378
|
+
: await this.getCachedTable(tableOrName);
|
|
379
|
+
return this.addColumns(table, [column]);
|
|
380
|
+
}
|
|
612
381
|
/**
|
|
613
382
|
* Creates a new columns from the column in the table.
|
|
614
383
|
*/
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
return [3 /*break*/, 3];
|
|
624
|
-
case 1: return [4 /*yield*/, this.getCachedTable(tableOrName)];
|
|
625
|
-
case 2:
|
|
626
|
-
_a = _b.sent();
|
|
627
|
-
_b.label = 3;
|
|
628
|
-
case 3:
|
|
629
|
-
table = _a;
|
|
630
|
-
changedTable = table.clone();
|
|
631
|
-
columns.forEach(function (column) { return changedTable.addColumn(column); });
|
|
632
|
-
return [4 /*yield*/, this.recreateTable(changedTable, table)];
|
|
633
|
-
case 4:
|
|
634
|
-
_b.sent();
|
|
635
|
-
return [2 /*return*/];
|
|
636
|
-
}
|
|
637
|
-
});
|
|
638
|
-
});
|
|
639
|
-
};
|
|
384
|
+
async addColumns(tableOrName, columns) {
|
|
385
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
386
|
+
? tableOrName
|
|
387
|
+
: await this.getCachedTable(tableOrName);
|
|
388
|
+
const changedTable = table.clone();
|
|
389
|
+
columns.forEach((column) => changedTable.addColumn(column));
|
|
390
|
+
await this.recreateTable(changedTable, table);
|
|
391
|
+
}
|
|
640
392
|
/**
|
|
641
393
|
* Renames column in the given table.
|
|
642
394
|
*/
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
throw new error_1.TypeORMError("Column \"".concat(oldTableColumnOrName, "\" was not found in the \"").concat(table.name, "\" table."));
|
|
663
|
-
newColumn = undefined;
|
|
664
|
-
if (InstanceChecker_1.InstanceChecker.isTableColumn(newTableColumnOrName)) {
|
|
665
|
-
newColumn = newTableColumnOrName;
|
|
666
|
-
}
|
|
667
|
-
else {
|
|
668
|
-
newColumn = oldColumn.clone();
|
|
669
|
-
newColumn.name = newTableColumnOrName;
|
|
670
|
-
}
|
|
671
|
-
return [2 /*return*/, this.changeColumn(table, oldColumn, newColumn)];
|
|
672
|
-
}
|
|
673
|
-
});
|
|
674
|
-
});
|
|
675
|
-
};
|
|
395
|
+
async renameColumn(tableOrName, oldTableColumnOrName, newTableColumnOrName) {
|
|
396
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
397
|
+
? tableOrName
|
|
398
|
+
: await this.getCachedTable(tableOrName);
|
|
399
|
+
const oldColumn = InstanceChecker_1.InstanceChecker.isTableColumn(oldTableColumnOrName)
|
|
400
|
+
? oldTableColumnOrName
|
|
401
|
+
: table.columns.find((c) => c.name === oldTableColumnOrName);
|
|
402
|
+
if (!oldColumn)
|
|
403
|
+
throw new error_1.TypeORMError(`Column "${oldTableColumnOrName}" was not found in the "${table.name}" table.`);
|
|
404
|
+
let newColumn = undefined;
|
|
405
|
+
if (InstanceChecker_1.InstanceChecker.isTableColumn(newTableColumnOrName)) {
|
|
406
|
+
newColumn = newTableColumnOrName;
|
|
407
|
+
}
|
|
408
|
+
else {
|
|
409
|
+
newColumn = oldColumn.clone();
|
|
410
|
+
newColumn.name = newTableColumnOrName;
|
|
411
|
+
}
|
|
412
|
+
return this.changeColumn(table, oldColumn, newColumn);
|
|
413
|
+
}
|
|
676
414
|
/**
|
|
677
415
|
* Changes a column in the table.
|
|
678
416
|
*/
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
_a = _b.sent();
|
|
691
|
-
_b.label = 3;
|
|
692
|
-
case 3:
|
|
693
|
-
table = _a;
|
|
694
|
-
oldColumn = InstanceChecker_1.InstanceChecker.isTableColumn(oldTableColumnOrName)
|
|
695
|
-
? oldTableColumnOrName
|
|
696
|
-
: table.columns.find(function (c) { return c.name === oldTableColumnOrName; });
|
|
697
|
-
if (!oldColumn)
|
|
698
|
-
throw new error_1.TypeORMError("Column \"".concat(oldTableColumnOrName, "\" was not found in the \"").concat(table.name, "\" table."));
|
|
699
|
-
return [4 /*yield*/, this.changeColumns(table, [{ oldColumn: oldColumn, newColumn: newColumn }])];
|
|
700
|
-
case 4:
|
|
701
|
-
_b.sent();
|
|
702
|
-
return [2 /*return*/];
|
|
703
|
-
}
|
|
704
|
-
});
|
|
705
|
-
});
|
|
706
|
-
};
|
|
417
|
+
async changeColumn(tableOrName, oldTableColumnOrName, newColumn) {
|
|
418
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
419
|
+
? tableOrName
|
|
420
|
+
: await this.getCachedTable(tableOrName);
|
|
421
|
+
const oldColumn = InstanceChecker_1.InstanceChecker.isTableColumn(oldTableColumnOrName)
|
|
422
|
+
? oldTableColumnOrName
|
|
423
|
+
: table.columns.find((c) => c.name === oldTableColumnOrName);
|
|
424
|
+
if (!oldColumn)
|
|
425
|
+
throw new error_1.TypeORMError(`Column "${oldTableColumnOrName}" was not found in the "${table.name}" table.`);
|
|
426
|
+
await this.changeColumns(table, [{ oldColumn, newColumn }]);
|
|
427
|
+
}
|
|
707
428
|
/**
|
|
708
429
|
* Changes a column in the table.
|
|
709
430
|
* Changed column looses all its keys in the db.
|
|
710
431
|
*/
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
index.columnNames.splice(index.columnNames.indexOf(changedColumnSet.oldColumn.name), 1);
|
|
760
|
-
index.columnNames.push(changedColumnSet.newColumn.name);
|
|
761
|
-
// rename Index only if it has default constraint name
|
|
762
|
-
if (index.name === indexName) {
|
|
763
|
-
index.name =
|
|
764
|
-
_this.connection.namingStrategy.indexName(changedTable, index.columnNames, index.where);
|
|
765
|
-
}
|
|
766
|
-
});
|
|
767
|
-
}
|
|
768
|
-
var originalColumn = changedTable.columns.find(function (column) { return column.name === changedColumnSet.oldColumn.name; });
|
|
769
|
-
if (originalColumn)
|
|
770
|
-
changedTable.columns[changedTable.columns.indexOf(originalColumn)] = changedColumnSet.newColumn;
|
|
771
|
-
});
|
|
772
|
-
return [4 /*yield*/, this.recreateTable(changedTable, table)];
|
|
773
|
-
case 4:
|
|
774
|
-
_b.sent();
|
|
775
|
-
return [2 /*return*/];
|
|
776
|
-
}
|
|
777
|
-
});
|
|
432
|
+
async changeColumns(tableOrName, changedColumns) {
|
|
433
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
434
|
+
? tableOrName
|
|
435
|
+
: await this.getCachedTable(tableOrName);
|
|
436
|
+
const changedTable = table.clone();
|
|
437
|
+
changedColumns.forEach((changedColumnSet) => {
|
|
438
|
+
if (changedColumnSet.newColumn.name !==
|
|
439
|
+
changedColumnSet.oldColumn.name) {
|
|
440
|
+
changedTable
|
|
441
|
+
.findColumnUniques(changedColumnSet.oldColumn)
|
|
442
|
+
.forEach((unique) => {
|
|
443
|
+
const uniqueName = this.connection.namingStrategy.uniqueConstraintName(table, unique.columnNames);
|
|
444
|
+
unique.columnNames.splice(unique.columnNames.indexOf(changedColumnSet.oldColumn.name), 1);
|
|
445
|
+
unique.columnNames.push(changedColumnSet.newColumn.name);
|
|
446
|
+
// rename Unique only if it has default constraint name
|
|
447
|
+
if (unique.name === uniqueName) {
|
|
448
|
+
unique.name =
|
|
449
|
+
this.connection.namingStrategy.uniqueConstraintName(changedTable, unique.columnNames);
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
changedTable
|
|
453
|
+
.findColumnForeignKeys(changedColumnSet.oldColumn)
|
|
454
|
+
.forEach((foreignKey) => {
|
|
455
|
+
const foreignKeyName = this.connection.namingStrategy.foreignKeyName(table, foreignKey.columnNames, this.getTablePath(foreignKey), foreignKey.referencedColumnNames);
|
|
456
|
+
foreignKey.columnNames.splice(foreignKey.columnNames.indexOf(changedColumnSet.oldColumn.name), 1);
|
|
457
|
+
foreignKey.columnNames.push(changedColumnSet.newColumn.name);
|
|
458
|
+
// rename FK only if it has default constraint name
|
|
459
|
+
if (foreignKey.name === foreignKeyName) {
|
|
460
|
+
foreignKey.name =
|
|
461
|
+
this.connection.namingStrategy.foreignKeyName(changedTable, foreignKey.columnNames, this.getTablePath(foreignKey), foreignKey.referencedColumnNames);
|
|
462
|
+
}
|
|
463
|
+
});
|
|
464
|
+
changedTable
|
|
465
|
+
.findColumnIndices(changedColumnSet.oldColumn)
|
|
466
|
+
.forEach((index) => {
|
|
467
|
+
const indexName = this.connection.namingStrategy.indexName(table, index.columnNames, index.where);
|
|
468
|
+
index.columnNames.splice(index.columnNames.indexOf(changedColumnSet.oldColumn.name), 1);
|
|
469
|
+
index.columnNames.push(changedColumnSet.newColumn.name);
|
|
470
|
+
// rename Index only if it has default constraint name
|
|
471
|
+
if (index.name === indexName) {
|
|
472
|
+
index.name =
|
|
473
|
+
this.connection.namingStrategy.indexName(changedTable, index.columnNames, index.where);
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
const originalColumn = changedTable.columns.find((column) => column.name === changedColumnSet.oldColumn.name);
|
|
478
|
+
if (originalColumn)
|
|
479
|
+
changedTable.columns[changedTable.columns.indexOf(originalColumn)] = changedColumnSet.newColumn;
|
|
778
480
|
});
|
|
779
|
-
|
|
481
|
+
await this.recreateTable(changedTable, table);
|
|
482
|
+
}
|
|
780
483
|
/**
|
|
781
484
|
* Drops column in the table.
|
|
782
485
|
*/
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
_a = _b.sent();
|
|
795
|
-
_b.label = 3;
|
|
796
|
-
case 3:
|
|
797
|
-
table = _a;
|
|
798
|
-
column = InstanceChecker_1.InstanceChecker.isTableColumn(columnOrName)
|
|
799
|
-
? columnOrName
|
|
800
|
-
: table.findColumnByName(columnOrName);
|
|
801
|
-
if (!column)
|
|
802
|
-
throw new error_1.TypeORMError("Column \"".concat(columnOrName, "\" was not found in table \"").concat(table.name, "\""));
|
|
803
|
-
return [4 /*yield*/, this.dropColumns(table, [column])];
|
|
804
|
-
case 4:
|
|
805
|
-
_b.sent();
|
|
806
|
-
return [2 /*return*/];
|
|
807
|
-
}
|
|
808
|
-
});
|
|
809
|
-
});
|
|
810
|
-
};
|
|
486
|
+
async dropColumn(tableOrName, columnOrName) {
|
|
487
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
488
|
+
? tableOrName
|
|
489
|
+
: await this.getCachedTable(tableOrName);
|
|
490
|
+
const column = InstanceChecker_1.InstanceChecker.isTableColumn(columnOrName)
|
|
491
|
+
? columnOrName
|
|
492
|
+
: table.findColumnByName(columnOrName);
|
|
493
|
+
if (!column)
|
|
494
|
+
throw new error_1.TypeORMError(`Column "${columnOrName}" was not found in table "${table.name}"`);
|
|
495
|
+
await this.dropColumns(table, [column]);
|
|
496
|
+
}
|
|
811
497
|
/**
|
|
812
498
|
* Drops the columns in the table.
|
|
813
499
|
*/
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
if (!columnInstance)
|
|
837
|
-
throw new Error("Column \"".concat(column, "\" was not found in table \"").concat(table.name, "\""));
|
|
838
|
-
changedTable.removeColumn(columnInstance);
|
|
839
|
-
changedTable
|
|
840
|
-
.findColumnUniques(columnInstance)
|
|
841
|
-
.forEach(function (unique) {
|
|
842
|
-
return changedTable.removeUniqueConstraint(unique);
|
|
843
|
-
});
|
|
844
|
-
changedTable
|
|
845
|
-
.findColumnIndices(columnInstance)
|
|
846
|
-
.forEach(function (index) { return changedTable.removeIndex(index); });
|
|
847
|
-
changedTable
|
|
848
|
-
.findColumnForeignKeys(columnInstance)
|
|
849
|
-
.forEach(function (fk) { return changedTable.removeForeignKey(fk); });
|
|
850
|
-
});
|
|
851
|
-
return [4 /*yield*/, this.recreateTable(changedTable, table)];
|
|
852
|
-
case 4:
|
|
853
|
-
_b.sent();
|
|
854
|
-
return [2 /*return*/];
|
|
855
|
-
}
|
|
856
|
-
});
|
|
500
|
+
async dropColumns(tableOrName, columns) {
|
|
501
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
502
|
+
? tableOrName
|
|
503
|
+
: await this.getCachedTable(tableOrName);
|
|
504
|
+
// clone original table and remove column and its constraints from cloned table
|
|
505
|
+
const changedTable = table.clone();
|
|
506
|
+
columns.forEach((column) => {
|
|
507
|
+
const columnInstance = InstanceChecker_1.InstanceChecker.isTableColumn(column)
|
|
508
|
+
? column
|
|
509
|
+
: table.findColumnByName(column);
|
|
510
|
+
if (!columnInstance)
|
|
511
|
+
throw new Error(`Column "${column}" was not found in table "${table.name}"`);
|
|
512
|
+
changedTable.removeColumn(columnInstance);
|
|
513
|
+
changedTable
|
|
514
|
+
.findColumnUniques(columnInstance)
|
|
515
|
+
.forEach((unique) => changedTable.removeUniqueConstraint(unique));
|
|
516
|
+
changedTable
|
|
517
|
+
.findColumnIndices(columnInstance)
|
|
518
|
+
.forEach((index) => changedTable.removeIndex(index));
|
|
519
|
+
changedTable
|
|
520
|
+
.findColumnForeignKeys(columnInstance)
|
|
521
|
+
.forEach((fk) => changedTable.removeForeignKey(fk));
|
|
857
522
|
});
|
|
858
|
-
|
|
523
|
+
await this.recreateTable(changedTable, table);
|
|
524
|
+
}
|
|
859
525
|
/**
|
|
860
526
|
* Creates a new primary key.
|
|
861
527
|
*/
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
case 1: return [4 /*yield*/, this.getCachedTable(tableOrName)
|
|
872
|
-
// clone original table and mark columns as primary
|
|
873
|
-
];
|
|
874
|
-
case 2:
|
|
875
|
-
_a = _b.sent();
|
|
876
|
-
_b.label = 3;
|
|
877
|
-
case 3:
|
|
878
|
-
table = _a;
|
|
879
|
-
changedTable = table.clone();
|
|
880
|
-
changedTable.columns.forEach(function (column) {
|
|
881
|
-
if (columnNames.find(function (columnName) { return columnName === column.name; }))
|
|
882
|
-
column.isPrimary = true;
|
|
883
|
-
});
|
|
884
|
-
return [4 /*yield*/, this.recreateTable(changedTable, table)
|
|
885
|
-
// mark columns as primary in original table
|
|
886
|
-
];
|
|
887
|
-
case 4:
|
|
888
|
-
_b.sent();
|
|
889
|
-
// mark columns as primary in original table
|
|
890
|
-
table.columns.forEach(function (column) {
|
|
891
|
-
if (columnNames.find(function (columnName) { return columnName === column.name; }))
|
|
892
|
-
column.isPrimary = true;
|
|
893
|
-
});
|
|
894
|
-
return [2 /*return*/];
|
|
895
|
-
}
|
|
896
|
-
});
|
|
528
|
+
async createPrimaryKey(tableOrName, columnNames) {
|
|
529
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
530
|
+
? tableOrName
|
|
531
|
+
: await this.getCachedTable(tableOrName);
|
|
532
|
+
// clone original table and mark columns as primary
|
|
533
|
+
const changedTable = table.clone();
|
|
534
|
+
changedTable.columns.forEach((column) => {
|
|
535
|
+
if (columnNames.find((columnName) => columnName === column.name))
|
|
536
|
+
column.isPrimary = true;
|
|
897
537
|
});
|
|
898
|
-
|
|
538
|
+
await this.recreateTable(changedTable, table);
|
|
539
|
+
// mark columns as primary in original table
|
|
540
|
+
table.columns.forEach((column) => {
|
|
541
|
+
if (columnNames.find((columnName) => columnName === column.name))
|
|
542
|
+
column.isPrimary = true;
|
|
543
|
+
});
|
|
544
|
+
}
|
|
899
545
|
/**
|
|
900
546
|
* Updates composite primary keys.
|
|
901
547
|
*/
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
switch (_a.label) {
|
|
906
|
-
case 0: return [4 /*yield*/, Promise.resolve()];
|
|
907
|
-
case 1:
|
|
908
|
-
_a.sent();
|
|
909
|
-
return [2 /*return*/];
|
|
910
|
-
}
|
|
911
|
-
});
|
|
912
|
-
});
|
|
913
|
-
};
|
|
548
|
+
async updatePrimaryKeys(tableOrName, columns) {
|
|
549
|
+
await Promise.resolve();
|
|
550
|
+
}
|
|
914
551
|
/**
|
|
915
552
|
* Drops a primary key.
|
|
916
553
|
*/
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
_a = _b.sent();
|
|
931
|
-
_b.label = 3;
|
|
932
|
-
case 3:
|
|
933
|
-
table = _a;
|
|
934
|
-
changedTable = table.clone();
|
|
935
|
-
changedTable.primaryColumns.forEach(function (column) {
|
|
936
|
-
column.isPrimary = false;
|
|
937
|
-
});
|
|
938
|
-
return [4 /*yield*/, this.recreateTable(changedTable, table)
|
|
939
|
-
// mark primary columns as non-primary in original table
|
|
940
|
-
];
|
|
941
|
-
case 4:
|
|
942
|
-
_b.sent();
|
|
943
|
-
// mark primary columns as non-primary in original table
|
|
944
|
-
table.primaryColumns.forEach(function (column) {
|
|
945
|
-
column.isPrimary = false;
|
|
946
|
-
});
|
|
947
|
-
return [2 /*return*/];
|
|
948
|
-
}
|
|
949
|
-
});
|
|
554
|
+
async dropPrimaryKey(tableOrName) {
|
|
555
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
556
|
+
? tableOrName
|
|
557
|
+
: await this.getCachedTable(tableOrName);
|
|
558
|
+
// clone original table and mark primary columns as non-primary
|
|
559
|
+
const changedTable = table.clone();
|
|
560
|
+
changedTable.primaryColumns.forEach((column) => {
|
|
561
|
+
column.isPrimary = false;
|
|
562
|
+
});
|
|
563
|
+
await this.recreateTable(changedTable, table);
|
|
564
|
+
// mark primary columns as non-primary in original table
|
|
565
|
+
table.primaryColumns.forEach((column) => {
|
|
566
|
+
column.isPrimary = false;
|
|
950
567
|
});
|
|
951
|
-
}
|
|
568
|
+
}
|
|
952
569
|
/**
|
|
953
570
|
* Creates a new unique constraint.
|
|
954
571
|
*/
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
switch (_a.label) {
|
|
959
|
-
case 0: return [4 /*yield*/, this.createUniqueConstraints(tableOrName, [uniqueConstraint])];
|
|
960
|
-
case 1:
|
|
961
|
-
_a.sent();
|
|
962
|
-
return [2 /*return*/];
|
|
963
|
-
}
|
|
964
|
-
});
|
|
965
|
-
});
|
|
966
|
-
};
|
|
572
|
+
async createUniqueConstraint(tableOrName, uniqueConstraint) {
|
|
573
|
+
await this.createUniqueConstraints(tableOrName, [uniqueConstraint]);
|
|
574
|
+
}
|
|
967
575
|
/**
|
|
968
576
|
* Creates a new unique constraints.
|
|
969
577
|
*/
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
case 1: return [4 /*yield*/, this.getCachedTable(tableOrName)
|
|
980
|
-
// clone original table and add unique constraints in to cloned table
|
|
981
|
-
];
|
|
982
|
-
case 2:
|
|
983
|
-
_a = _b.sent();
|
|
984
|
-
_b.label = 3;
|
|
985
|
-
case 3:
|
|
986
|
-
table = _a;
|
|
987
|
-
changedTable = table.clone();
|
|
988
|
-
uniqueConstraints.forEach(function (uniqueConstraint) {
|
|
989
|
-
return changedTable.addUniqueConstraint(uniqueConstraint);
|
|
990
|
-
});
|
|
991
|
-
return [4 /*yield*/, this.recreateTable(changedTable, table)];
|
|
992
|
-
case 4:
|
|
993
|
-
_b.sent();
|
|
994
|
-
return [2 /*return*/];
|
|
995
|
-
}
|
|
996
|
-
});
|
|
997
|
-
});
|
|
998
|
-
};
|
|
578
|
+
async createUniqueConstraints(tableOrName, uniqueConstraints) {
|
|
579
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
580
|
+
? tableOrName
|
|
581
|
+
: await this.getCachedTable(tableOrName);
|
|
582
|
+
// clone original table and add unique constraints in to cloned table
|
|
583
|
+
const changedTable = table.clone();
|
|
584
|
+
uniqueConstraints.forEach((uniqueConstraint) => changedTable.addUniqueConstraint(uniqueConstraint));
|
|
585
|
+
await this.recreateTable(changedTable, table);
|
|
586
|
+
}
|
|
999
587
|
/**
|
|
1000
588
|
* Drops an unique constraint.
|
|
1001
589
|
*/
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
_a = _b.sent();
|
|
1014
|
-
_b.label = 3;
|
|
1015
|
-
case 3:
|
|
1016
|
-
table = _a;
|
|
1017
|
-
uniqueConstraint = InstanceChecker_1.InstanceChecker.isTableUnique(uniqueOrName)
|
|
1018
|
-
? uniqueOrName
|
|
1019
|
-
: table.uniques.find(function (u) { return u.name === uniqueOrName; });
|
|
1020
|
-
if (!uniqueConstraint)
|
|
1021
|
-
throw new error_1.TypeORMError("Supplied unique constraint was not found in table ".concat(table.name));
|
|
1022
|
-
return [4 /*yield*/, this.dropUniqueConstraints(table, [uniqueConstraint])];
|
|
1023
|
-
case 4:
|
|
1024
|
-
_b.sent();
|
|
1025
|
-
return [2 /*return*/];
|
|
1026
|
-
}
|
|
1027
|
-
});
|
|
1028
|
-
});
|
|
1029
|
-
};
|
|
590
|
+
async dropUniqueConstraint(tableOrName, uniqueOrName) {
|
|
591
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
592
|
+
? tableOrName
|
|
593
|
+
: await this.getCachedTable(tableOrName);
|
|
594
|
+
const uniqueConstraint = InstanceChecker_1.InstanceChecker.isTableUnique(uniqueOrName)
|
|
595
|
+
? uniqueOrName
|
|
596
|
+
: table.uniques.find((u) => u.name === uniqueOrName);
|
|
597
|
+
if (!uniqueConstraint)
|
|
598
|
+
throw new error_1.TypeORMError(`Supplied unique constraint was not found in table ${table.name}`);
|
|
599
|
+
await this.dropUniqueConstraints(table, [uniqueConstraint]);
|
|
600
|
+
}
|
|
1030
601
|
/**
|
|
1031
602
|
* Creates an unique constraints.
|
|
1032
603
|
*/
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
case 1: return [4 /*yield*/, this.getCachedTable(tableOrName)
|
|
1043
|
-
// clone original table and remove unique constraints from cloned table
|
|
1044
|
-
];
|
|
1045
|
-
case 2:
|
|
1046
|
-
_a = _b.sent();
|
|
1047
|
-
_b.label = 3;
|
|
1048
|
-
case 3:
|
|
1049
|
-
table = _a;
|
|
1050
|
-
changedTable = table.clone();
|
|
1051
|
-
uniqueConstraints.forEach(function (uniqueConstraint) {
|
|
1052
|
-
return changedTable.removeUniqueConstraint(uniqueConstraint);
|
|
1053
|
-
});
|
|
1054
|
-
return [4 /*yield*/, this.recreateTable(changedTable, table)];
|
|
1055
|
-
case 4:
|
|
1056
|
-
_b.sent();
|
|
1057
|
-
return [2 /*return*/];
|
|
1058
|
-
}
|
|
1059
|
-
});
|
|
1060
|
-
});
|
|
1061
|
-
};
|
|
604
|
+
async dropUniqueConstraints(tableOrName, uniqueConstraints) {
|
|
605
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
606
|
+
? tableOrName
|
|
607
|
+
: await this.getCachedTable(tableOrName);
|
|
608
|
+
// clone original table and remove unique constraints from cloned table
|
|
609
|
+
const changedTable = table.clone();
|
|
610
|
+
uniqueConstraints.forEach((uniqueConstraint) => changedTable.removeUniqueConstraint(uniqueConstraint));
|
|
611
|
+
await this.recreateTable(changedTable, table);
|
|
612
|
+
}
|
|
1062
613
|
/**
|
|
1063
614
|
* Creates new check constraint.
|
|
1064
615
|
*/
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
switch (_a.label) {
|
|
1069
|
-
case 0: return [4 /*yield*/, this.createCheckConstraints(tableOrName, [checkConstraint])];
|
|
1070
|
-
case 1:
|
|
1071
|
-
_a.sent();
|
|
1072
|
-
return [2 /*return*/];
|
|
1073
|
-
}
|
|
1074
|
-
});
|
|
1075
|
-
});
|
|
1076
|
-
};
|
|
616
|
+
async createCheckConstraint(tableOrName, checkConstraint) {
|
|
617
|
+
await this.createCheckConstraints(tableOrName, [checkConstraint]);
|
|
618
|
+
}
|
|
1077
619
|
/**
|
|
1078
620
|
* Creates new check constraints.
|
|
1079
621
|
*/
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
case 1: return [4 /*yield*/, this.getCachedTable(tableOrName)
|
|
1090
|
-
// clone original table and add check constraints in to cloned table
|
|
1091
|
-
];
|
|
1092
|
-
case 2:
|
|
1093
|
-
_a = _b.sent();
|
|
1094
|
-
_b.label = 3;
|
|
1095
|
-
case 3:
|
|
1096
|
-
table = _a;
|
|
1097
|
-
changedTable = table.clone();
|
|
1098
|
-
checkConstraints.forEach(function (checkConstraint) {
|
|
1099
|
-
return changedTable.addCheckConstraint(checkConstraint);
|
|
1100
|
-
});
|
|
1101
|
-
return [4 /*yield*/, this.recreateTable(changedTable, table)];
|
|
1102
|
-
case 4:
|
|
1103
|
-
_b.sent();
|
|
1104
|
-
return [2 /*return*/];
|
|
1105
|
-
}
|
|
1106
|
-
});
|
|
1107
|
-
});
|
|
1108
|
-
};
|
|
622
|
+
async createCheckConstraints(tableOrName, checkConstraints) {
|
|
623
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
624
|
+
? tableOrName
|
|
625
|
+
: await this.getCachedTable(tableOrName);
|
|
626
|
+
// clone original table and add check constraints in to cloned table
|
|
627
|
+
const changedTable = table.clone();
|
|
628
|
+
checkConstraints.forEach((checkConstraint) => changedTable.addCheckConstraint(checkConstraint));
|
|
629
|
+
await this.recreateTable(changedTable, table);
|
|
630
|
+
}
|
|
1109
631
|
/**
|
|
1110
632
|
* Drops check constraint.
|
|
1111
633
|
*/
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
_a = _b.sent();
|
|
1124
|
-
_b.label = 3;
|
|
1125
|
-
case 3:
|
|
1126
|
-
table = _a;
|
|
1127
|
-
checkConstraint = InstanceChecker_1.InstanceChecker.isTableCheck(checkOrName)
|
|
1128
|
-
? checkOrName
|
|
1129
|
-
: table.checks.find(function (c) { return c.name === checkOrName; });
|
|
1130
|
-
if (!checkConstraint)
|
|
1131
|
-
throw new error_1.TypeORMError("Supplied check constraint was not found in table ".concat(table.name));
|
|
1132
|
-
return [4 /*yield*/, this.dropCheckConstraints(table, [checkConstraint])];
|
|
1133
|
-
case 4:
|
|
1134
|
-
_b.sent();
|
|
1135
|
-
return [2 /*return*/];
|
|
1136
|
-
}
|
|
1137
|
-
});
|
|
1138
|
-
});
|
|
1139
|
-
};
|
|
634
|
+
async dropCheckConstraint(tableOrName, checkOrName) {
|
|
635
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
636
|
+
? tableOrName
|
|
637
|
+
: await this.getCachedTable(tableOrName);
|
|
638
|
+
const checkConstraint = InstanceChecker_1.InstanceChecker.isTableCheck(checkOrName)
|
|
639
|
+
? checkOrName
|
|
640
|
+
: table.checks.find((c) => c.name === checkOrName);
|
|
641
|
+
if (!checkConstraint)
|
|
642
|
+
throw new error_1.TypeORMError(`Supplied check constraint was not found in table ${table.name}`);
|
|
643
|
+
await this.dropCheckConstraints(table, [checkConstraint]);
|
|
644
|
+
}
|
|
1140
645
|
/**
|
|
1141
646
|
* Drops check constraints.
|
|
1142
647
|
*/
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
case 1: return [4 /*yield*/, this.getCachedTable(tableOrName)
|
|
1153
|
-
// clone original table and remove check constraints from cloned table
|
|
1154
|
-
];
|
|
1155
|
-
case 2:
|
|
1156
|
-
_a = _b.sent();
|
|
1157
|
-
_b.label = 3;
|
|
1158
|
-
case 3:
|
|
1159
|
-
table = _a;
|
|
1160
|
-
changedTable = table.clone();
|
|
1161
|
-
checkConstraints.forEach(function (checkConstraint) {
|
|
1162
|
-
return changedTable.removeCheckConstraint(checkConstraint);
|
|
1163
|
-
});
|
|
1164
|
-
return [4 /*yield*/, this.recreateTable(changedTable, table)];
|
|
1165
|
-
case 4:
|
|
1166
|
-
_b.sent();
|
|
1167
|
-
return [2 /*return*/];
|
|
1168
|
-
}
|
|
1169
|
-
});
|
|
1170
|
-
});
|
|
1171
|
-
};
|
|
648
|
+
async dropCheckConstraints(tableOrName, checkConstraints) {
|
|
649
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
650
|
+
? tableOrName
|
|
651
|
+
: await this.getCachedTable(tableOrName);
|
|
652
|
+
// clone original table and remove check constraints from cloned table
|
|
653
|
+
const changedTable = table.clone();
|
|
654
|
+
checkConstraints.forEach((checkConstraint) => changedTable.removeCheckConstraint(checkConstraint));
|
|
655
|
+
await this.recreateTable(changedTable, table);
|
|
656
|
+
}
|
|
1172
657
|
/**
|
|
1173
658
|
* Creates a new exclusion constraint.
|
|
1174
659
|
*/
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
throw new error_1.TypeORMError("Sqlite does not support exclusion constraints.");
|
|
1179
|
-
});
|
|
1180
|
-
});
|
|
1181
|
-
};
|
|
660
|
+
async createExclusionConstraint(tableOrName, exclusionConstraint) {
|
|
661
|
+
throw new error_1.TypeORMError(`Sqlite does not support exclusion constraints.`);
|
|
662
|
+
}
|
|
1182
663
|
/**
|
|
1183
664
|
* Creates a new exclusion constraints.
|
|
1184
665
|
*/
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
throw new error_1.TypeORMError("Sqlite does not support exclusion constraints.");
|
|
1189
|
-
});
|
|
1190
|
-
});
|
|
1191
|
-
};
|
|
666
|
+
async createExclusionConstraints(tableOrName, exclusionConstraints) {
|
|
667
|
+
throw new error_1.TypeORMError(`Sqlite does not support exclusion constraints.`);
|
|
668
|
+
}
|
|
1192
669
|
/**
|
|
1193
670
|
* Drops exclusion constraint.
|
|
1194
671
|
*/
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
throw new error_1.TypeORMError("Sqlite does not support exclusion constraints.");
|
|
1199
|
-
});
|
|
1200
|
-
});
|
|
1201
|
-
};
|
|
672
|
+
async dropExclusionConstraint(tableOrName, exclusionOrName) {
|
|
673
|
+
throw new error_1.TypeORMError(`Sqlite does not support exclusion constraints.`);
|
|
674
|
+
}
|
|
1202
675
|
/**
|
|
1203
676
|
* Drops exclusion constraints.
|
|
1204
677
|
*/
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
throw new error_1.TypeORMError("Sqlite does not support exclusion constraints.");
|
|
1209
|
-
});
|
|
1210
|
-
});
|
|
1211
|
-
};
|
|
678
|
+
async dropExclusionConstraints(tableOrName, exclusionConstraints) {
|
|
679
|
+
throw new error_1.TypeORMError(`Sqlite does not support exclusion constraints.`);
|
|
680
|
+
}
|
|
1212
681
|
/**
|
|
1213
682
|
* Creates a new foreign key.
|
|
1214
683
|
*/
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
switch (_a.label) {
|
|
1219
|
-
case 0: return [4 /*yield*/, this.createForeignKeys(tableOrName, [foreignKey])];
|
|
1220
|
-
case 1:
|
|
1221
|
-
_a.sent();
|
|
1222
|
-
return [2 /*return*/];
|
|
1223
|
-
}
|
|
1224
|
-
});
|
|
1225
|
-
});
|
|
1226
|
-
};
|
|
684
|
+
async createForeignKey(tableOrName, foreignKey) {
|
|
685
|
+
await this.createForeignKeys(tableOrName, [foreignKey]);
|
|
686
|
+
}
|
|
1227
687
|
/**
|
|
1228
688
|
* Creates a new foreign keys.
|
|
1229
689
|
*/
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
case 1: return [4 /*yield*/, this.getCachedTable(tableOrName)
|
|
1240
|
-
// clone original table and add foreign keys in to cloned table
|
|
1241
|
-
];
|
|
1242
|
-
case 2:
|
|
1243
|
-
_a = _b.sent();
|
|
1244
|
-
_b.label = 3;
|
|
1245
|
-
case 3:
|
|
1246
|
-
table = _a;
|
|
1247
|
-
changedTable = table.clone();
|
|
1248
|
-
foreignKeys.forEach(function (foreignKey) {
|
|
1249
|
-
return changedTable.addForeignKey(foreignKey);
|
|
1250
|
-
});
|
|
1251
|
-
return [4 /*yield*/, this.recreateTable(changedTable, table)];
|
|
1252
|
-
case 4:
|
|
1253
|
-
_b.sent();
|
|
1254
|
-
return [2 /*return*/];
|
|
1255
|
-
}
|
|
1256
|
-
});
|
|
1257
|
-
});
|
|
1258
|
-
};
|
|
690
|
+
async createForeignKeys(tableOrName, foreignKeys) {
|
|
691
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
692
|
+
? tableOrName
|
|
693
|
+
: await this.getCachedTable(tableOrName);
|
|
694
|
+
// clone original table and add foreign keys in to cloned table
|
|
695
|
+
const changedTable = table.clone();
|
|
696
|
+
foreignKeys.forEach((foreignKey) => changedTable.addForeignKey(foreignKey));
|
|
697
|
+
await this.recreateTable(changedTable, table);
|
|
698
|
+
}
|
|
1259
699
|
/**
|
|
1260
700
|
* Drops a foreign key from the table.
|
|
1261
701
|
*/
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
_a = _b.sent();
|
|
1274
|
-
_b.label = 3;
|
|
1275
|
-
case 3:
|
|
1276
|
-
table = _a;
|
|
1277
|
-
foreignKey = InstanceChecker_1.InstanceChecker.isTableForeignKey(foreignKeyOrName)
|
|
1278
|
-
? foreignKeyOrName
|
|
1279
|
-
: table.foreignKeys.find(function (fk) { return fk.name === foreignKeyOrName; });
|
|
1280
|
-
if (!foreignKey)
|
|
1281
|
-
throw new error_1.TypeORMError("Supplied foreign key was not found in table ".concat(table.name));
|
|
1282
|
-
return [4 /*yield*/, this.dropForeignKeys(tableOrName, [foreignKey])];
|
|
1283
|
-
case 4:
|
|
1284
|
-
_b.sent();
|
|
1285
|
-
return [2 /*return*/];
|
|
1286
|
-
}
|
|
1287
|
-
});
|
|
1288
|
-
});
|
|
1289
|
-
};
|
|
702
|
+
async dropForeignKey(tableOrName, foreignKeyOrName) {
|
|
703
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
704
|
+
? tableOrName
|
|
705
|
+
: await this.getCachedTable(tableOrName);
|
|
706
|
+
const foreignKey = InstanceChecker_1.InstanceChecker.isTableForeignKey(foreignKeyOrName)
|
|
707
|
+
? foreignKeyOrName
|
|
708
|
+
: table.foreignKeys.find((fk) => fk.name === foreignKeyOrName);
|
|
709
|
+
if (!foreignKey)
|
|
710
|
+
throw new error_1.TypeORMError(`Supplied foreign key was not found in table ${table.name}`);
|
|
711
|
+
await this.dropForeignKeys(tableOrName, [foreignKey]);
|
|
712
|
+
}
|
|
1290
713
|
/**
|
|
1291
714
|
* Drops a foreign keys from the table.
|
|
1292
715
|
*/
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
case 1: return [4 /*yield*/, this.getCachedTable(tableOrName)
|
|
1303
|
-
// clone original table and remove foreign keys from cloned table
|
|
1304
|
-
];
|
|
1305
|
-
case 2:
|
|
1306
|
-
_a = _b.sent();
|
|
1307
|
-
_b.label = 3;
|
|
1308
|
-
case 3:
|
|
1309
|
-
table = _a;
|
|
1310
|
-
changedTable = table.clone();
|
|
1311
|
-
foreignKeys.forEach(function (foreignKey) {
|
|
1312
|
-
return changedTable.removeForeignKey(foreignKey);
|
|
1313
|
-
});
|
|
1314
|
-
return [4 /*yield*/, this.recreateTable(changedTable, table)];
|
|
1315
|
-
case 4:
|
|
1316
|
-
_b.sent();
|
|
1317
|
-
return [2 /*return*/];
|
|
1318
|
-
}
|
|
1319
|
-
});
|
|
1320
|
-
});
|
|
1321
|
-
};
|
|
716
|
+
async dropForeignKeys(tableOrName, foreignKeys) {
|
|
717
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
718
|
+
? tableOrName
|
|
719
|
+
: await this.getCachedTable(tableOrName);
|
|
720
|
+
// clone original table and remove foreign keys from cloned table
|
|
721
|
+
const changedTable = table.clone();
|
|
722
|
+
foreignKeys.forEach((foreignKey) => changedTable.removeForeignKey(foreignKey));
|
|
723
|
+
await this.recreateTable(changedTable, table);
|
|
724
|
+
}
|
|
1322
725
|
/**
|
|
1323
726
|
* Creates a new index.
|
|
1324
727
|
*/
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
case 2:
|
|
1338
|
-
_a = _b.sent();
|
|
1339
|
-
_b.label = 3;
|
|
1340
|
-
case 3:
|
|
1341
|
-
table = _a;
|
|
1342
|
-
// new index may be passed without name. In this case we generate index name manually.
|
|
1343
|
-
if (!index.name)
|
|
1344
|
-
index.name = this.generateIndexName(table, index);
|
|
1345
|
-
up = this.createIndexSql(table, index);
|
|
1346
|
-
down = this.dropIndexSql(index);
|
|
1347
|
-
return [4 /*yield*/, this.executeQueries(up, down)];
|
|
1348
|
-
case 4:
|
|
1349
|
-
_b.sent();
|
|
1350
|
-
table.addIndex(index);
|
|
1351
|
-
return [2 /*return*/];
|
|
1352
|
-
}
|
|
1353
|
-
});
|
|
1354
|
-
});
|
|
1355
|
-
};
|
|
728
|
+
async createIndex(tableOrName, index) {
|
|
729
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
730
|
+
? tableOrName
|
|
731
|
+
: await this.getCachedTable(tableOrName);
|
|
732
|
+
// new index may be passed without name. In this case we generate index name manually.
|
|
733
|
+
if (!index.name)
|
|
734
|
+
index.name = this.generateIndexName(table, index);
|
|
735
|
+
const up = this.createIndexSql(table, index);
|
|
736
|
+
const down = this.dropIndexSql(index);
|
|
737
|
+
await this.executeQueries(up, down);
|
|
738
|
+
table.addIndex(index);
|
|
739
|
+
}
|
|
1356
740
|
/**
|
|
1357
741
|
* Creates a new indices
|
|
1358
742
|
*/
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
return tslib_1.__generator(this, function (_a) {
|
|
1364
|
-
switch (_a.label) {
|
|
1365
|
-
case 0:
|
|
1366
|
-
promises = indices.map(function (index) {
|
|
1367
|
-
return _this.createIndex(tableOrName, index);
|
|
1368
|
-
});
|
|
1369
|
-
return [4 /*yield*/, Promise.all(promises)];
|
|
1370
|
-
case 1:
|
|
1371
|
-
_a.sent();
|
|
1372
|
-
return [2 /*return*/];
|
|
1373
|
-
}
|
|
1374
|
-
});
|
|
1375
|
-
});
|
|
1376
|
-
};
|
|
743
|
+
async createIndices(tableOrName, indices) {
|
|
744
|
+
const promises = indices.map((index) => this.createIndex(tableOrName, index));
|
|
745
|
+
await Promise.all(promises);
|
|
746
|
+
}
|
|
1377
747
|
/**
|
|
1378
748
|
* Drops an index from the table.
|
|
1379
749
|
*/
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
: table.indices.find(function (i) { return i.name === indexOrName; });
|
|
1398
|
-
if (!index)
|
|
1399
|
-
throw new error_1.TypeORMError("Supplied index ".concat(indexOrName, " was not found in table ").concat(table.name));
|
|
1400
|
-
// old index may be passed without name. In this case we generate index name manually.
|
|
1401
|
-
if (!index.name)
|
|
1402
|
-
index.name = this.generateIndexName(table, index);
|
|
1403
|
-
up = this.dropIndexSql(index);
|
|
1404
|
-
down = this.createIndexSql(table, index);
|
|
1405
|
-
return [4 /*yield*/, this.executeQueries(up, down)];
|
|
1406
|
-
case 4:
|
|
1407
|
-
_b.sent();
|
|
1408
|
-
table.removeIndex(index);
|
|
1409
|
-
return [2 /*return*/];
|
|
1410
|
-
}
|
|
1411
|
-
});
|
|
1412
|
-
});
|
|
1413
|
-
};
|
|
750
|
+
async dropIndex(tableOrName, indexOrName) {
|
|
751
|
+
const table = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
752
|
+
? tableOrName
|
|
753
|
+
: await this.getCachedTable(tableOrName);
|
|
754
|
+
const index = InstanceChecker_1.InstanceChecker.isTableIndex(indexOrName)
|
|
755
|
+
? indexOrName
|
|
756
|
+
: table.indices.find((i) => i.name === indexOrName);
|
|
757
|
+
if (!index)
|
|
758
|
+
throw new error_1.TypeORMError(`Supplied index ${indexOrName} was not found in table ${table.name}`);
|
|
759
|
+
// old index may be passed without name. In this case we generate index name manually.
|
|
760
|
+
if (!index.name)
|
|
761
|
+
index.name = this.generateIndexName(table, index);
|
|
762
|
+
const up = this.dropIndexSql(index);
|
|
763
|
+
const down = this.createIndexSql(table, index);
|
|
764
|
+
await this.executeQueries(up, down);
|
|
765
|
+
table.removeIndex(index);
|
|
766
|
+
}
|
|
1414
767
|
/**
|
|
1415
768
|
* Drops an indices from the table.
|
|
1416
769
|
*/
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
return tslib_1.__generator(this, function (_a) {
|
|
1422
|
-
switch (_a.label) {
|
|
1423
|
-
case 0:
|
|
1424
|
-
promises = indices.map(function (index) {
|
|
1425
|
-
return _this.dropIndex(tableOrName, index);
|
|
1426
|
-
});
|
|
1427
|
-
return [4 /*yield*/, Promise.all(promises)];
|
|
1428
|
-
case 1:
|
|
1429
|
-
_a.sent();
|
|
1430
|
-
return [2 /*return*/];
|
|
1431
|
-
}
|
|
1432
|
-
});
|
|
1433
|
-
});
|
|
1434
|
-
};
|
|
770
|
+
async dropIndices(tableOrName, indices) {
|
|
771
|
+
const promises = indices.map((index) => this.dropIndex(tableOrName, index));
|
|
772
|
+
await Promise.all(promises);
|
|
773
|
+
}
|
|
1435
774
|
/**
|
|
1436
775
|
* Clears all table contents.
|
|
1437
776
|
* Note: this operation uses SQL's TRUNCATE query which cannot be reverted in transactions.
|
|
1438
777
|
*/
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
switch (_a.label) {
|
|
1443
|
-
case 0: return [4 /*yield*/, this.query("DELETE FROM ".concat(this.escapePath(tableName)))];
|
|
1444
|
-
case 1:
|
|
1445
|
-
_a.sent();
|
|
1446
|
-
return [2 /*return*/];
|
|
1447
|
-
}
|
|
1448
|
-
});
|
|
1449
|
-
});
|
|
1450
|
-
};
|
|
778
|
+
async clearTable(tableName) {
|
|
779
|
+
await this.query(`DELETE FROM ${this.escapePath(tableName)}`);
|
|
780
|
+
}
|
|
1451
781
|
/**
|
|
1452
782
|
* Removes all tables from the currently connected database.
|
|
1453
783
|
*/
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
dropTableQueries = _a.sent();
|
|
1493
|
-
return [4 /*yield*/, Promise.all(dropTableQueries.map(function (q) { return _this.query(q["query"]); }))];
|
|
1494
|
-
case 7:
|
|
1495
|
-
_a.sent();
|
|
1496
|
-
if (!!isAnotherTransactionActive) return [3 /*break*/, 9];
|
|
1497
|
-
return [4 /*yield*/, this.commitTransaction()];
|
|
1498
|
-
case 8:
|
|
1499
|
-
_a.sent();
|
|
1500
|
-
_a.label = 9;
|
|
1501
|
-
case 9: return [3 /*break*/, 18];
|
|
1502
|
-
case 10:
|
|
1503
|
-
error_2 = _a.sent();
|
|
1504
|
-
_a.label = 11;
|
|
1505
|
-
case 11:
|
|
1506
|
-
_a.trys.push([11, 14, , 15]);
|
|
1507
|
-
if (!!isAnotherTransactionActive) return [3 /*break*/, 13];
|
|
1508
|
-
return [4 /*yield*/, this.rollbackTransaction()];
|
|
1509
|
-
case 12:
|
|
1510
|
-
_a.sent();
|
|
1511
|
-
_a.label = 13;
|
|
1512
|
-
case 13: return [3 /*break*/, 15];
|
|
1513
|
-
case 14:
|
|
1514
|
-
rollbackError_1 = _a.sent();
|
|
1515
|
-
return [3 /*break*/, 15];
|
|
1516
|
-
case 15: throw error_2;
|
|
1517
|
-
case 16: return [4 /*yield*/, this.query("PRAGMA foreign_keys = ON")];
|
|
1518
|
-
case 17:
|
|
1519
|
-
_a.sent();
|
|
1520
|
-
return [7 /*endfinally*/];
|
|
1521
|
-
case 18: return [2 /*return*/];
|
|
1522
|
-
}
|
|
1523
|
-
});
|
|
1524
|
-
});
|
|
1525
|
-
};
|
|
784
|
+
async clearDatabase(database) {
|
|
785
|
+
let dbPath = undefined;
|
|
786
|
+
if (database &&
|
|
787
|
+
this.driver.getAttachedDatabaseHandleByRelativePath(database)) {
|
|
788
|
+
dbPath =
|
|
789
|
+
this.driver.getAttachedDatabaseHandleByRelativePath(database);
|
|
790
|
+
}
|
|
791
|
+
await this.query(`PRAGMA foreign_keys = OFF`);
|
|
792
|
+
const isAnotherTransactionActive = this.isTransactionActive;
|
|
793
|
+
if (!isAnotherTransactionActive)
|
|
794
|
+
await this.startTransaction();
|
|
795
|
+
try {
|
|
796
|
+
const selectViewDropsQuery = dbPath
|
|
797
|
+
? `SELECT 'DROP VIEW "${dbPath}"."' || name || '";' as query FROM "${dbPath}"."sqlite_master" WHERE "type" = 'view'`
|
|
798
|
+
: `SELECT 'DROP VIEW "' || name || '";' as query FROM "sqlite_master" WHERE "type" = 'view'`;
|
|
799
|
+
const dropViewQueries = await this.query(selectViewDropsQuery);
|
|
800
|
+
await Promise.all(dropViewQueries.map((q) => this.query(q["query"])));
|
|
801
|
+
const selectTableDropsQuery = dbPath
|
|
802
|
+
? `SELECT 'DROP TABLE "${dbPath}"."' || name || '";' as query FROM "${dbPath}"."sqlite_master" WHERE "type" = 'table' AND "name" != 'sqlite_sequence'`
|
|
803
|
+
: `SELECT 'DROP TABLE "' || name || '";' as query FROM "sqlite_master" WHERE "type" = 'table' AND "name" != 'sqlite_sequence'`;
|
|
804
|
+
const dropTableQueries = await this.query(selectTableDropsQuery);
|
|
805
|
+
await Promise.all(dropTableQueries.map((q) => this.query(q["query"])));
|
|
806
|
+
if (!isAnotherTransactionActive)
|
|
807
|
+
await this.commitTransaction();
|
|
808
|
+
}
|
|
809
|
+
catch (error) {
|
|
810
|
+
try {
|
|
811
|
+
// we throw original error even if rollback thrown an error
|
|
812
|
+
if (!isAnotherTransactionActive)
|
|
813
|
+
await this.rollbackTransaction();
|
|
814
|
+
}
|
|
815
|
+
catch (rollbackError) { }
|
|
816
|
+
throw error;
|
|
817
|
+
}
|
|
818
|
+
finally {
|
|
819
|
+
await this.query(`PRAGMA foreign_keys = ON`);
|
|
820
|
+
}
|
|
821
|
+
}
|
|
1526
822
|
// -------------------------------------------------------------------------
|
|
1527
823
|
// Protected Methods
|
|
1528
824
|
// -------------------------------------------------------------------------
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
return
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
return [4 /*yield*/, this.query(query)];
|
|
1550
|
-
case 2:
|
|
1551
|
-
dbViews = _a.sent();
|
|
1552
|
-
return [2 /*return*/, dbViews.map(function (dbView) {
|
|
1553
|
-
var view = new View_1.View();
|
|
1554
|
-
view.name = dbView["name"];
|
|
1555
|
-
view.expression = dbView["value"];
|
|
1556
|
-
return view;
|
|
1557
|
-
})];
|
|
1558
|
-
}
|
|
1559
|
-
});
|
|
1560
|
-
});
|
|
1561
|
-
};
|
|
1562
|
-
AbstractSqliteQueryRunner.prototype.loadTableRecords = function (tablePath, tableOrIndex) {
|
|
1563
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1564
|
-
var database, _a, schema, tableName, res;
|
|
1565
|
-
return tslib_1.__generator(this, function (_b) {
|
|
1566
|
-
switch (_b.label) {
|
|
1567
|
-
case 0:
|
|
1568
|
-
database = undefined;
|
|
1569
|
-
_a = tslib_1.__read(this.splitTablePath(tablePath), 2), schema = _a[0], tableName = _a[1];
|
|
1570
|
-
if (schema &&
|
|
1571
|
-
this.driver.getAttachedDatabasePathRelativeByHandle(schema)) {
|
|
1572
|
-
database =
|
|
1573
|
-
this.driver.getAttachedDatabasePathRelativeByHandle(schema);
|
|
1574
|
-
}
|
|
1575
|
-
return [4 /*yield*/, this.query("SELECT ".concat(database ? "'".concat(database, "'") : null, " as database, ").concat(schema ? "'".concat(schema, "'") : null, " as schema, * FROM ").concat(schema ? "\"".concat(schema, "\".") : "").concat(this.escapePath("sqlite_master"), " WHERE \"type\" = '").concat(tableOrIndex, "' AND \"").concat(tableOrIndex === "table" ? "name" : "tbl_name", "\" IN ('").concat(tableName, "')"))];
|
|
1576
|
-
case 1:
|
|
1577
|
-
res = _b.sent();
|
|
1578
|
-
return [2 /*return*/, res];
|
|
1579
|
-
}
|
|
1580
|
-
});
|
|
1581
|
-
});
|
|
1582
|
-
};
|
|
1583
|
-
AbstractSqliteQueryRunner.prototype.loadPragmaRecords = function (tablePath, pragma) {
|
|
1584
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
1585
|
-
var _a, tableName, res;
|
|
1586
|
-
return tslib_1.__generator(this, function (_b) {
|
|
1587
|
-
switch (_b.label) {
|
|
1588
|
-
case 0:
|
|
1589
|
-
_a = tslib_1.__read(this.splitTablePath(tablePath), 2), tableName = _a[1];
|
|
1590
|
-
return [4 /*yield*/, this.query("PRAGMA ".concat(pragma, "(\"").concat(tableName, "\")"))];
|
|
1591
|
-
case 1:
|
|
1592
|
-
res = _b.sent();
|
|
1593
|
-
return [2 /*return*/, res];
|
|
1594
|
-
}
|
|
1595
|
-
});
|
|
825
|
+
async loadViews(viewNames) {
|
|
826
|
+
const hasTable = await this.hasTable(this.getTypeormMetadataTableName());
|
|
827
|
+
if (!hasTable) {
|
|
828
|
+
return [];
|
|
829
|
+
}
|
|
830
|
+
if (!viewNames) {
|
|
831
|
+
viewNames = [];
|
|
832
|
+
}
|
|
833
|
+
const viewNamesString = viewNames
|
|
834
|
+
.map((name) => "'" + name + "'")
|
|
835
|
+
.join(", ");
|
|
836
|
+
let query = `SELECT "t".* FROM "${this.getTypeormMetadataTableName()}" "t" INNER JOIN "sqlite_master" s ON "s"."name" = "t"."name" AND "s"."type" = 'view' WHERE "t"."type" = '${MetadataTableType_1.MetadataTableType.VIEW}'`;
|
|
837
|
+
if (viewNamesString.length > 0)
|
|
838
|
+
query += ` AND "t"."name" IN (${viewNamesString})`;
|
|
839
|
+
const dbViews = await this.query(query);
|
|
840
|
+
return dbViews.map((dbView) => {
|
|
841
|
+
const view = new View_1.View();
|
|
842
|
+
view.name = dbView["name"];
|
|
843
|
+
view.expression = dbView["value"];
|
|
844
|
+
return view;
|
|
1596
845
|
});
|
|
1597
|
-
}
|
|
846
|
+
}
|
|
847
|
+
async loadTableRecords(tablePath, tableOrIndex) {
|
|
848
|
+
let database = undefined;
|
|
849
|
+
const [schema, tableName] = this.splitTablePath(tablePath);
|
|
850
|
+
if (schema &&
|
|
851
|
+
this.driver.getAttachedDatabasePathRelativeByHandle(schema)) {
|
|
852
|
+
database =
|
|
853
|
+
this.driver.getAttachedDatabasePathRelativeByHandle(schema);
|
|
854
|
+
}
|
|
855
|
+
const res = await this.query(`SELECT ${database ? `'${database}'` : null} as database, ${schema ? `'${schema}'` : null} as schema, * FROM ${schema ? `"${schema}".` : ""}${this.escapePath(`sqlite_master`)} WHERE "type" = '${tableOrIndex}' AND "${tableOrIndex === "table" ? "name" : "tbl_name"}" IN ('${tableName}')`);
|
|
856
|
+
return res;
|
|
857
|
+
}
|
|
858
|
+
async loadPragmaRecords(tablePath, pragma) {
|
|
859
|
+
const [, tableName] = this.splitTablePath(tablePath);
|
|
860
|
+
const res = await this.query(`PRAGMA ${pragma}("${tableName}")`);
|
|
861
|
+
return res;
|
|
862
|
+
}
|
|
1598
863
|
/**
|
|
1599
864
|
* Loads all tables (with given names) from the database and creates a Table from them.
|
|
1600
865
|
*/
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
866
|
+
async loadTables(tableNames) {
|
|
867
|
+
// if no tables given then no need to proceed
|
|
868
|
+
if (tableNames && tableNames.length === 0) {
|
|
869
|
+
return [];
|
|
870
|
+
}
|
|
871
|
+
let dbTables = [];
|
|
872
|
+
let dbIndicesDef;
|
|
873
|
+
if (!tableNames) {
|
|
874
|
+
const tablesSql = `SELECT * FROM "sqlite_master" WHERE "type" = 'table'`;
|
|
875
|
+
dbTables.push(...(await this.query(tablesSql)));
|
|
876
|
+
const tableNamesString = dbTables
|
|
877
|
+
.map(({ name }) => `'${name}'`)
|
|
878
|
+
.join(", ");
|
|
879
|
+
dbIndicesDef = await this.query(`SELECT * FROM "sqlite_master" WHERE "type" = 'index' AND "tbl_name" IN (${tableNamesString})`);
|
|
880
|
+
}
|
|
881
|
+
else {
|
|
882
|
+
dbTables = (await Promise.all(tableNames.map((tableName) => this.loadTableRecords(tableName, "table"))))
|
|
883
|
+
.reduce((acc, res) => [...acc, ...res], [])
|
|
884
|
+
.filter(Boolean);
|
|
885
|
+
dbIndicesDef = (await Promise.all((tableNames ?? []).map((tableName) => this.loadTableRecords(tableName, "index"))))
|
|
886
|
+
.reduce((acc, res) => [...acc, ...res], [])
|
|
887
|
+
.filter(Boolean);
|
|
888
|
+
}
|
|
889
|
+
// if tables were not found in the db, no need to proceed
|
|
890
|
+
if (dbTables.length === 0) {
|
|
891
|
+
return [];
|
|
892
|
+
}
|
|
893
|
+
// create table schemas for loaded tables
|
|
894
|
+
return Promise.all(dbTables.map(async (dbTable) => {
|
|
895
|
+
const tablePath = dbTable["database"] &&
|
|
896
|
+
this.driver.getAttachedDatabaseHandleByRelativePath(dbTable["database"])
|
|
897
|
+
? `${this.driver.getAttachedDatabaseHandleByRelativePath(dbTable["database"])}.${dbTable["name"]}`
|
|
898
|
+
: dbTable["name"];
|
|
899
|
+
const sql = dbTable["sql"];
|
|
900
|
+
const withoutRowid = sql.includes("WITHOUT ROWID");
|
|
901
|
+
const table = new Table_1.Table({ name: tablePath, withoutRowid });
|
|
902
|
+
// load columns and indices
|
|
903
|
+
const [dbColumns, dbIndices, dbForeignKeys] = await Promise.all([
|
|
904
|
+
this.loadPragmaRecords(tablePath, `table_xinfo`),
|
|
905
|
+
this.loadPragmaRecords(tablePath, `index_list`),
|
|
906
|
+
this.loadPragmaRecords(tablePath, `foreign_key_list`),
|
|
907
|
+
]);
|
|
908
|
+
// find column name with auto increment
|
|
909
|
+
let autoIncrementColumnName = undefined;
|
|
910
|
+
const tableSql = dbTable["sql"];
|
|
911
|
+
let autoIncrementIndex = tableSql
|
|
912
|
+
.toUpperCase()
|
|
913
|
+
.indexOf("AUTOINCREMENT");
|
|
914
|
+
if (autoIncrementIndex !== -1) {
|
|
915
|
+
autoIncrementColumnName = tableSql.substr(0, autoIncrementIndex);
|
|
916
|
+
const comma = autoIncrementColumnName.lastIndexOf(",");
|
|
917
|
+
const bracket = autoIncrementColumnName.lastIndexOf("(");
|
|
918
|
+
if (comma !== -1) {
|
|
919
|
+
autoIncrementColumnName =
|
|
920
|
+
autoIncrementColumnName.substr(comma);
|
|
921
|
+
autoIncrementColumnName =
|
|
922
|
+
autoIncrementColumnName.substr(0, autoIncrementColumnName.lastIndexOf('"'));
|
|
923
|
+
autoIncrementColumnName =
|
|
924
|
+
autoIncrementColumnName.substr(autoIncrementColumnName.indexOf('"') + 1);
|
|
925
|
+
}
|
|
926
|
+
else if (bracket !== -1) {
|
|
927
|
+
autoIncrementColumnName =
|
|
928
|
+
autoIncrementColumnName.substr(bracket);
|
|
929
|
+
autoIncrementColumnName =
|
|
930
|
+
autoIncrementColumnName.substr(0, autoIncrementColumnName.lastIndexOf('"'));
|
|
931
|
+
autoIncrementColumnName =
|
|
932
|
+
autoIncrementColumnName.substr(autoIncrementColumnName.indexOf('"') + 1);
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
// create columns from the loaded columns
|
|
936
|
+
table.columns = await Promise.all(dbColumns.map(async (dbColumn) => {
|
|
937
|
+
const tableColumn = new TableColumn_1.TableColumn();
|
|
938
|
+
tableColumn.name = dbColumn["name"];
|
|
939
|
+
tableColumn.type = dbColumn["type"].toLowerCase();
|
|
940
|
+
tableColumn.default =
|
|
941
|
+
dbColumn["dflt_value"] !== null &&
|
|
942
|
+
dbColumn["dflt_value"] !== undefined
|
|
943
|
+
? dbColumn["dflt_value"]
|
|
944
|
+
: undefined;
|
|
945
|
+
tableColumn.isNullable = dbColumn["notnull"] === 0;
|
|
946
|
+
// primary keys are numbered starting with 1, columns that aren't primary keys are marked with 0
|
|
947
|
+
tableColumn.isPrimary = dbColumn["pk"] > 0;
|
|
948
|
+
tableColumn.comment = ""; // SQLite does not support column comments
|
|
949
|
+
tableColumn.isGenerated =
|
|
950
|
+
autoIncrementColumnName === dbColumn["name"];
|
|
951
|
+
if (tableColumn.isGenerated) {
|
|
952
|
+
tableColumn.generationStrategy = "increment";
|
|
953
|
+
}
|
|
954
|
+
if (dbColumn["hidden"] === 2 ||
|
|
955
|
+
dbColumn["hidden"] === 3) {
|
|
956
|
+
tableColumn.generatedType =
|
|
957
|
+
dbColumn["hidden"] === 2 ? "VIRTUAL" : "STORED";
|
|
958
|
+
const asExpressionQuery = await this.selectTypeormMetadataSql({
|
|
959
|
+
table: table.name,
|
|
960
|
+
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
961
|
+
name: tableColumn.name,
|
|
962
|
+
});
|
|
963
|
+
const results = await this.query(asExpressionQuery.query, asExpressionQuery.parameters);
|
|
964
|
+
if (results[0] && results[0].value) {
|
|
965
|
+
tableColumn.asExpression = results[0].value;
|
|
966
|
+
}
|
|
967
|
+
else {
|
|
968
|
+
tableColumn.asExpression = "";
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
if (tableColumn.type === "varchar") {
|
|
972
|
+
// Check if this is an enum
|
|
973
|
+
const enumMatch = sql.match(new RegExp('"(' +
|
|
974
|
+
tableColumn.name +
|
|
975
|
+
")\" varchar CHECK\\s*\\(\\s*\"\\1\"\\s+IN\\s*\\(('[^']+'(?:\\s*,\\s*'[^']+')+)\\s*\\)\\s*\\)"));
|
|
976
|
+
if (enumMatch) {
|
|
977
|
+
// This is an enum
|
|
978
|
+
tableColumn.enum = enumMatch[2]
|
|
979
|
+
.substr(1, enumMatch[2].length - 2)
|
|
980
|
+
.split("','");
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
// parse datatype and attempt to retrieve length, precision and scale
|
|
984
|
+
let pos = tableColumn.type.indexOf("(");
|
|
985
|
+
if (pos !== -1) {
|
|
986
|
+
const fullType = tableColumn.type;
|
|
987
|
+
let dataType = fullType.substr(0, pos);
|
|
988
|
+
if (!!this.driver.withLengthColumnTypes.find((col) => col === dataType)) {
|
|
989
|
+
let len = parseInt(fullType.substring(pos + 1, fullType.length - 1));
|
|
990
|
+
if (len) {
|
|
991
|
+
tableColumn.length = len.toString();
|
|
992
|
+
tableColumn.type = dataType; // remove the length part from the datatype
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
if (!!this.driver.withPrecisionColumnTypes.find((col) => col === dataType)) {
|
|
996
|
+
const re = new RegExp(`^${dataType}\\((\\d+),?\\s?(\\d+)?\\)`);
|
|
997
|
+
const matches = fullType.match(re);
|
|
998
|
+
if (matches && matches[1]) {
|
|
999
|
+
tableColumn.precision = +matches[1];
|
|
1611
1000
|
}
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
_c = [dbTables];
|
|
1617
|
-
_d = [[]];
|
|
1618
|
-
return [4 /*yield*/, this.query(tablesSql)];
|
|
1619
|
-
case 1:
|
|
1620
|
-
_b.apply(_a, _c.concat([tslib_1.__spreadArray.apply(void 0, _d.concat([tslib_1.__read.apply(void 0, [(_e.sent())]), false]))]));
|
|
1621
|
-
tableNamesString = dbTables
|
|
1622
|
-
.map(function (_a) {
|
|
1623
|
-
var name = _a.name;
|
|
1624
|
-
return "'".concat(name, "'");
|
|
1625
|
-
})
|
|
1626
|
-
.join(", ");
|
|
1627
|
-
return [4 /*yield*/, this.query("SELECT * FROM \"sqlite_master\" WHERE \"type\" = 'index' AND \"tbl_name\" IN (".concat(tableNamesString, ")"))];
|
|
1628
|
-
case 2:
|
|
1629
|
-
dbIndicesDef = _e.sent();
|
|
1630
|
-
return [3 /*break*/, 6];
|
|
1631
|
-
case 3: return [4 /*yield*/, Promise.all(tableNames.map(function (tableName) {
|
|
1632
|
-
return _this.loadTableRecords(tableName, "table");
|
|
1633
|
-
}))];
|
|
1634
|
-
case 4:
|
|
1635
|
-
dbTables = (_e.sent())
|
|
1636
|
-
.reduce(function (acc, res) { return tslib_1.__spreadArray(tslib_1.__spreadArray([], tslib_1.__read(acc), false), tslib_1.__read(res), false); }, [])
|
|
1637
|
-
.filter(Boolean);
|
|
1638
|
-
return [4 /*yield*/, Promise.all((tableNames !== null && tableNames !== void 0 ? tableNames : []).map(function (tableName) {
|
|
1639
|
-
return _this.loadTableRecords(tableName, "index");
|
|
1640
|
-
}))];
|
|
1641
|
-
case 5:
|
|
1642
|
-
dbIndicesDef = (_e.sent())
|
|
1643
|
-
.reduce(function (acc, res) { return tslib_1.__spreadArray(tslib_1.__spreadArray([], tslib_1.__read(acc), false), tslib_1.__read(res), false); }, [])
|
|
1644
|
-
.filter(Boolean);
|
|
1645
|
-
_e.label = 6;
|
|
1646
|
-
case 6:
|
|
1647
|
-
// if tables were not found in the db, no need to proceed
|
|
1648
|
-
if (dbTables.length === 0) {
|
|
1649
|
-
return [2 /*return*/, []];
|
|
1001
|
+
if (!!this.driver.withScaleColumnTypes.find((col) => col === dataType)) {
|
|
1002
|
+
if (matches && matches[2]) {
|
|
1003
|
+
tableColumn.scale = +matches[2];
|
|
1004
|
+
}
|
|
1650
1005
|
}
|
|
1651
|
-
//
|
|
1652
|
-
|
|
1653
|
-
var tablePath, sql, withoutRowid, table, _a, dbColumns, dbIndices, dbForeignKeys, autoIncrementColumnName, tableSql, autoIncrementIndex, comma, bracket, _b, fkResult, fkMappings, fkRegex, tableForeignKeyConstraints, uniqueRegexResult, uniqueMappings, uniqueRegex, tableUniquePromises, _c, result, regexp, indicesPromises, indices;
|
|
1654
|
-
var _this = this;
|
|
1655
|
-
return tslib_1.__generator(this, function (_d) {
|
|
1656
|
-
switch (_d.label) {
|
|
1657
|
-
case 0:
|
|
1658
|
-
tablePath = dbTable["database"] &&
|
|
1659
|
-
this.driver.getAttachedDatabaseHandleByRelativePath(dbTable["database"])
|
|
1660
|
-
? "".concat(this.driver.getAttachedDatabaseHandleByRelativePath(dbTable["database"]), ".").concat(dbTable["name"])
|
|
1661
|
-
: dbTable["name"];
|
|
1662
|
-
sql = dbTable["sql"];
|
|
1663
|
-
withoutRowid = sql.includes("WITHOUT ROWID");
|
|
1664
|
-
table = new Table_1.Table({ name: tablePath, withoutRowid: withoutRowid });
|
|
1665
|
-
return [4 /*yield*/, Promise.all([
|
|
1666
|
-
this.loadPragmaRecords(tablePath, "table_xinfo"),
|
|
1667
|
-
this.loadPragmaRecords(tablePath, "index_list"),
|
|
1668
|
-
this.loadPragmaRecords(tablePath, "foreign_key_list"),
|
|
1669
|
-
])
|
|
1670
|
-
// find column name with auto increment
|
|
1671
|
-
];
|
|
1672
|
-
case 1:
|
|
1673
|
-
_a = tslib_1.__read.apply(void 0, [_d.sent()
|
|
1674
|
-
// find column name with auto increment
|
|
1675
|
-
, 3]), dbColumns = _a[0], dbIndices = _a[1], dbForeignKeys = _a[2];
|
|
1676
|
-
autoIncrementColumnName = undefined;
|
|
1677
|
-
tableSql = dbTable["sql"];
|
|
1678
|
-
autoIncrementIndex = tableSql
|
|
1679
|
-
.toUpperCase()
|
|
1680
|
-
.indexOf("AUTOINCREMENT");
|
|
1681
|
-
if (autoIncrementIndex !== -1) {
|
|
1682
|
-
autoIncrementColumnName = tableSql.substr(0, autoIncrementIndex);
|
|
1683
|
-
comma = autoIncrementColumnName.lastIndexOf(",");
|
|
1684
|
-
bracket = autoIncrementColumnName.lastIndexOf("(");
|
|
1685
|
-
if (comma !== -1) {
|
|
1686
|
-
autoIncrementColumnName =
|
|
1687
|
-
autoIncrementColumnName.substr(comma);
|
|
1688
|
-
autoIncrementColumnName =
|
|
1689
|
-
autoIncrementColumnName.substr(0, autoIncrementColumnName.lastIndexOf('"'));
|
|
1690
|
-
autoIncrementColumnName =
|
|
1691
|
-
autoIncrementColumnName.substr(autoIncrementColumnName.indexOf('"') + 1);
|
|
1692
|
-
}
|
|
1693
|
-
else if (bracket !== -1) {
|
|
1694
|
-
autoIncrementColumnName =
|
|
1695
|
-
autoIncrementColumnName.substr(bracket);
|
|
1696
|
-
autoIncrementColumnName =
|
|
1697
|
-
autoIncrementColumnName.substr(0, autoIncrementColumnName.lastIndexOf('"'));
|
|
1698
|
-
autoIncrementColumnName =
|
|
1699
|
-
autoIncrementColumnName.substr(autoIncrementColumnName.indexOf('"') + 1);
|
|
1700
|
-
}
|
|
1701
|
-
}
|
|
1702
|
-
// create columns from the loaded columns
|
|
1703
|
-
_b = table;
|
|
1704
|
-
return [4 /*yield*/, Promise.all(dbColumns.map(function (dbColumn) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
1705
|
-
var tableColumn, asExpressionQuery, results, enumMatch, pos, fullType, dataType_1, len, re, matches;
|
|
1706
|
-
return tslib_1.__generator(this, function (_a) {
|
|
1707
|
-
switch (_a.label) {
|
|
1708
|
-
case 0:
|
|
1709
|
-
tableColumn = new TableColumn_1.TableColumn();
|
|
1710
|
-
tableColumn.name = dbColumn["name"];
|
|
1711
|
-
tableColumn.type = dbColumn["type"].toLowerCase();
|
|
1712
|
-
tableColumn.default =
|
|
1713
|
-
dbColumn["dflt_value"] !== null &&
|
|
1714
|
-
dbColumn["dflt_value"] !== undefined
|
|
1715
|
-
? dbColumn["dflt_value"]
|
|
1716
|
-
: undefined;
|
|
1717
|
-
tableColumn.isNullable = dbColumn["notnull"] === 0;
|
|
1718
|
-
// primary keys are numbered starting with 1, columns that aren't primary keys are marked with 0
|
|
1719
|
-
tableColumn.isPrimary = dbColumn["pk"] > 0;
|
|
1720
|
-
tableColumn.comment = ""; // SQLite does not support column comments
|
|
1721
|
-
tableColumn.isGenerated =
|
|
1722
|
-
autoIncrementColumnName === dbColumn["name"];
|
|
1723
|
-
if (tableColumn.isGenerated) {
|
|
1724
|
-
tableColumn.generationStrategy = "increment";
|
|
1725
|
-
}
|
|
1726
|
-
if (!(dbColumn["hidden"] === 2 ||
|
|
1727
|
-
dbColumn["hidden"] === 3)) return [3 /*break*/, 3];
|
|
1728
|
-
tableColumn.generatedType =
|
|
1729
|
-
dbColumn["hidden"] === 2 ? "VIRTUAL" : "STORED";
|
|
1730
|
-
return [4 /*yield*/, this.selectTypeormMetadataSql({
|
|
1731
|
-
table: table.name,
|
|
1732
|
-
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
1733
|
-
name: tableColumn.name,
|
|
1734
|
-
})];
|
|
1735
|
-
case 1:
|
|
1736
|
-
asExpressionQuery = _a.sent();
|
|
1737
|
-
return [4 /*yield*/, this.query(asExpressionQuery.query, asExpressionQuery.parameters)];
|
|
1738
|
-
case 2:
|
|
1739
|
-
results = _a.sent();
|
|
1740
|
-
if (results[0] && results[0].value) {
|
|
1741
|
-
tableColumn.asExpression = results[0].value;
|
|
1742
|
-
}
|
|
1743
|
-
else {
|
|
1744
|
-
tableColumn.asExpression = "";
|
|
1745
|
-
}
|
|
1746
|
-
_a.label = 3;
|
|
1747
|
-
case 3:
|
|
1748
|
-
if (tableColumn.type === "varchar") {
|
|
1749
|
-
enumMatch = sql.match(new RegExp('"(' +
|
|
1750
|
-
tableColumn.name +
|
|
1751
|
-
")\" varchar CHECK\\s*\\(\\s*\"\\1\"\\s+IN\\s*\\(('[^']+'(?:\\s*,\\s*'[^']+')+)\\s*\\)\\s*\\)"));
|
|
1752
|
-
if (enumMatch) {
|
|
1753
|
-
// This is an enum
|
|
1754
|
-
tableColumn.enum = enumMatch[2]
|
|
1755
|
-
.substr(1, enumMatch[2].length - 2)
|
|
1756
|
-
.split("','");
|
|
1757
|
-
}
|
|
1758
|
-
}
|
|
1759
|
-
pos = tableColumn.type.indexOf("(");
|
|
1760
|
-
if (pos !== -1) {
|
|
1761
|
-
fullType = tableColumn.type;
|
|
1762
|
-
dataType_1 = fullType.substr(0, pos);
|
|
1763
|
-
if (!!this.driver.withLengthColumnTypes.find(function (col) { return col === dataType_1; })) {
|
|
1764
|
-
len = parseInt(fullType.substring(pos + 1, fullType.length - 1));
|
|
1765
|
-
if (len) {
|
|
1766
|
-
tableColumn.length = len.toString();
|
|
1767
|
-
tableColumn.type = dataType_1; // remove the length part from the datatype
|
|
1768
|
-
}
|
|
1769
|
-
}
|
|
1770
|
-
if (!!this.driver.withPrecisionColumnTypes.find(function (col) { return col === dataType_1; })) {
|
|
1771
|
-
re = new RegExp("^".concat(dataType_1, "\\((\\d+),?\\s?(\\d+)?\\)"));
|
|
1772
|
-
matches = fullType.match(re);
|
|
1773
|
-
if (matches && matches[1]) {
|
|
1774
|
-
tableColumn.precision = +matches[1];
|
|
1775
|
-
}
|
|
1776
|
-
if (!!this.driver.withScaleColumnTypes.find(function (col) { return col === dataType_1; })) {
|
|
1777
|
-
if (matches && matches[2]) {
|
|
1778
|
-
tableColumn.scale = +matches[2];
|
|
1779
|
-
}
|
|
1780
|
-
}
|
|
1781
|
-
tableColumn.type = dataType_1; // remove the precision/scale part from the datatype
|
|
1782
|
-
}
|
|
1783
|
-
}
|
|
1784
|
-
return [2 /*return*/, tableColumn];
|
|
1785
|
-
}
|
|
1786
|
-
});
|
|
1787
|
-
}); }))
|
|
1788
|
-
// find foreign key constraints from CREATE TABLE sql
|
|
1789
|
-
];
|
|
1790
|
-
case 2:
|
|
1791
|
-
// create columns from the loaded columns
|
|
1792
|
-
_b.columns = _d.sent();
|
|
1793
|
-
fkMappings = [];
|
|
1794
|
-
fkRegex = /CONSTRAINT "([^"]*)" FOREIGN KEY ?\((.*?)\) REFERENCES "([^"]*)"/g;
|
|
1795
|
-
while ((fkResult = fkRegex.exec(sql)) !== null) {
|
|
1796
|
-
fkMappings.push({
|
|
1797
|
-
name: fkResult[1],
|
|
1798
|
-
columns: fkResult[2]
|
|
1799
|
-
.substr(1, fkResult[2].length - 2)
|
|
1800
|
-
.split("\", \""),
|
|
1801
|
-
referencedTableName: fkResult[3],
|
|
1802
|
-
});
|
|
1803
|
-
}
|
|
1804
|
-
tableForeignKeyConstraints = OrmUtils_1.OrmUtils.uniq(dbForeignKeys, function (dbForeignKey) { return dbForeignKey["id"]; });
|
|
1805
|
-
table.foreignKeys = tableForeignKeyConstraints.map(function (foreignKey) {
|
|
1806
|
-
var ownForeignKeys = dbForeignKeys.filter(function (dbForeignKey) {
|
|
1807
|
-
return dbForeignKey["id"] === foreignKey["id"] &&
|
|
1808
|
-
dbForeignKey["table"] === foreignKey["table"];
|
|
1809
|
-
});
|
|
1810
|
-
var columnNames = ownForeignKeys.map(function (dbForeignKey) { return dbForeignKey["from"]; });
|
|
1811
|
-
var referencedColumnNames = ownForeignKeys.map(function (dbForeignKey) { return dbForeignKey["to"]; });
|
|
1812
|
-
// find related foreign key mapping
|
|
1813
|
-
var fkMapping = fkMappings.find(function (it) {
|
|
1814
|
-
return it.referencedTableName ===
|
|
1815
|
-
foreignKey["table"] &&
|
|
1816
|
-
it.columns.every(function (column) {
|
|
1817
|
-
return columnNames.indexOf(column) !== -1;
|
|
1818
|
-
});
|
|
1819
|
-
});
|
|
1820
|
-
return new TableForeignKey_1.TableForeignKey({
|
|
1821
|
-
name: fkMapping.name,
|
|
1822
|
-
columnNames: columnNames,
|
|
1823
|
-
referencedTableName: foreignKey["table"],
|
|
1824
|
-
referencedColumnNames: referencedColumnNames,
|
|
1825
|
-
onDelete: foreignKey["on_delete"],
|
|
1826
|
-
onUpdate: foreignKey["on_update"],
|
|
1827
|
-
});
|
|
1828
|
-
});
|
|
1829
|
-
uniqueMappings = [];
|
|
1830
|
-
uniqueRegex = /CONSTRAINT "([^"]*)" UNIQUE ?\((.*?)\)/g;
|
|
1831
|
-
while ((uniqueRegexResult = uniqueRegex.exec(sql)) !== null) {
|
|
1832
|
-
uniqueMappings.push({
|
|
1833
|
-
name: uniqueRegexResult[1],
|
|
1834
|
-
columns: uniqueRegexResult[2]
|
|
1835
|
-
.substr(1, uniqueRegexResult[2].length - 2)
|
|
1836
|
-
.split("\", \""),
|
|
1837
|
-
});
|
|
1838
|
-
}
|
|
1839
|
-
tableUniquePromises = dbIndices
|
|
1840
|
-
.filter(function (dbIndex) { return dbIndex["origin"] === "u"; })
|
|
1841
|
-
.map(function (dbIndex) { return dbIndex["name"]; })
|
|
1842
|
-
.filter(function (value, index, self) { return self.indexOf(value) === index; })
|
|
1843
|
-
.map(function (dbIndexName) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
1844
|
-
var dbIndex, indexInfos, indexColumns, column, foundMapping;
|
|
1845
|
-
return tslib_1.__generator(this, function (_a) {
|
|
1846
|
-
switch (_a.label) {
|
|
1847
|
-
case 0:
|
|
1848
|
-
dbIndex = dbIndices.find(function (dbIndex) { return dbIndex["name"] === dbIndexName; });
|
|
1849
|
-
return [4 /*yield*/, this.query("PRAGMA index_info(\"".concat(dbIndex["name"], "\")"))];
|
|
1850
|
-
case 1:
|
|
1851
|
-
indexInfos = _a.sent();
|
|
1852
|
-
indexColumns = indexInfos
|
|
1853
|
-
.sort(function (indexInfo1, indexInfo2) {
|
|
1854
|
-
return parseInt(indexInfo1["seqno"]) -
|
|
1855
|
-
parseInt(indexInfo2["seqno"]);
|
|
1856
|
-
})
|
|
1857
|
-
.map(function (indexInfo) { return indexInfo["name"]; });
|
|
1858
|
-
if (indexColumns.length === 1) {
|
|
1859
|
-
column = table.columns.find(function (column) {
|
|
1860
|
-
return !!indexColumns.find(function (indexColumn) {
|
|
1861
|
-
return indexColumn === column.name;
|
|
1862
|
-
});
|
|
1863
|
-
});
|
|
1864
|
-
if (column)
|
|
1865
|
-
column.isUnique = true;
|
|
1866
|
-
}
|
|
1867
|
-
foundMapping = uniqueMappings.find(function (mapping) {
|
|
1868
|
-
return mapping.columns.every(function (column) { return indexColumns.indexOf(column) !== -1; });
|
|
1869
|
-
});
|
|
1870
|
-
return [2 /*return*/, new TableUnique_1.TableUnique({
|
|
1871
|
-
name: foundMapping
|
|
1872
|
-
? foundMapping.name
|
|
1873
|
-
: this.connection.namingStrategy.uniqueConstraintName(table, indexColumns),
|
|
1874
|
-
columnNames: indexColumns,
|
|
1875
|
-
})];
|
|
1876
|
-
}
|
|
1877
|
-
});
|
|
1878
|
-
}); });
|
|
1879
|
-
_c = table;
|
|
1880
|
-
return [4 /*yield*/, Promise.all(tableUniquePromises)];
|
|
1881
|
-
case 3:
|
|
1882
|
-
_c.uniques = (_d.sent());
|
|
1883
|
-
regexp = /CONSTRAINT "([^"]*)" CHECK ?(\(.*?\))([,]|[)]$)/g;
|
|
1884
|
-
while ((result = regexp.exec(sql)) !== null) {
|
|
1885
|
-
table.checks.push(new TableCheck_1.TableCheck({
|
|
1886
|
-
name: result[1],
|
|
1887
|
-
expression: result[2],
|
|
1888
|
-
}));
|
|
1889
|
-
}
|
|
1890
|
-
indicesPromises = dbIndices
|
|
1891
|
-
.filter(function (dbIndex) { return dbIndex["origin"] === "c"; })
|
|
1892
|
-
.map(function (dbIndex) { return dbIndex["name"]; })
|
|
1893
|
-
.filter(function (value, index, self) { return self.indexOf(value) === index; }) // unqiue
|
|
1894
|
-
.map(function (dbIndexName) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
1895
|
-
var indexDef, condition, dbIndex, indexInfos, indexColumns, dbIndexPath, isUnique;
|
|
1896
|
-
return tslib_1.__generator(this, function (_a) {
|
|
1897
|
-
switch (_a.label) {
|
|
1898
|
-
case 0:
|
|
1899
|
-
indexDef = dbIndicesDef.find(function (dbIndexDef) { return dbIndexDef["name"] === dbIndexName; });
|
|
1900
|
-
condition = /WHERE (.*)/.exec(indexDef["sql"]);
|
|
1901
|
-
dbIndex = dbIndices.find(function (dbIndex) { return dbIndex["name"] === dbIndexName; });
|
|
1902
|
-
return [4 /*yield*/, this.query("PRAGMA index_info(\"".concat(dbIndex["name"], "\")"))];
|
|
1903
|
-
case 1:
|
|
1904
|
-
indexInfos = _a.sent();
|
|
1905
|
-
indexColumns = indexInfos
|
|
1906
|
-
.sort(function (indexInfo1, indexInfo2) {
|
|
1907
|
-
return parseInt(indexInfo1["seqno"]) -
|
|
1908
|
-
parseInt(indexInfo2["seqno"]);
|
|
1909
|
-
})
|
|
1910
|
-
.map(function (indexInfo) { return indexInfo["name"]; });
|
|
1911
|
-
dbIndexPath = "".concat(dbTable["database"] ? "".concat(dbTable["database"], ".") : "").concat(dbIndex["name"]);
|
|
1912
|
-
isUnique = dbIndex["unique"] === "1" ||
|
|
1913
|
-
dbIndex["unique"] === 1;
|
|
1914
|
-
return [2 /*return*/, new TableIndex_1.TableIndex({
|
|
1915
|
-
table: table,
|
|
1916
|
-
name: dbIndexPath,
|
|
1917
|
-
columnNames: indexColumns,
|
|
1918
|
-
isUnique: isUnique,
|
|
1919
|
-
where: condition ? condition[1] : undefined,
|
|
1920
|
-
})];
|
|
1921
|
-
}
|
|
1922
|
-
});
|
|
1923
|
-
}); });
|
|
1924
|
-
return [4 /*yield*/, Promise.all(indicesPromises)];
|
|
1925
|
-
case 4:
|
|
1926
|
-
indices = _d.sent();
|
|
1927
|
-
table.indices = indices.filter(function (index) { return !!index; });
|
|
1928
|
-
return [2 /*return*/, table];
|
|
1929
|
-
}
|
|
1930
|
-
});
|
|
1931
|
-
}); }))];
|
|
1006
|
+
tableColumn.type = dataType; // remove the precision/scale part from the datatype
|
|
1007
|
+
}
|
|
1932
1008
|
}
|
|
1009
|
+
return tableColumn;
|
|
1010
|
+
}));
|
|
1011
|
+
// find foreign key constraints from CREATE TABLE sql
|
|
1012
|
+
let fkResult;
|
|
1013
|
+
const fkMappings = [];
|
|
1014
|
+
const fkRegex = /CONSTRAINT "([^"]*)" FOREIGN KEY ?\((.*?)\) REFERENCES "([^"]*)"/g;
|
|
1015
|
+
while ((fkResult = fkRegex.exec(sql)) !== null) {
|
|
1016
|
+
fkMappings.push({
|
|
1017
|
+
name: fkResult[1],
|
|
1018
|
+
columns: fkResult[2]
|
|
1019
|
+
.substr(1, fkResult[2].length - 2)
|
|
1020
|
+
.split(`", "`),
|
|
1021
|
+
referencedTableName: fkResult[3],
|
|
1022
|
+
});
|
|
1023
|
+
}
|
|
1024
|
+
// build foreign keys
|
|
1025
|
+
const tableForeignKeyConstraints = OrmUtils_1.OrmUtils.uniq(dbForeignKeys, (dbForeignKey) => dbForeignKey["id"]);
|
|
1026
|
+
table.foreignKeys = tableForeignKeyConstraints.map((foreignKey) => {
|
|
1027
|
+
const ownForeignKeys = dbForeignKeys.filter((dbForeignKey) => dbForeignKey["id"] === foreignKey["id"] &&
|
|
1028
|
+
dbForeignKey["table"] === foreignKey["table"]);
|
|
1029
|
+
const columnNames = ownForeignKeys.map((dbForeignKey) => dbForeignKey["from"]);
|
|
1030
|
+
const referencedColumnNames = ownForeignKeys.map((dbForeignKey) => dbForeignKey["to"]);
|
|
1031
|
+
// find related foreign key mapping
|
|
1032
|
+
const fkMapping = fkMappings.find((it) => it.referencedTableName ===
|
|
1033
|
+
foreignKey["table"] &&
|
|
1034
|
+
it.columns.every((column) => columnNames.indexOf(column) !== -1));
|
|
1035
|
+
return new TableForeignKey_1.TableForeignKey({
|
|
1036
|
+
name: fkMapping.name,
|
|
1037
|
+
columnNames: columnNames,
|
|
1038
|
+
referencedTableName: foreignKey["table"],
|
|
1039
|
+
referencedColumnNames: referencedColumnNames,
|
|
1040
|
+
onDelete: foreignKey["on_delete"],
|
|
1041
|
+
onUpdate: foreignKey["on_update"],
|
|
1042
|
+
});
|
|
1933
1043
|
});
|
|
1934
|
-
|
|
1935
|
-
|
|
1044
|
+
// find unique constraints from CREATE TABLE sql
|
|
1045
|
+
let uniqueRegexResult;
|
|
1046
|
+
const uniqueMappings = [];
|
|
1047
|
+
const uniqueRegex = /CONSTRAINT "([^"]*)" UNIQUE ?\((.*?)\)/g;
|
|
1048
|
+
while ((uniqueRegexResult = uniqueRegex.exec(sql)) !== null) {
|
|
1049
|
+
uniqueMappings.push({
|
|
1050
|
+
name: uniqueRegexResult[1],
|
|
1051
|
+
columns: uniqueRegexResult[2]
|
|
1052
|
+
.substr(1, uniqueRegexResult[2].length - 2)
|
|
1053
|
+
.split(`", "`),
|
|
1054
|
+
});
|
|
1055
|
+
}
|
|
1056
|
+
// build unique constraints
|
|
1057
|
+
const tableUniquePromises = dbIndices
|
|
1058
|
+
.filter((dbIndex) => dbIndex["origin"] === "u")
|
|
1059
|
+
.map((dbIndex) => dbIndex["name"])
|
|
1060
|
+
.filter((value, index, self) => self.indexOf(value) === index)
|
|
1061
|
+
.map(async (dbIndexName) => {
|
|
1062
|
+
const dbIndex = dbIndices.find((dbIndex) => dbIndex["name"] === dbIndexName);
|
|
1063
|
+
const indexInfos = await this.query(`PRAGMA index_info("${dbIndex["name"]}")`);
|
|
1064
|
+
const indexColumns = indexInfos
|
|
1065
|
+
.sort((indexInfo1, indexInfo2) => parseInt(indexInfo1["seqno"]) -
|
|
1066
|
+
parseInt(indexInfo2["seqno"]))
|
|
1067
|
+
.map((indexInfo) => indexInfo["name"]);
|
|
1068
|
+
if (indexColumns.length === 1) {
|
|
1069
|
+
const column = table.columns.find((column) => {
|
|
1070
|
+
return !!indexColumns.find((indexColumn) => indexColumn === column.name);
|
|
1071
|
+
});
|
|
1072
|
+
if (column)
|
|
1073
|
+
column.isUnique = true;
|
|
1074
|
+
}
|
|
1075
|
+
// find existent mapping by a column names
|
|
1076
|
+
const foundMapping = uniqueMappings.find((mapping) => {
|
|
1077
|
+
return mapping.columns.every((column) => indexColumns.indexOf(column) !== -1);
|
|
1078
|
+
});
|
|
1079
|
+
return new TableUnique_1.TableUnique({
|
|
1080
|
+
name: foundMapping
|
|
1081
|
+
? foundMapping.name
|
|
1082
|
+
: this.connection.namingStrategy.uniqueConstraintName(table, indexColumns),
|
|
1083
|
+
columnNames: indexColumns,
|
|
1084
|
+
});
|
|
1085
|
+
});
|
|
1086
|
+
table.uniques = (await Promise.all(tableUniquePromises));
|
|
1087
|
+
// build checks
|
|
1088
|
+
let result;
|
|
1089
|
+
const regexp = /CONSTRAINT "([^"]*)" CHECK ?(\(.*?\))([,]|[)]$)/g;
|
|
1090
|
+
while ((result = regexp.exec(sql)) !== null) {
|
|
1091
|
+
table.checks.push(new TableCheck_1.TableCheck({
|
|
1092
|
+
name: result[1],
|
|
1093
|
+
expression: result[2],
|
|
1094
|
+
}));
|
|
1095
|
+
}
|
|
1096
|
+
// build indices
|
|
1097
|
+
const indicesPromises = dbIndices
|
|
1098
|
+
.filter((dbIndex) => dbIndex["origin"] === "c")
|
|
1099
|
+
.map((dbIndex) => dbIndex["name"])
|
|
1100
|
+
.filter((value, index, self) => self.indexOf(value) === index) // unqiue
|
|
1101
|
+
.map(async (dbIndexName) => {
|
|
1102
|
+
const indexDef = dbIndicesDef.find((dbIndexDef) => dbIndexDef["name"] === dbIndexName);
|
|
1103
|
+
const condition = /WHERE (.*)/.exec(indexDef["sql"]);
|
|
1104
|
+
const dbIndex = dbIndices.find((dbIndex) => dbIndex["name"] === dbIndexName);
|
|
1105
|
+
const indexInfos = await this.query(`PRAGMA index_info("${dbIndex["name"]}")`);
|
|
1106
|
+
const indexColumns = indexInfos
|
|
1107
|
+
.sort((indexInfo1, indexInfo2) => parseInt(indexInfo1["seqno"]) -
|
|
1108
|
+
parseInt(indexInfo2["seqno"]))
|
|
1109
|
+
.map((indexInfo) => indexInfo["name"]);
|
|
1110
|
+
const dbIndexPath = `${dbTable["database"] ? `${dbTable["database"]}.` : ""}${dbIndex["name"]}`;
|
|
1111
|
+
const isUnique = dbIndex["unique"] === "1" ||
|
|
1112
|
+
dbIndex["unique"] === 1;
|
|
1113
|
+
return new TableIndex_1.TableIndex({
|
|
1114
|
+
table: table,
|
|
1115
|
+
name: dbIndexPath,
|
|
1116
|
+
columnNames: indexColumns,
|
|
1117
|
+
isUnique: isUnique,
|
|
1118
|
+
where: condition ? condition[1] : undefined,
|
|
1119
|
+
});
|
|
1120
|
+
});
|
|
1121
|
+
const indices = await Promise.all(indicesPromises);
|
|
1122
|
+
table.indices = indices.filter((index) => !!index);
|
|
1123
|
+
return table;
|
|
1124
|
+
}));
|
|
1125
|
+
}
|
|
1936
1126
|
/**
|
|
1937
1127
|
* Builds create table sql.
|
|
1938
1128
|
*/
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
return column.isGenerated && column.generationStrategy === "increment";
|
|
1944
|
-
});
|
|
1945
|
-
var skipPrimary = primaryColumns.length > 1;
|
|
1129
|
+
createTableSql(table, createForeignKeys, temporaryTable) {
|
|
1130
|
+
const primaryColumns = table.columns.filter((column) => column.isPrimary);
|
|
1131
|
+
const hasAutoIncrement = primaryColumns.find((column) => column.isGenerated && column.generationStrategy === "increment");
|
|
1132
|
+
const skipPrimary = primaryColumns.length > 1;
|
|
1946
1133
|
if (skipPrimary && hasAutoIncrement)
|
|
1947
|
-
throw new error_1.TypeORMError(
|
|
1948
|
-
|
|
1949
|
-
.map(
|
|
1134
|
+
throw new error_1.TypeORMError(`Sqlite does not support AUTOINCREMENT on composite primary key`);
|
|
1135
|
+
const columnDefinitions = table.columns
|
|
1136
|
+
.map((column) => this.buildCreateColumnSql(column, skipPrimary))
|
|
1950
1137
|
.join(", ");
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
?
|
|
1138
|
+
const [database] = this.splitTablePath(table.name);
|
|
1139
|
+
let sql = `CREATE TABLE ${this.escapePath(table.name)} (${columnDefinitions}`;
|
|
1140
|
+
let [databaseNew, tableName] = this.splitTablePath(table.name);
|
|
1141
|
+
const newTableName = temporaryTable
|
|
1142
|
+
? `${databaseNew ? `${databaseNew}.` : ""}${tableName.replace(/^temporary_/, "")}`
|
|
1956
1143
|
: table.name;
|
|
1957
1144
|
// need for `addColumn()` method, because it recreates table.
|
|
1958
1145
|
table.columns
|
|
1959
|
-
.filter(
|
|
1960
|
-
.forEach(
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
unique.columnNames[0] === column.name;
|
|
1964
|
-
});
|
|
1146
|
+
.filter((column) => column.isUnique)
|
|
1147
|
+
.forEach((column) => {
|
|
1148
|
+
const isUniqueExist = table.uniques.some((unique) => unique.columnNames.length === 1 &&
|
|
1149
|
+
unique.columnNames[0] === column.name);
|
|
1965
1150
|
if (!isUniqueExist)
|
|
1966
1151
|
table.uniques.push(new TableUnique_1.TableUnique({
|
|
1967
|
-
name:
|
|
1152
|
+
name: this.connection.namingStrategy.uniqueConstraintName(table, [column.name]),
|
|
1968
1153
|
columnNames: [column.name],
|
|
1969
1154
|
}));
|
|
1970
1155
|
});
|
|
1971
1156
|
if (table.uniques.length > 0) {
|
|
1972
|
-
|
|
1973
|
-
.map(
|
|
1974
|
-
|
|
1157
|
+
const uniquesSql = table.uniques
|
|
1158
|
+
.map((unique) => {
|
|
1159
|
+
const uniqueName = unique.name
|
|
1975
1160
|
? unique.name
|
|
1976
|
-
:
|
|
1977
|
-
|
|
1978
|
-
.map(
|
|
1161
|
+
: this.connection.namingStrategy.uniqueConstraintName(newTableName, unique.columnNames);
|
|
1162
|
+
const columnNames = unique.columnNames
|
|
1163
|
+
.map((columnName) => `"${columnName}"`)
|
|
1979
1164
|
.join(", ");
|
|
1980
|
-
return
|
|
1165
|
+
return `CONSTRAINT "${uniqueName}" UNIQUE (${columnNames})`;
|
|
1981
1166
|
})
|
|
1982
1167
|
.join(", ");
|
|
1983
|
-
sql +=
|
|
1168
|
+
sql += `, ${uniquesSql}`;
|
|
1984
1169
|
}
|
|
1985
1170
|
if (table.checks.length > 0) {
|
|
1986
|
-
|
|
1987
|
-
.map(
|
|
1988
|
-
|
|
1171
|
+
const checksSql = table.checks
|
|
1172
|
+
.map((check) => {
|
|
1173
|
+
const checkName = check.name
|
|
1989
1174
|
? check.name
|
|
1990
|
-
:
|
|
1991
|
-
return
|
|
1175
|
+
: this.connection.namingStrategy.checkConstraintName(newTableName, check.expression);
|
|
1176
|
+
return `CONSTRAINT "${checkName}" CHECK (${check.expression})`;
|
|
1992
1177
|
})
|
|
1993
1178
|
.join(", ");
|
|
1994
|
-
sql +=
|
|
1179
|
+
sql += `, ${checksSql}`;
|
|
1995
1180
|
}
|
|
1996
1181
|
if (table.foreignKeys.length > 0 && createForeignKeys) {
|
|
1997
|
-
|
|
1998
|
-
.filter(
|
|
1999
|
-
|
|
1182
|
+
const foreignKeysSql = table.foreignKeys
|
|
1183
|
+
.filter((fk) => {
|
|
1184
|
+
const [referencedDatabase] = this.splitTablePath(fk.referencedTableName);
|
|
2000
1185
|
if (referencedDatabase !== database) {
|
|
2001
1186
|
return false;
|
|
2002
1187
|
}
|
|
2003
1188
|
return true;
|
|
2004
1189
|
})
|
|
2005
|
-
.map(
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
.map(
|
|
1190
|
+
.map((fk) => {
|
|
1191
|
+
const [, referencedTable] = this.splitTablePath(fk.referencedTableName);
|
|
1192
|
+
const columnNames = fk.columnNames
|
|
1193
|
+
.map((columnName) => `"${columnName}"`)
|
|
2009
1194
|
.join(", ");
|
|
2010
1195
|
if (!fk.name)
|
|
2011
|
-
fk.name =
|
|
2012
|
-
|
|
2013
|
-
.map(
|
|
1196
|
+
fk.name = this.connection.namingStrategy.foreignKeyName(newTableName, fk.columnNames, this.getTablePath(fk), fk.referencedColumnNames);
|
|
1197
|
+
const referencedColumnNames = fk.referencedColumnNames
|
|
1198
|
+
.map((columnName) => `"${columnName}"`)
|
|
2014
1199
|
.join(", ");
|
|
2015
|
-
|
|
1200
|
+
let constraint = `CONSTRAINT "${fk.name}" FOREIGN KEY (${columnNames}) REFERENCES "${referencedTable}" (${referencedColumnNames})`;
|
|
2016
1201
|
if (fk.onDelete)
|
|
2017
|
-
constraint +=
|
|
1202
|
+
constraint += ` ON DELETE ${fk.onDelete}`;
|
|
2018
1203
|
if (fk.onUpdate)
|
|
2019
|
-
constraint +=
|
|
1204
|
+
constraint += ` ON UPDATE ${fk.onUpdate}`;
|
|
2020
1205
|
if (fk.deferrable)
|
|
2021
|
-
constraint +=
|
|
1206
|
+
constraint += ` DEFERRABLE ${fk.deferrable}`;
|
|
2022
1207
|
return constraint;
|
|
2023
1208
|
})
|
|
2024
1209
|
.join(", ");
|
|
2025
|
-
sql +=
|
|
1210
|
+
sql += `, ${foreignKeysSql}`;
|
|
2026
1211
|
}
|
|
2027
1212
|
if (primaryColumns.length > 1) {
|
|
2028
|
-
|
|
2029
|
-
.map(
|
|
1213
|
+
const columnNames = primaryColumns
|
|
1214
|
+
.map((column) => `"${column.name}"`)
|
|
2030
1215
|
.join(", ");
|
|
2031
|
-
sql +=
|
|
1216
|
+
sql += `, PRIMARY KEY (${columnNames})`;
|
|
2032
1217
|
}
|
|
2033
|
-
sql +=
|
|
1218
|
+
sql += `)`;
|
|
2034
1219
|
if (table.withoutRowid) {
|
|
2035
1220
|
sql += " WITHOUT ROWID";
|
|
2036
1221
|
}
|
|
2037
1222
|
return new Query_1.Query(sql);
|
|
2038
|
-
}
|
|
1223
|
+
}
|
|
2039
1224
|
/**
|
|
2040
1225
|
* Builds drop table sql.
|
|
2041
1226
|
*/
|
|
2042
|
-
|
|
2043
|
-
|
|
1227
|
+
dropTableSql(tableOrName, ifExist) {
|
|
1228
|
+
const tableName = InstanceChecker_1.InstanceChecker.isTable(tableOrName)
|
|
2044
1229
|
? tableOrName.name
|
|
2045
1230
|
: tableOrName;
|
|
2046
|
-
|
|
2047
|
-
?
|
|
2048
|
-
:
|
|
1231
|
+
const query = ifExist
|
|
1232
|
+
? `DROP TABLE IF EXISTS ${this.escapePath(tableName)}`
|
|
1233
|
+
: `DROP TABLE ${this.escapePath(tableName)}`;
|
|
2049
1234
|
return new Query_1.Query(query);
|
|
2050
|
-
}
|
|
2051
|
-
|
|
1235
|
+
}
|
|
1236
|
+
createViewSql(view) {
|
|
2052
1237
|
if (typeof view.expression === "string") {
|
|
2053
|
-
return new Query_1.Query(
|
|
1238
|
+
return new Query_1.Query(`CREATE VIEW "${view.name}" AS ${view.expression}`);
|
|
2054
1239
|
}
|
|
2055
1240
|
else {
|
|
2056
|
-
return new Query_1.Query(
|
|
1241
|
+
return new Query_1.Query(`CREATE VIEW "${view.name}" AS ${view
|
|
2057
1242
|
.expression(this.connection)
|
|
2058
|
-
.getQuery())
|
|
1243
|
+
.getQuery()}`);
|
|
2059
1244
|
}
|
|
2060
|
-
}
|
|
2061
|
-
|
|
2062
|
-
|
|
1245
|
+
}
|
|
1246
|
+
insertViewDefinitionSql(view) {
|
|
1247
|
+
const expression = typeof view.expression === "string"
|
|
2063
1248
|
? view.expression.trim()
|
|
2064
1249
|
: view.expression(this.connection).getQuery();
|
|
2065
1250
|
return this.insertTypeormMetadataSql({
|
|
@@ -2067,52 +1252,52 @@ var AbstractSqliteQueryRunner = /** @class */ (function (_super) {
|
|
|
2067
1252
|
name: view.name,
|
|
2068
1253
|
value: expression,
|
|
2069
1254
|
});
|
|
2070
|
-
}
|
|
1255
|
+
}
|
|
2071
1256
|
/**
|
|
2072
1257
|
* Builds drop view sql.
|
|
2073
1258
|
*/
|
|
2074
|
-
|
|
2075
|
-
|
|
1259
|
+
dropViewSql(viewOrPath) {
|
|
1260
|
+
const viewName = InstanceChecker_1.InstanceChecker.isView(viewOrPath)
|
|
2076
1261
|
? viewOrPath.name
|
|
2077
1262
|
: viewOrPath;
|
|
2078
|
-
return new Query_1.Query(
|
|
2079
|
-
}
|
|
1263
|
+
return new Query_1.Query(`DROP VIEW "${viewName}"`);
|
|
1264
|
+
}
|
|
2080
1265
|
/**
|
|
2081
1266
|
* Builds remove view sql.
|
|
2082
1267
|
*/
|
|
2083
|
-
|
|
2084
|
-
|
|
1268
|
+
deleteViewDefinitionSql(viewOrPath) {
|
|
1269
|
+
const viewName = InstanceChecker_1.InstanceChecker.isView(viewOrPath)
|
|
2085
1270
|
? viewOrPath.name
|
|
2086
1271
|
: viewOrPath;
|
|
2087
1272
|
return this.deleteTypeormMetadataSql({
|
|
2088
1273
|
type: MetadataTableType_1.MetadataTableType.VIEW,
|
|
2089
1274
|
name: viewName,
|
|
2090
1275
|
});
|
|
2091
|
-
}
|
|
1276
|
+
}
|
|
2092
1277
|
/**
|
|
2093
1278
|
* Builds create index sql.
|
|
2094
1279
|
*/
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
.map(
|
|
1280
|
+
createIndexSql(table, index) {
|
|
1281
|
+
const columns = index.columnNames
|
|
1282
|
+
.map((columnName) => `"${columnName}"`)
|
|
2098
1283
|
.join(", ");
|
|
2099
|
-
|
|
2100
|
-
return new Query_1.Query(
|
|
2101
|
-
}
|
|
1284
|
+
const [database, tableName] = this.splitTablePath(table.name);
|
|
1285
|
+
return new Query_1.Query(`CREATE ${index.isUnique ? "UNIQUE " : ""}INDEX ${database ? `"${database}".` : ""}${this.escapePath(index.name)} ON "${tableName}" (${columns}) ${index.where ? "WHERE " + index.where : ""}`);
|
|
1286
|
+
}
|
|
2102
1287
|
/**
|
|
2103
1288
|
* Builds drop index sql.
|
|
2104
1289
|
*/
|
|
2105
|
-
|
|
2106
|
-
|
|
1290
|
+
dropIndexSql(indexOrName) {
|
|
1291
|
+
let indexName = InstanceChecker_1.InstanceChecker.isTableIndex(indexOrName)
|
|
2107
1292
|
? indexOrName.name
|
|
2108
1293
|
: indexOrName;
|
|
2109
|
-
return new Query_1.Query(
|
|
2110
|
-
}
|
|
1294
|
+
return new Query_1.Query(`DROP INDEX ${this.escapePath(indexName)}`);
|
|
1295
|
+
}
|
|
2111
1296
|
/**
|
|
2112
1297
|
* Builds a query for create column.
|
|
2113
1298
|
*/
|
|
2114
|
-
|
|
2115
|
-
|
|
1299
|
+
buildCreateColumnSql(column, skipPrimary) {
|
|
1300
|
+
let c = '"' + column.name + '"';
|
|
2116
1301
|
if (InstanceChecker_1.InstanceChecker.isColumnMetadata(column)) {
|
|
2117
1302
|
c += " " + this.driver.normalizeType(column);
|
|
2118
1303
|
}
|
|
@@ -2124,7 +1309,7 @@ var AbstractSqliteQueryRunner = /** @class */ (function (_super) {
|
|
|
2124
1309
|
' CHECK( "' +
|
|
2125
1310
|
column.name +
|
|
2126
1311
|
'" IN (' +
|
|
2127
|
-
column.enum.map(
|
|
1312
|
+
column.enum.map((val) => "'" + val + "'").join(",") +
|
|
2128
1313
|
") )";
|
|
2129
1314
|
if (column.isPrimary && !skipPrimary)
|
|
2130
1315
|
c += " PRIMARY KEY";
|
|
@@ -2137,201 +1322,184 @@ var AbstractSqliteQueryRunner = /** @class */ (function (_super) {
|
|
|
2137
1322
|
if (column.isNullable !== true)
|
|
2138
1323
|
c += " NOT NULL";
|
|
2139
1324
|
if (column.asExpression) {
|
|
2140
|
-
c +=
|
|
1325
|
+
c += ` AS (${column.asExpression}) ${column.generatedType ? column.generatedType : "VIRTUAL"}`;
|
|
2141
1326
|
}
|
|
2142
1327
|
else {
|
|
2143
1328
|
if (column.default !== undefined && column.default !== null)
|
|
2144
1329
|
c += " DEFAULT (" + column.default + ")";
|
|
2145
1330
|
}
|
|
2146
1331
|
return c;
|
|
2147
|
-
}
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
});
|
|
2232
|
-
var insertQuery = _this.insertTypeormMetadataSql({
|
|
2233
|
-
table: oldTable.name,
|
|
2234
|
-
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
2235
|
-
name: column.name,
|
|
2236
|
-
value: column.asExpression,
|
|
2237
|
-
});
|
|
2238
|
-
upQueries.push(deleteQuery);
|
|
2239
|
-
downQueries.push(insertQuery);
|
|
2240
|
-
});
|
|
2241
|
-
// Step 2: add data for new generated columns
|
|
2242
|
-
newTable.columns
|
|
2243
|
-
.filter(function (column) {
|
|
2244
|
-
return column.generatedType &&
|
|
2245
|
-
column.asExpression &&
|
|
2246
|
-
!oldTable.columns.some(function (c) { return c.name === column.name; });
|
|
2247
|
-
})
|
|
2248
|
-
.forEach(function (column) {
|
|
2249
|
-
var insertQuery = _this.insertTypeormMetadataSql({
|
|
2250
|
-
table: newTable.name,
|
|
2251
|
-
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
2252
|
-
name: column.name,
|
|
2253
|
-
value: column.asExpression,
|
|
2254
|
-
});
|
|
2255
|
-
var deleteQuery = _this.deleteTypeormMetadataSql({
|
|
2256
|
-
table: newTable.name,
|
|
2257
|
-
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
2258
|
-
name: column.name,
|
|
2259
|
-
});
|
|
2260
|
-
upQueries.push(insertQuery);
|
|
2261
|
-
downQueries.push(deleteQuery);
|
|
2262
|
-
});
|
|
2263
|
-
// Step 3: update changed expressions
|
|
2264
|
-
newTable.columns
|
|
2265
|
-
.filter(function (column) { return column.generatedType && column.asExpression; })
|
|
2266
|
-
.forEach(function (column) {
|
|
2267
|
-
var oldColumn = oldTable.columns.find(function (c) {
|
|
2268
|
-
return c.name === column.name &&
|
|
2269
|
-
c.generatedType &&
|
|
2270
|
-
column.generatedType &&
|
|
2271
|
-
c.asExpression !== column.asExpression;
|
|
2272
|
-
});
|
|
2273
|
-
if (!oldColumn)
|
|
2274
|
-
return;
|
|
2275
|
-
// update expression
|
|
2276
|
-
var deleteQuery = _this.deleteTypeormMetadataSql({
|
|
2277
|
-
table: oldTable.name,
|
|
2278
|
-
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
2279
|
-
name: oldColumn.name,
|
|
2280
|
-
});
|
|
2281
|
-
var insertQuery = _this.insertTypeormMetadataSql({
|
|
2282
|
-
table: newTable.name,
|
|
2283
|
-
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
2284
|
-
name: column.name,
|
|
2285
|
-
value: column.asExpression,
|
|
2286
|
-
});
|
|
2287
|
-
upQueries.push(deleteQuery);
|
|
2288
|
-
upQueries.push(insertQuery);
|
|
2289
|
-
// revert update
|
|
2290
|
-
var revertInsertQuery = _this.insertTypeormMetadataSql({
|
|
2291
|
-
table: newTable.name,
|
|
2292
|
-
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
2293
|
-
name: oldColumn.name,
|
|
2294
|
-
value: oldColumn.asExpression,
|
|
2295
|
-
});
|
|
2296
|
-
var revertDeleteQuery = _this.deleteTypeormMetadataSql({
|
|
2297
|
-
table: oldTable.name,
|
|
2298
|
-
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
2299
|
-
name: column.name,
|
|
2300
|
-
});
|
|
2301
|
-
downQueries.push(revertInsertQuery);
|
|
2302
|
-
downQueries.push(revertDeleteQuery);
|
|
2303
|
-
});
|
|
2304
|
-
return [4 /*yield*/, this.executeQueries(upQueries, downQueries)];
|
|
2305
|
-
case 1:
|
|
2306
|
-
_c.sent();
|
|
2307
|
-
this.replaceCachedTable(oldTable, newTable);
|
|
2308
|
-
return [2 /*return*/];
|
|
2309
|
-
}
|
|
1332
|
+
}
|
|
1333
|
+
async recreateTable(newTable, oldTable, migrateData = true) {
|
|
1334
|
+
const upQueries = [];
|
|
1335
|
+
const downQueries = [];
|
|
1336
|
+
// drop old table indices
|
|
1337
|
+
oldTable.indices.forEach((index) => {
|
|
1338
|
+
upQueries.push(this.dropIndexSql(index));
|
|
1339
|
+
downQueries.push(this.createIndexSql(oldTable, index));
|
|
1340
|
+
});
|
|
1341
|
+
// change table name into 'temporary_table'
|
|
1342
|
+
let [databaseNew, tableNameNew] = this.splitTablePath(newTable.name);
|
|
1343
|
+
let [, tableNameOld] = this.splitTablePath(oldTable.name);
|
|
1344
|
+
newTable.name = tableNameNew = `${databaseNew ? `${databaseNew}.` : ""}temporary_${tableNameNew}`;
|
|
1345
|
+
// create new table
|
|
1346
|
+
upQueries.push(this.createTableSql(newTable, true, true));
|
|
1347
|
+
downQueries.push(this.dropTableSql(newTable));
|
|
1348
|
+
// migrate all data from the old table into new table
|
|
1349
|
+
if (migrateData) {
|
|
1350
|
+
let newColumnNames = newTable.columns
|
|
1351
|
+
.filter((column) => !column.generatedType)
|
|
1352
|
+
.map((column) => `"${column.name}"`);
|
|
1353
|
+
let oldColumnNames = oldTable.columns
|
|
1354
|
+
.filter((column) => !column.generatedType)
|
|
1355
|
+
.map((column) => `"${column.name}"`);
|
|
1356
|
+
if (oldColumnNames.length < newColumnNames.length) {
|
|
1357
|
+
newColumnNames = newTable.columns
|
|
1358
|
+
.filter((column) => {
|
|
1359
|
+
const oldColumn = oldTable.columns.find((c) => c.name === column.name);
|
|
1360
|
+
if (oldColumn && oldColumn.generatedType)
|
|
1361
|
+
return false;
|
|
1362
|
+
return !column.generatedType && oldColumn;
|
|
1363
|
+
})
|
|
1364
|
+
.map((column) => `"${column.name}"`);
|
|
1365
|
+
}
|
|
1366
|
+
else if (oldColumnNames.length > newColumnNames.length) {
|
|
1367
|
+
oldColumnNames = oldTable.columns
|
|
1368
|
+
.filter((column) => {
|
|
1369
|
+
return (!column.generatedType &&
|
|
1370
|
+
newTable.columns.find((c) => c.name === column.name));
|
|
1371
|
+
})
|
|
1372
|
+
.map((column) => `"${column.name}"`);
|
|
1373
|
+
}
|
|
1374
|
+
upQueries.push(new Query_1.Query(`INSERT INTO ${this.escapePath(newTable.name)}(${newColumnNames.join(", ")}) SELECT ${oldColumnNames.join(", ")} FROM ${this.escapePath(oldTable.name)}`));
|
|
1375
|
+
downQueries.push(new Query_1.Query(`INSERT INTO ${this.escapePath(oldTable.name)}(${oldColumnNames.join(", ")}) SELECT ${newColumnNames.join(", ")} FROM ${this.escapePath(newTable.name)}`));
|
|
1376
|
+
}
|
|
1377
|
+
// drop old table
|
|
1378
|
+
upQueries.push(this.dropTableSql(oldTable));
|
|
1379
|
+
downQueries.push(this.createTableSql(oldTable, true));
|
|
1380
|
+
// rename old table
|
|
1381
|
+
upQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(newTable.name)} RENAME TO ${this.escapePath(tableNameOld)}`));
|
|
1382
|
+
downQueries.push(new Query_1.Query(`ALTER TABLE ${this.escapePath(oldTable.name)} RENAME TO ${this.escapePath(tableNameNew)}`));
|
|
1383
|
+
newTable.name = oldTable.name;
|
|
1384
|
+
// recreate table indices
|
|
1385
|
+
newTable.indices.forEach((index) => {
|
|
1386
|
+
// new index may be passed without name. In this case we generate index name manually.
|
|
1387
|
+
if (!index.name)
|
|
1388
|
+
index.name = this.connection.namingStrategy.indexName(newTable, index.columnNames, index.where);
|
|
1389
|
+
upQueries.push(this.createIndexSql(newTable, index));
|
|
1390
|
+
downQueries.push(this.dropIndexSql(index));
|
|
1391
|
+
});
|
|
1392
|
+
// update generated columns in "typeorm_metadata" table
|
|
1393
|
+
// Step 1: clear data for removed generated columns
|
|
1394
|
+
oldTable.columns
|
|
1395
|
+
.filter((column) => {
|
|
1396
|
+
const newTableColumn = newTable.columns.find((c) => c.name === column.name);
|
|
1397
|
+
// we should delete record from "typeorm_metadata" if generated column was removed
|
|
1398
|
+
// or it was changed to non-generated
|
|
1399
|
+
return (column.generatedType &&
|
|
1400
|
+
column.asExpression &&
|
|
1401
|
+
(!newTableColumn ||
|
|
1402
|
+
(!newTableColumn.generatedType &&
|
|
1403
|
+
!newTableColumn.asExpression)));
|
|
1404
|
+
})
|
|
1405
|
+
.forEach((column) => {
|
|
1406
|
+
const deleteQuery = this.deleteTypeormMetadataSql({
|
|
1407
|
+
table: oldTable.name,
|
|
1408
|
+
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
1409
|
+
name: column.name,
|
|
1410
|
+
});
|
|
1411
|
+
const insertQuery = this.insertTypeormMetadataSql({
|
|
1412
|
+
table: oldTable.name,
|
|
1413
|
+
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
1414
|
+
name: column.name,
|
|
1415
|
+
value: column.asExpression,
|
|
2310
1416
|
});
|
|
1417
|
+
upQueries.push(deleteQuery);
|
|
1418
|
+
downQueries.push(insertQuery);
|
|
2311
1419
|
});
|
|
2312
|
-
|
|
1420
|
+
// Step 2: add data for new generated columns
|
|
1421
|
+
newTable.columns
|
|
1422
|
+
.filter((column) => column.generatedType &&
|
|
1423
|
+
column.asExpression &&
|
|
1424
|
+
!oldTable.columns.some((c) => c.name === column.name))
|
|
1425
|
+
.forEach((column) => {
|
|
1426
|
+
const insertQuery = this.insertTypeormMetadataSql({
|
|
1427
|
+
table: newTable.name,
|
|
1428
|
+
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
1429
|
+
name: column.name,
|
|
1430
|
+
value: column.asExpression,
|
|
1431
|
+
});
|
|
1432
|
+
const deleteQuery = this.deleteTypeormMetadataSql({
|
|
1433
|
+
table: newTable.name,
|
|
1434
|
+
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
1435
|
+
name: column.name,
|
|
1436
|
+
});
|
|
1437
|
+
upQueries.push(insertQuery);
|
|
1438
|
+
downQueries.push(deleteQuery);
|
|
1439
|
+
});
|
|
1440
|
+
// Step 3: update changed expressions
|
|
1441
|
+
newTable.columns
|
|
1442
|
+
.filter((column) => column.generatedType && column.asExpression)
|
|
1443
|
+
.forEach((column) => {
|
|
1444
|
+
const oldColumn = oldTable.columns.find((c) => c.name === column.name &&
|
|
1445
|
+
c.generatedType &&
|
|
1446
|
+
column.generatedType &&
|
|
1447
|
+
c.asExpression !== column.asExpression);
|
|
1448
|
+
if (!oldColumn)
|
|
1449
|
+
return;
|
|
1450
|
+
// update expression
|
|
1451
|
+
const deleteQuery = this.deleteTypeormMetadataSql({
|
|
1452
|
+
table: oldTable.name,
|
|
1453
|
+
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
1454
|
+
name: oldColumn.name,
|
|
1455
|
+
});
|
|
1456
|
+
const insertQuery = this.insertTypeormMetadataSql({
|
|
1457
|
+
table: newTable.name,
|
|
1458
|
+
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
1459
|
+
name: column.name,
|
|
1460
|
+
value: column.asExpression,
|
|
1461
|
+
});
|
|
1462
|
+
upQueries.push(deleteQuery);
|
|
1463
|
+
upQueries.push(insertQuery);
|
|
1464
|
+
// revert update
|
|
1465
|
+
const revertInsertQuery = this.insertTypeormMetadataSql({
|
|
1466
|
+
table: newTable.name,
|
|
1467
|
+
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
1468
|
+
name: oldColumn.name,
|
|
1469
|
+
value: oldColumn.asExpression,
|
|
1470
|
+
});
|
|
1471
|
+
const revertDeleteQuery = this.deleteTypeormMetadataSql({
|
|
1472
|
+
table: oldTable.name,
|
|
1473
|
+
type: MetadataTableType_1.MetadataTableType.GENERATED_COLUMN,
|
|
1474
|
+
name: column.name,
|
|
1475
|
+
});
|
|
1476
|
+
downQueries.push(revertInsertQuery);
|
|
1477
|
+
downQueries.push(revertDeleteQuery);
|
|
1478
|
+
});
|
|
1479
|
+
await this.executeQueries(upQueries, downQueries);
|
|
1480
|
+
this.replaceCachedTable(oldTable, newTable);
|
|
1481
|
+
}
|
|
2313
1482
|
/**
|
|
2314
1483
|
* tablePath e.g. "myDB.myTable", "myTable"
|
|
2315
1484
|
*/
|
|
2316
|
-
|
|
1485
|
+
splitTablePath(tablePath) {
|
|
2317
1486
|
return (tablePath.indexOf(".") !== -1
|
|
2318
1487
|
? tablePath.split(".")
|
|
2319
1488
|
: [undefined, tablePath]);
|
|
2320
|
-
}
|
|
1489
|
+
}
|
|
2321
1490
|
/**
|
|
2322
1491
|
* Escapes given table or view path. Tolerates leading/trailing dots
|
|
2323
1492
|
*/
|
|
2324
|
-
|
|
2325
|
-
|
|
1493
|
+
escapePath(target, disableEscape) {
|
|
1494
|
+
const tableName = InstanceChecker_1.InstanceChecker.isTable(target) || InstanceChecker_1.InstanceChecker.isView(target)
|
|
2326
1495
|
? target.name
|
|
2327
1496
|
: target;
|
|
2328
1497
|
return tableName
|
|
2329
1498
|
.replace(/^\.+|\.+$/g, "")
|
|
2330
1499
|
.split(".")
|
|
2331
|
-
.map(
|
|
1500
|
+
.map((i) => (disableEscape ? i : `"${i}"`))
|
|
2332
1501
|
.join(".");
|
|
2333
|
-
}
|
|
2334
|
-
|
|
2335
|
-
}(BaseQueryRunner_1.BaseQueryRunner));
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
2336
1504
|
exports.AbstractSqliteQueryRunner = AbstractSqliteQueryRunner;
|
|
2337
1505
|
//# sourceMappingURL=AbstractSqliteQueryRunner.js.map
|