typeorm 0.3.16-dev.54f4f89 → 0.3.16-dev.9460296

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.
Files changed (49) hide show
  1. package/browser/cli-ts-node-esm.js +4 -2
  2. package/browser/cli-ts-node-esm.js.map +1 -1
  3. package/browser/driver/Driver.d.ts +10 -0
  4. package/browser/driver/Driver.js.map +1 -1
  5. package/browser/driver/mysql/MysqlDriver.d.ts +6 -0
  6. package/browser/driver/mysql/MysqlDriver.js +18 -2
  7. package/browser/driver/mysql/MysqlDriver.js.map +1 -1
  8. package/browser/driver/oracle/OracleDriver.d.ts +13 -0
  9. package/browser/driver/oracle/OracleDriver.js +15 -0
  10. package/browser/driver/oracle/OracleDriver.js.map +1 -1
  11. package/browser/driver/oracle/OracleQueryRunner.js +4 -2
  12. package/browser/driver/oracle/OracleQueryRunner.js.map +1 -1
  13. package/browser/driver/sqlserver/SqlServerConnectionOptions.d.ts +9 -0
  14. package/browser/driver/sqlserver/SqlServerConnectionOptions.js.map +1 -1
  15. package/browser/metadata-builder/EntityMetadataValidator.js +12 -0
  16. package/browser/metadata-builder/EntityMetadataValidator.js.map +1 -1
  17. package/browser/query-builder/RelationIdLoader.d.ts +3 -1
  18. package/browser/query-builder/RelationIdLoader.js +6 -5
  19. package/browser/query-builder/RelationIdLoader.js.map +1 -1
  20. package/browser/query-builder/SelectQueryBuilder.js +3 -1
  21. package/browser/query-builder/SelectQueryBuilder.js.map +1 -1
  22. package/browser/query-builder/transformer/RawSqlResultsToEntityTransformer.js +1 -1
  23. package/browser/query-builder/transformer/RawSqlResultsToEntityTransformer.js.map +1 -1
  24. package/cli-ts-node-esm.js +4 -2
  25. package/cli-ts-node-esm.js.map +1 -1
  26. package/commands/InitCommand.js +1 -1
  27. package/commands/InitCommand.js.map +1 -1
  28. package/driver/Driver.d.ts +10 -0
  29. package/driver/Driver.js.map +1 -1
  30. package/driver/mysql/MysqlDriver.d.ts +6 -0
  31. package/driver/mysql/MysqlDriver.js +18 -2
  32. package/driver/mysql/MysqlDriver.js.map +1 -1
  33. package/driver/oracle/OracleDriver.d.ts +13 -0
  34. package/driver/oracle/OracleDriver.js +15 -0
  35. package/driver/oracle/OracleDriver.js.map +1 -1
  36. package/driver/oracle/OracleQueryRunner.js +4 -2
  37. package/driver/oracle/OracleQueryRunner.js.map +1 -1
  38. package/driver/sqlserver/SqlServerConnectionOptions.d.ts +9 -0
  39. package/driver/sqlserver/SqlServerConnectionOptions.js.map +1 -1
  40. package/metadata-builder/EntityMetadataValidator.js +12 -0
  41. package/metadata-builder/EntityMetadataValidator.js.map +1 -1
  42. package/package.json +1 -1
  43. package/query-builder/RelationIdLoader.d.ts +3 -1
  44. package/query-builder/RelationIdLoader.js +6 -5
  45. package/query-builder/RelationIdLoader.js.map +1 -1
  46. package/query-builder/SelectQueryBuilder.js +3 -1
  47. package/query-builder/SelectQueryBuilder.js.map +1 -1
  48. package/query-builder/transformer/RawSqlResultsToEntityTransformer.js +1 -1
  49. package/query-builder/transformer/RawSqlResultsToEntityTransformer.js.map +1 -1
@@ -94,6 +94,10 @@ export interface SqlServerConnectionOptions extends BaseDataSourceOptions, SqlSe
94
94
  * Extra options
95
95
  */
96
96
  readonly options?: {
97
+ /**
98
+ * The named instance to connect to
99
+ */
100
+ readonly instanceName?: string;
97
101
  /**
98
102
  * By default, if the database requestion by options.database cannot be accessed, the connection will fail with
99
103
  * an error. However, if options.fallbackToDefaultDb is set to true, then the user's default database will
@@ -219,6 +223,11 @@ export interface SqlServerConnectionOptions extends BaseDataSourceOptions, SqlSe
219
223
  * (default: node-mssql)
220
224
  */
221
225
  readonly appName?: string;
226
+ /**
227
+ * A boolean, controlling whether encryption occurs if there is no verifiable server certificate.
228
+ * (default: false)
229
+ */
230
+ readonly trustServerCertificate?: boolean;
222
231
  };
223
232
  /**
224
233
  * Replication setup.
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/driver/sqlserver/SqlServerConnectionOptions.ts"],"names":[],"mappings":"","file":"SqlServerConnectionOptions.js","sourcesContent":["import { BaseDataSourceOptions } from \"../../data-source/BaseDataSourceOptions\"\nimport { SqlServerConnectionCredentialsOptions } from \"./SqlServerConnectionCredentialsOptions\"\n\n/**\n * Microsoft Sql Server specific connection options.\n */\nexport interface SqlServerConnectionOptions\n extends BaseDataSourceOptions,\n SqlServerConnectionCredentialsOptions {\n /**\n * Database type.\n */\n readonly type: \"mssql\"\n\n /**\n * Connection timeout in ms (default: 15000).\n */\n readonly connectionTimeout?: number\n\n /**\n * Request timeout in ms (default: 15000). NOTE: msnodesqlv8 driver doesn't support timeouts < 1 second.\n */\n readonly requestTimeout?: number\n\n /**\n * Stream recordsets/rows instead of returning them all at once as an argument of callback (default: false).\n * You can also enable streaming for each request independently (request.stream = true).\n * Always set to true if you plan to work with large amount of rows.\n */\n readonly stream?: boolean\n\n /**\n * Database schema.\n */\n readonly schema?: string\n\n /**\n * The driver object\n * This defaults to `require(\"mssql\")`\n */\n readonly driver?: any\n\n /**\n * An optional object/dictionary with the any of the properties\n */\n readonly pool?: {\n /**\n * Maximum number of resources to create at any given time. (default=1)\n */\n readonly max?: number\n\n /**\n * Minimum number of resources to keep in pool at any given time. If this is set >= max, the pool will silently\n * set the min to equal max. (default=0)\n */\n readonly min?: number\n\n /**\n * Maximum number of queued requests allowed, additional acquire calls will be callback with an err in a future\n * cycle of the event loop.\n */\n readonly maxWaitingClients?: number\n\n /**\n * Should the pool validate resources before giving them to clients. Requires that either factory.validate or\n * factory.validateAsync to be specified\n */\n readonly testOnBorrow?: boolean\n\n /**\n * Max milliseconds an acquire call will wait for a resource before timing out. (default no limit), if supplied should non-zero positive integer.\n */\n readonly acquireTimeoutMillis?: number\n\n /**\n * If true the oldest resources will be first to be allocated. If false the most recently released resources will\n * be the first to be allocated. This in effect turns the pool's behaviour from a queue into a stack. boolean,\n * (default true)\n */\n readonly fifo?: boolean\n\n /**\n * Int between 1 and x - if set, borrowers can specify their relative priority in the queue if no resources\n * are available. see example. (default 1)\n */\n readonly priorityRange?: number\n\n /**\n * How often to run eviction checks. Default: 0 (does not run).\n */\n readonly evictionRunIntervalMillis?: number\n\n /**\n * Number of resources to check each eviction run. Default: 3.\n */\n readonly numTestsPerRun?: number\n\n /**\n * Amount of time an object may sit idle in the pool before it is eligible for eviction by the idle object\n * evictor (if any), with the extra condition that at least \"min idle\" object instances remain in the pool.\n * Default -1 (nothing can get evicted)\n */\n readonly softIdleTimeoutMillis?: number\n\n /**\n * The minimum amount of time that an object may sit idle in the pool before it is eligible for eviction due\n * to idle time. Supercedes softIdleTimeoutMillis Default: 30000\n */\n readonly idleTimeoutMillis?: number\n\n /*\n * Function handling errors thrown by drivers pool.\n * Defaults to logging error with `warn` level.\n */\n readonly errorHandler?: (err: any) => any\n }\n\n /**\n * Extra options\n */\n readonly options?: {\n /**\n * By default, if the database requestion by options.database cannot be accessed, the connection will fail with\n * an error. However, if options.fallbackToDefaultDb is set to true, then the user's default database will\n * be used instead (Default: false).\n */\n readonly fallbackToDefaultDb?: boolean\n\n /**\n * If true, SET ANSI_NULL_DFLT_ON ON will be set in the initial sql. This means new columns will be nullable by\n * default. See the T-SQL documentation for more details. (Default: true).\n */\n readonly enableAnsiNullDefault?: boolean\n\n /**\n * The number of milliseconds before the attempt to connect is considered failed (default: 15000).\n */\n readonly connectTimeout?: number\n\n /**\n * The number of milliseconds before the cancel (abort) of a request is considered failed (default: 5000).\n */\n readonly cancelTimeout?: number\n\n /**\n * The size of TDS packets (subject to negotiation with the server). Should be a power of 2. (default: 4096).\n */\n readonly packetSize?: number\n\n /**\n * A boolean determining whether to pass time values in UTC or local time. (default: false).\n */\n readonly useUTC?: boolean\n\n /**\n * A boolean determining whether to rollback a transaction automatically if any error is encountered during\n * the given transaction's execution. This sets the value for SET XACT_ABORT during the initial SQL phase\n * of a connection (documentation).\n */\n readonly abortTransactionOnError?: boolean\n\n /**\n * A string indicating which network interface (ip address) to use when connecting to SQL Server.\n */\n readonly localAddress?: string\n\n /**\n * A boolean determining whether to return rows as arrays or key-value collections. (default: false).\n */\n readonly useColumnNames?: boolean\n\n /**\n * A boolean, controlling whether the column names returned will have the first letter converted to lower case\n * (true) or not. This value is ignored if you provide a columnNameReplacer. (default: false).\n */\n readonly camelCaseColumns?: boolean\n\n /**\n * A boolean, controlling whatever to disable RETURNING / OUTPUT statements.\n */\n readonly disableOutputReturning?: boolean\n\n /**\n * Debug options\n */\n readonly debug?: {\n /**\n * A boolean, controlling whether debug events will be emitted with text describing packet details\n * (default: false).\n */\n readonly packet?: boolean\n\n /**\n * A boolean, controlling whether debug events will be emitted with text describing packet data details\n * (default: false).\n */\n readonly data?: boolean\n\n /**\n * A boolean, controlling whether debug events will be emitted with text describing packet payload details\n * (default: false).\n */\n readonly payload?: boolean\n\n /**\n * A boolean, controlling whether debug events will be emitted with text describing token stream tokens\n * (default: false).\n */\n readonly token?: boolean\n }\n\n /**\n * The default isolation level that transactions will be run with. The isolation levels are available\n * from require('tedious').ISOLATION_LEVEL. (default: READ_COMMITTED).\n */\n readonly isolation?:\n | \"READ_UNCOMMITTED\"\n | \"READ_COMMITTED\"\n | \"REPEATABLE_READ\"\n | \"SERIALIZABLE\"\n | \"SNAPSHOT\"\n\n /**\n * The default isolation level for new connections. All out-of-transaction queries are executed with this\n * setting. The isolation levels are available from require('tedious').ISOLATION_LEVEL .\n */\n readonly connectionIsolationLevel?:\n | \"READ_UNCOMMITTED\"\n | \"READ_COMMITTED\"\n | \"REPEATABLE_READ\"\n | \"SERIALIZABLE\"\n | \"SNAPSHOT\"\n\n /**\n * A boolean, determining whether the connection will request read only access from a SQL Server\n * Availability Group. For more information, see here. (default: false).\n */\n readonly readOnlyIntent?: boolean\n\n /**\n * A boolean determining whether or not the connection will be encrypted. Set to true if you're on\n * Windows Azure. (default: true).\n */\n readonly encrypt?: boolean\n\n /**\n * When encryption is used, an object may be supplied that will be used for the first argument when calling\n * tls.createSecurePair (default: {}).\n */\n readonly cryptoCredentialsDetails?: any\n\n /**\n * A boolean, that when true will expose received rows in Requests' done* events. See done, doneInProc and\n * doneProc. (default: false)\n * Caution: If many row are received, enabling this option could result in excessive memory usage.\n */\n readonly rowCollectionOnDone?: boolean\n\n /**\n * A boolean, that when true will expose received rows in Requests' completion callback. See new Request. (default: false)\n * Caution: If many row are received, enabling this option could result in excessive memory usage.\n */\n readonly rowCollectionOnRequestCompletion?: boolean\n\n /**\n * The version of TDS to use. If server doesn't support specified version, negotiated version is used instead.\n * The versions are available from require('tedious').TDS_VERSION. (default: 7_4).\n */\n readonly tdsVersion?: string\n\n /**\n * A boolean, that when true will abort a query when an overflow or divide-by-zero error occurs during query execution.\n */\n readonly enableArithAbort?: boolean\n\n /**\n * Application name used for identifying a specific application in profiling, logging or tracing tools of SQL Server.\n * (default: node-mssql)\n */\n readonly appName?: string\n }\n\n /**\n * Replication setup.\n */\n readonly replication?: {\n /**\n * Master server used by orm to perform writes.\n */\n readonly master: SqlServerConnectionCredentialsOptions\n\n /**\n * List of read-from severs (slaves).\n */\n readonly slaves: SqlServerConnectionCredentialsOptions[]\n }\n\n readonly poolSize?: never\n}\n"],"sourceRoot":"../.."}
1
+ {"version":3,"sources":["../browser/src/driver/sqlserver/SqlServerConnectionOptions.ts"],"names":[],"mappings":"","file":"SqlServerConnectionOptions.js","sourcesContent":["import { BaseDataSourceOptions } from \"../../data-source/BaseDataSourceOptions\"\nimport { SqlServerConnectionCredentialsOptions } from \"./SqlServerConnectionCredentialsOptions\"\n\n/**\n * Microsoft Sql Server specific connection options.\n */\nexport interface SqlServerConnectionOptions\n extends BaseDataSourceOptions,\n SqlServerConnectionCredentialsOptions {\n /**\n * Database type.\n */\n readonly type: \"mssql\"\n\n /**\n * Connection timeout in ms (default: 15000).\n */\n readonly connectionTimeout?: number\n\n /**\n * Request timeout in ms (default: 15000). NOTE: msnodesqlv8 driver doesn't support timeouts < 1 second.\n */\n readonly requestTimeout?: number\n\n /**\n * Stream recordsets/rows instead of returning them all at once as an argument of callback (default: false).\n * You can also enable streaming for each request independently (request.stream = true).\n * Always set to true if you plan to work with large amount of rows.\n */\n readonly stream?: boolean\n\n /**\n * Database schema.\n */\n readonly schema?: string\n\n /**\n * The driver object\n * This defaults to `require(\"mssql\")`\n */\n readonly driver?: any\n\n /**\n * An optional object/dictionary with the any of the properties\n */\n readonly pool?: {\n /**\n * Maximum number of resources to create at any given time. (default=1)\n */\n readonly max?: number\n\n /**\n * Minimum number of resources to keep in pool at any given time. If this is set >= max, the pool will silently\n * set the min to equal max. (default=0)\n */\n readonly min?: number\n\n /**\n * Maximum number of queued requests allowed, additional acquire calls will be callback with an err in a future\n * cycle of the event loop.\n */\n readonly maxWaitingClients?: number\n\n /**\n * Should the pool validate resources before giving them to clients. Requires that either factory.validate or\n * factory.validateAsync to be specified\n */\n readonly testOnBorrow?: boolean\n\n /**\n * Max milliseconds an acquire call will wait for a resource before timing out. (default no limit), if supplied should non-zero positive integer.\n */\n readonly acquireTimeoutMillis?: number\n\n /**\n * If true the oldest resources will be first to be allocated. If false the most recently released resources will\n * be the first to be allocated. This in effect turns the pool's behaviour from a queue into a stack. boolean,\n * (default true)\n */\n readonly fifo?: boolean\n\n /**\n * Int between 1 and x - if set, borrowers can specify their relative priority in the queue if no resources\n * are available. see example. (default 1)\n */\n readonly priorityRange?: number\n\n /**\n * How often to run eviction checks. Default: 0 (does not run).\n */\n readonly evictionRunIntervalMillis?: number\n\n /**\n * Number of resources to check each eviction run. Default: 3.\n */\n readonly numTestsPerRun?: number\n\n /**\n * Amount of time an object may sit idle in the pool before it is eligible for eviction by the idle object\n * evictor (if any), with the extra condition that at least \"min idle\" object instances remain in the pool.\n * Default -1 (nothing can get evicted)\n */\n readonly softIdleTimeoutMillis?: number\n\n /**\n * The minimum amount of time that an object may sit idle in the pool before it is eligible for eviction due\n * to idle time. Supercedes softIdleTimeoutMillis Default: 30000\n */\n readonly idleTimeoutMillis?: number\n\n /*\n * Function handling errors thrown by drivers pool.\n * Defaults to logging error with `warn` level.\n */\n readonly errorHandler?: (err: any) => any\n }\n\n /**\n * Extra options\n */\n readonly options?: {\n /**\n * The named instance to connect to\n */\n readonly instanceName?: string\n\n /**\n * By default, if the database requestion by options.database cannot be accessed, the connection will fail with\n * an error. However, if options.fallbackToDefaultDb is set to true, then the user's default database will\n * be used instead (Default: false).\n */\n readonly fallbackToDefaultDb?: boolean\n\n /**\n * If true, SET ANSI_NULL_DFLT_ON ON will be set in the initial sql. This means new columns will be nullable by\n * default. See the T-SQL documentation for more details. (Default: true).\n */\n readonly enableAnsiNullDefault?: boolean\n\n /**\n * The number of milliseconds before the attempt to connect is considered failed (default: 15000).\n */\n readonly connectTimeout?: number\n\n /**\n * The number of milliseconds before the cancel (abort) of a request is considered failed (default: 5000).\n */\n readonly cancelTimeout?: number\n\n /**\n * The size of TDS packets (subject to negotiation with the server). Should be a power of 2. (default: 4096).\n */\n readonly packetSize?: number\n\n /**\n * A boolean determining whether to pass time values in UTC or local time. (default: false).\n */\n readonly useUTC?: boolean\n\n /**\n * A boolean determining whether to rollback a transaction automatically if any error is encountered during\n * the given transaction's execution. This sets the value for SET XACT_ABORT during the initial SQL phase\n * of a connection (documentation).\n */\n readonly abortTransactionOnError?: boolean\n\n /**\n * A string indicating which network interface (ip address) to use when connecting to SQL Server.\n */\n readonly localAddress?: string\n\n /**\n * A boolean determining whether to return rows as arrays or key-value collections. (default: false).\n */\n readonly useColumnNames?: boolean\n\n /**\n * A boolean, controlling whether the column names returned will have the first letter converted to lower case\n * (true) or not. This value is ignored if you provide a columnNameReplacer. (default: false).\n */\n readonly camelCaseColumns?: boolean\n\n /**\n * A boolean, controlling whatever to disable RETURNING / OUTPUT statements.\n */\n readonly disableOutputReturning?: boolean\n\n /**\n * Debug options\n */\n readonly debug?: {\n /**\n * A boolean, controlling whether debug events will be emitted with text describing packet details\n * (default: false).\n */\n readonly packet?: boolean\n\n /**\n * A boolean, controlling whether debug events will be emitted with text describing packet data details\n * (default: false).\n */\n readonly data?: boolean\n\n /**\n * A boolean, controlling whether debug events will be emitted with text describing packet payload details\n * (default: false).\n */\n readonly payload?: boolean\n\n /**\n * A boolean, controlling whether debug events will be emitted with text describing token stream tokens\n * (default: false).\n */\n readonly token?: boolean\n }\n\n /**\n * The default isolation level that transactions will be run with. The isolation levels are available\n * from require('tedious').ISOLATION_LEVEL. (default: READ_COMMITTED).\n */\n readonly isolation?:\n | \"READ_UNCOMMITTED\"\n | \"READ_COMMITTED\"\n | \"REPEATABLE_READ\"\n | \"SERIALIZABLE\"\n | \"SNAPSHOT\"\n\n /**\n * The default isolation level for new connections. All out-of-transaction queries are executed with this\n * setting. The isolation levels are available from require('tedious').ISOLATION_LEVEL .\n */\n readonly connectionIsolationLevel?:\n | \"READ_UNCOMMITTED\"\n | \"READ_COMMITTED\"\n | \"REPEATABLE_READ\"\n | \"SERIALIZABLE\"\n | \"SNAPSHOT\"\n\n /**\n * A boolean, determining whether the connection will request read only access from a SQL Server\n * Availability Group. For more information, see here. (default: false).\n */\n readonly readOnlyIntent?: boolean\n\n /**\n * A boolean determining whether or not the connection will be encrypted. Set to true if you're on\n * Windows Azure. (default: true).\n */\n readonly encrypt?: boolean\n\n /**\n * When encryption is used, an object may be supplied that will be used for the first argument when calling\n * tls.createSecurePair (default: {}).\n */\n readonly cryptoCredentialsDetails?: any\n\n /**\n * A boolean, that when true will expose received rows in Requests' done* events. See done, doneInProc and\n * doneProc. (default: false)\n * Caution: If many row are received, enabling this option could result in excessive memory usage.\n */\n readonly rowCollectionOnDone?: boolean\n\n /**\n * A boolean, that when true will expose received rows in Requests' completion callback. See new Request. (default: false)\n * Caution: If many row are received, enabling this option could result in excessive memory usage.\n */\n readonly rowCollectionOnRequestCompletion?: boolean\n\n /**\n * The version of TDS to use. If server doesn't support specified version, negotiated version is used instead.\n * The versions are available from require('tedious').TDS_VERSION. (default: 7_4).\n */\n readonly tdsVersion?: string\n\n /**\n * A boolean, that when true will abort a query when an overflow or divide-by-zero error occurs during query execution.\n */\n readonly enableArithAbort?: boolean\n\n /**\n * Application name used for identifying a specific application in profiling, logging or tracing tools of SQL Server.\n * (default: node-mssql)\n */\n readonly appName?: string\n\n /**\n * A boolean, controlling whether encryption occurs if there is no verifiable server certificate.\n * (default: false)\n */\n readonly trustServerCertificate?: boolean\n }\n\n /**\n * Replication setup.\n */\n readonly replication?: {\n /**\n * Master server used by orm to perform writes.\n */\n readonly master: SqlServerConnectionCredentialsOptions\n\n /**\n * List of read-from severs (slaves).\n */\n readonly slaves: SqlServerConnectionCredentialsOptions[]\n }\n\n readonly poolSize?: never\n}\n"],"sourceRoot":"../.."}
@@ -138,6 +138,18 @@ export class EntityMetadataValidator {
138
138
  });
139
139
  // validate relations
140
140
  entityMetadata.relations.forEach((relation) => {
141
+ // check OnDeleteTypes
142
+ if (driver.supportedOnDeleteTypes &&
143
+ relation.onDelete &&
144
+ !driver.supportedOnDeleteTypes.includes(relation.onDelete)) {
145
+ throw new TypeORMError(`OnDeleteType "${relation.onDelete}" is not supported for ${driver.options.type}!`);
146
+ }
147
+ // check OnUpdateTypes
148
+ if (driver.supportedOnUpdateTypes &&
149
+ relation.onUpdate &&
150
+ !driver.supportedOnUpdateTypes.includes(relation.onUpdate)) {
151
+ throw new TypeORMError(`OnUpdateType "${relation.onUpdate}" is not valid for ${driver.options.type}!`);
152
+ }
141
153
  // check join tables:
142
154
  // using JoinTable is possible only on one side of the many-to-many relation
143
155
  // todo(dima): fix
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/metadata-builder/EntityMetadataValidator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAA;AAC9E,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAA;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAE3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAA;AAE9E,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAA;AAC1E,OAAO,EAAE,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C;IAED;;OAEG;IACO,sBAAsB,CAAC,eAAiC;QAC9D,eAAe,CAAC,OAAO,CAAC,CAAC,cAAc,EAAE,EAAE;YACvC,cAAc,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;gBAC/C,IACI,QAAQ,CAAC,eAAe;oBACxB,QAAQ,CAAC,eAAe,CAAC,OAAO;oBAEhC,MAAM,IAAI,YAAY,CAClB,2CAA2C;wBACvC,GAAG,cAAc,CAAC,UAAU,IAAI,QAAQ,CAAC,YAAY,gDAAgD;wBACrG,GAAG,QAAQ,CAAC,qBAAqB,CAAC,UAAU,IAAI,QAAQ,CAAC,eAAe,CAAC,YAAY,kCAAkC;wBACvH,sDAAsD,CAC7D,CAAA;YACT,CAAC,CAAC,CAAA;QACN,CAAC,CAAC,CAAA;IACN,CAAC;CACJ","file":"EntityMetadataValidator.js","sourcesContent":["import { EntityMetadata } from \"../metadata/EntityMetadata\"\nimport { MissingPrimaryColumnError } from \"../error/MissingPrimaryColumnError\"\nimport { CircularRelationsError } from \"../error/CircularRelationsError\"\nimport { DepGraph } from \"../util/DepGraph\"\nimport { Driver } from \"../driver/Driver\"\nimport { DataTypeNotSupportedError } from \"../error/DataTypeNotSupportedError\"\nimport { ColumnType } from \"../driver/types/ColumnTypes\"\nimport { NoConnectionOptionError } from \"../error/NoConnectionOptionError\"\nimport { InitializedRelationError } from \"../error/InitializedRelationError\"\nimport { TypeORMError } from \"../error\"\nimport { DriverUtils } from \"../driver/DriverUtils\"\n\n/// todo: add check if there are multiple tables with the same name\n/// todo: add checks when generated column / table names are too long for the specific driver\n// todo: type in function validation, inverse side function validation\n// todo: check on build for duplicate names, since naming checking was removed from MetadataStorage\n// todo: duplicate name checking for: table, relation, column, index, naming strategy, join tables/columns?\n// todo: check if multiple tree parent metadatas in validator\n// todo: tree decorators can be used only on closure table (validation)\n// todo: throw error if parent tree metadata was not specified in a closure table\n\n// todo: MetadataArgsStorage: type in function validation, inverse side function validation\n// todo: MetadataArgsStorage: check on build for duplicate names, since naming checking was removed from MetadataStorage\n// todo: MetadataArgsStorage: duplicate name checking for: table, relation, column, index, naming strategy, join tables/columns?\n// todo: MetadataArgsStorage: check for duplicate targets too since this check has been removed too\n// todo: check if relation decorator contains primary: true and nullable: true\n// todo: check column length, precision. scale\n// todo: MySQL index can be unique or spatial or fulltext\n\n/**\n * Validates built entity metadatas.\n */\nexport class EntityMetadataValidator {\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Validates all given entity metadatas.\n */\n validateMany(entityMetadatas: EntityMetadata[], driver: Driver) {\n entityMetadatas.forEach((entityMetadata) =>\n this.validate(entityMetadata, entityMetadatas, driver),\n )\n this.validateDependencies(entityMetadatas)\n this.validateEagerRelations(entityMetadatas)\n }\n\n /**\n * Validates given entity metadata.\n */\n validate(\n entityMetadata: EntityMetadata,\n allEntityMetadatas: EntityMetadata[],\n driver: Driver,\n ) {\n // check if table metadata has an id\n if (!entityMetadata.primaryColumns.length && !entityMetadata.isJunction)\n throw new MissingPrimaryColumnError(entityMetadata)\n\n // if entity has multiple primary keys and uses custom constraint name,\n // then all primary keys should have the same constraint name\n if (entityMetadata.primaryColumns.length > 1) {\n const areConstraintNamesEqual = entityMetadata.primaryColumns.every(\n (columnMetadata, i, columnMetadatas) =>\n columnMetadata.primaryKeyConstraintName ===\n columnMetadatas[0].primaryKeyConstraintName,\n )\n if (!areConstraintNamesEqual) {\n throw new TypeORMError(\n `Entity ${entityMetadata.name} has multiple primary columns with different constraint names. Constraint names should be the equal.`,\n )\n }\n }\n\n // validate if table is using inheritance it has a discriminator\n // also validate if discriminator values are not empty and not repeated\n if (\n entityMetadata.inheritancePattern === \"STI\" ||\n entityMetadata.tableType === \"entity-child\"\n ) {\n if (!entityMetadata.discriminatorColumn)\n throw new TypeORMError(\n `Entity ${entityMetadata.name} using single-table inheritance, it should also have a discriminator column. Did you forget to put discriminator column options?`,\n )\n\n if (typeof entityMetadata.discriminatorValue === \"undefined\")\n throw new TypeORMError(\n `Entity ${entityMetadata.name} has an undefined discriminator value. Discriminator value should be defined.`,\n )\n\n const sameDiscriminatorValueEntityMetadata =\n allEntityMetadatas.find((metadata) => {\n return (\n metadata !== entityMetadata &&\n (metadata.inheritancePattern === \"STI\" ||\n metadata.tableType === \"entity-child\") &&\n metadata.tableName === entityMetadata.tableName &&\n metadata.discriminatorValue ===\n entityMetadata.discriminatorValue &&\n metadata.inheritanceTree.some(\n (parent) =>\n entityMetadata.inheritanceTree.indexOf(\n parent,\n ) !== -1,\n )\n )\n })\n if (sameDiscriminatorValueEntityMetadata)\n throw new TypeORMError(\n `Entities ${entityMetadata.name} and ${sameDiscriminatorValueEntityMetadata.name} have the same discriminator values. Make sure they are different while using the @ChildEntity decorator.`,\n )\n }\n\n entityMetadata.relationCounts.forEach((relationCount) => {\n if (\n relationCount.relation.isManyToOne ||\n relationCount.relation.isOneToOne\n )\n throw new TypeORMError(\n `Relation count can not be implemented on ManyToOne or OneToOne relations.`,\n )\n })\n\n if (!(driver.options.type === \"mongodb\")) {\n entityMetadata.columns\n .filter((column) => !column.isVirtualProperty)\n .forEach((column) => {\n const normalizedColumn = driver.normalizeType(\n column,\n ) as ColumnType\n if (\n driver.supportedDataTypes.indexOf(normalizedColumn) ===\n -1\n )\n throw new DataTypeNotSupportedError(\n column,\n normalizedColumn,\n driver.options.type,\n )\n if (\n column.length &&\n driver.withLengthColumnTypes.indexOf(\n normalizedColumn,\n ) === -1\n )\n throw new TypeORMError(\n `Column ${column.propertyName} of Entity ${entityMetadata.name} does not support length property.`,\n )\n if (\n column.type === \"enum\" &&\n !column.enum &&\n !column.enumName\n )\n throw new TypeORMError(\n `Column \"${column.propertyName}\" of Entity \"${entityMetadata.name}\" is defined as enum, but missing \"enum\" or \"enumName\" properties.`,\n )\n })\n }\n\n if (\n DriverUtils.isMySQLFamily(driver) ||\n driver.options.type === \"aurora-mysql\"\n ) {\n const generatedColumns = entityMetadata.columns.filter(\n (column) =>\n column.isGenerated && column.generationStrategy !== \"uuid\",\n )\n if (generatedColumns.length > 1)\n throw new TypeORMError(\n `Error in ${entityMetadata.name} entity. There can be only one auto-increment column in MySql table.`,\n )\n }\n\n // for mysql we are able to not define a default selected database, instead all entities can have their database\n // defined in their decorators. To make everything work either all entities must have database define and we\n // can live without database set in the connection options, either database in the connection options must be set\n if (DriverUtils.isMySQLFamily(driver)) {\n const metadatasWithDatabase = allEntityMetadatas.filter(\n (metadata) => metadata.database,\n )\n if (metadatasWithDatabase.length === 0 && !driver.database)\n throw new NoConnectionOptionError(\"database\")\n }\n\n if (driver.options.type === \"mssql\") {\n const charsetColumns = entityMetadata.columns.filter(\n (column) => column.charset,\n )\n if (charsetColumns.length > 1)\n throw new TypeORMError(\n `Character set specifying is not supported in Sql Server`,\n )\n }\n\n // Postgres supports only STORED generated columns.\n if (driver.options.type === \"postgres\") {\n const virtualColumn = entityMetadata.columns.find(\n (column) =>\n column.asExpression &&\n (!column.generatedType ||\n column.generatedType === \"VIRTUAL\"),\n )\n if (virtualColumn)\n throw new TypeORMError(\n `Column \"${virtualColumn.propertyName}\" of Entity \"${entityMetadata.name}\" is defined as VIRTUAL, but Postgres supports only STORED generated columns.`,\n )\n }\n\n // check if relations are all without initialized properties\n const entityInstance = entityMetadata.create(undefined, {\n fromDeserializer: true,\n })\n entityMetadata.relations.forEach((relation) => {\n if (relation.isManyToMany || relation.isOneToMany) {\n // we skip relations for which persistence is disabled since initialization in them cannot harm somehow\n if (relation.persistenceEnabled === false) return\n\n // get entity relation value and check if its an array\n const relationInitializedValue =\n relation.getEntityValue(entityInstance)\n if (Array.isArray(relationInitializedValue))\n throw new InitializedRelationError(relation)\n }\n })\n\n // validate relations\n entityMetadata.relations.forEach((relation) => {\n // check join tables:\n // using JoinTable is possible only on one side of the many-to-many relation\n // todo(dima): fix\n // if (relation.joinTable) {\n // if (!relation.isManyToMany)\n // throw new UsingJoinTableIsNotAllowedError(entityMetadata, relation);\n // // if there is inverse side of the relation, then check if it does not have join table too\n // if (relation.hasInverseSide && relation.inverseRelation.joinTable)\n // throw new UsingJoinTableOnlyOnOneSideAllowedError(entityMetadata, relation);\n // }\n // check join columns:\n // using JoinColumn is possible only on one side of the relation and on one-to-one, many-to-one relation types\n // first check if relation is one-to-one or many-to-one\n // todo(dima): fix\n /*if (relation.joinColumn) {\n\n // join column can be applied only on one-to-one and many-to-one relations\n if (!relation.isOneToOne && !relation.isManyToOne)\n throw new UsingJoinColumnIsNotAllowedError(entityMetadata, relation);\n\n // if there is inverse side of the relation, then check if it does not have join table too\n if (relation.hasInverseSide && relation.inverseRelation.joinColumn && relation.isOneToOne)\n throw new UsingJoinColumnOnlyOnOneSideAllowedError(entityMetadata, relation);\n\n // check if join column really has referenced column\n if (relation.joinColumn && !relation.joinColumn.referencedColumn)\n throw new TypeORMError(`Join column does not have referenced column set`);\n\n }\n\n // if its a one-to-one relation and JoinColumn is missing on both sides of the relation\n // or its one-side relation without JoinColumn we should give an error\n if (!relation.joinColumn && relation.isOneToOne && (!relation.hasInverseSide || !relation.inverseRelation.joinColumn))\n throw new MissingJoinColumnError(entityMetadata, relation);*/\n // if its a many-to-many relation and JoinTable is missing on both sides of the relation\n // or its one-side relation without JoinTable we should give an error\n // todo(dima): fix it\n // if (!relation.joinTable && relation.isManyToMany && (!relation.hasInverseSide || !relation.inverseRelation.joinTable))\n // throw new MissingJoinTableError(entityMetadata, relation);\n // todo: validate if its one-to-one and side which does not have join column MUST have inverse side\n // todo: validate if its many-to-many and side which does not have join table MUST have inverse side\n // todo: if there is a relation, and inverse side is specified only on one side, shall we give error\n // todo: with message like: \"Inverse side is specified only on one side of the relationship. Specify on other side too to prevent confusion\".\n // todo: add validation if there two entities with the same target, and show error message with description of the problem (maybe file was renamed/moved but left in output directory)\n // todo: check if there are multiple columns on the same column applied.\n // todo: check column type if is missing in relational databases (throw new TypeORMError(`Column type of ${type} cannot be determined.`);)\n // todo: include driver-specific checks. for example in mongodb empty prefixes are not allowed\n // todo: if multiple columns with same name - throw exception, including cases when columns are in embeds with same prefixes or without prefix at all\n // todo: if multiple primary key used, at least one of them must be unique or @Index decorator must be set on entity\n // todo: check if entity with duplicate names, some decorators exist\n })\n\n // make sure cascade remove is not set for both sides of relationships (can be set in OneToOne decorators)\n entityMetadata.relations.forEach((relation) => {\n const isCircularCascadeRemove =\n relation.isCascadeRemove &&\n relation.inverseRelation &&\n relation.inverseRelation!.isCascadeRemove\n if (isCircularCascadeRemove)\n throw new TypeORMError(\n `Relation ${entityMetadata.name}#${\n relation.propertyName\n } and ${relation.inverseRelation!.entityMetadata.name}#${\n relation.inverseRelation!.propertyName\n } both has cascade remove set. ` +\n `This may lead to unexpected circular removals. Please set cascade remove only from one side of relationship.`,\n )\n }) // todo: maybe better just deny removal from one to one relation without join column?\n\n entityMetadata.eagerRelations.forEach((relation) => {})\n }\n\n /**\n * Validates dependencies of the entity metadatas.\n */\n protected validateDependencies(entityMetadatas: EntityMetadata[]) {\n const graph = new DepGraph()\n entityMetadatas.forEach((entityMetadata) => {\n graph.addNode(entityMetadata.name)\n })\n entityMetadatas.forEach((entityMetadata) => {\n entityMetadata.relationsWithJoinColumns\n .filter((relation) => !relation.isNullable)\n .forEach((relation) => {\n graph.addDependency(\n entityMetadata.name,\n relation.inverseEntityMetadata.name,\n )\n })\n })\n try {\n graph.overallOrder()\n } catch (err) {\n throw new CircularRelationsError(\n err.toString().replace(\"Error: Dependency Cycle Found: \", \"\"),\n )\n }\n }\n\n /**\n * Validates eager relations to prevent circular dependency in them.\n */\n protected validateEagerRelations(entityMetadatas: EntityMetadata[]) {\n entityMetadatas.forEach((entityMetadata) => {\n entityMetadata.eagerRelations.forEach((relation) => {\n if (\n relation.inverseRelation &&\n relation.inverseRelation.isEager\n )\n throw new TypeORMError(\n `Circular eager relations are disallowed. ` +\n `${entityMetadata.targetName}#${relation.propertyPath} contains \"eager: true\", and its inverse side ` +\n `${relation.inverseEntityMetadata.targetName}#${relation.inverseRelation.propertyPath} contains \"eager: true\" as well.` +\n ` Remove \"eager: true\" from one side of the relation.`,\n )\n })\n })\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../browser/src/metadata-builder/EntityMetadataValidator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAA;AAC9E,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAA;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAE3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAA;AAE9E,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAA;AAC1E,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAA;AAC5E,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAEnD,mEAAmE;AACnE,6FAA6F;AAC7F,sEAAsE;AACtE,mGAAmG;AACnG,2GAA2G;AAC3G,6DAA6D;AAC7D,uEAAuE;AACvE,iFAAiF;AAEjF,2FAA2F;AAC3F,wHAAwH;AACxH,gIAAgI;AAChI,mGAAmG;AACnG,8EAA8E;AAC9E,8CAA8C;AAC9C,yDAAyD;AAEzD;;GAEG;AACH,MAAM,OAAO,uBAAuB;IAChC,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;OAEG;IACH,YAAY,CAAC,eAAiC,EAAE,MAAc;QAC1D,eAAe,CAAC,OAAO,CAAC,CAAC,cAAc,EAAE,EAAE,CACvC,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE,eAAe,EAAE,MAAM,CAAC,CACzD,CAAA;QACD,IAAI,CAAC,oBAAoB,CAAC,eAAe,CAAC,CAAA;QAC1C,IAAI,CAAC,sBAAsB,CAAC,eAAe,CAAC,CAAA;IAChD,CAAC;IAED;;OAEG;IACH,QAAQ,CACJ,cAA8B,EAC9B,kBAAoC,EACpC,MAAc;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AM,IAAI,YAAY,CAClB,2CAA2C;wBACvC,GAAG,cAAc,CAAC,UAAU,IAAI,QAAQ,CAAC,YAAY,gDAAgD;wBACrG,GAAG,QAAQ,CAAC,qBAAqB,CAAC,UAAU,IAAI,QAAQ,CAAC,eAAe,CAAC,YAAY,kCAAkC;wBACvH,sDAAsD,CAC7D,CAAA;YACT,CAAC,CAAC,CAAA;QACN,CAAC,CAAC,CAAA;IACN,CAAC;CACJ","file":"EntityMetadataValidator.js","sourcesContent":["import { EntityMetadata } from \"../metadata/EntityMetadata\"\nimport { MissingPrimaryColumnError } from \"../error/MissingPrimaryColumnError\"\nimport { CircularRelationsError } from \"../error/CircularRelationsError\"\nimport { DepGraph } from \"../util/DepGraph\"\nimport { Driver } from \"../driver/Driver\"\nimport { DataTypeNotSupportedError } from \"../error/DataTypeNotSupportedError\"\nimport { ColumnType } from \"../driver/types/ColumnTypes\"\nimport { NoConnectionOptionError } from \"../error/NoConnectionOptionError\"\nimport { InitializedRelationError } from \"../error/InitializedRelationError\"\nimport { TypeORMError } from \"../error\"\nimport { DriverUtils } from \"../driver/DriverUtils\"\n\n/// todo: add check if there are multiple tables with the same name\n/// todo: add checks when generated column / table names are too long for the specific driver\n// todo: type in function validation, inverse side function validation\n// todo: check on build for duplicate names, since naming checking was removed from MetadataStorage\n// todo: duplicate name checking for: table, relation, column, index, naming strategy, join tables/columns?\n// todo: check if multiple tree parent metadatas in validator\n// todo: tree decorators can be used only on closure table (validation)\n// todo: throw error if parent tree metadata was not specified in a closure table\n\n// todo: MetadataArgsStorage: type in function validation, inverse side function validation\n// todo: MetadataArgsStorage: check on build for duplicate names, since naming checking was removed from MetadataStorage\n// todo: MetadataArgsStorage: duplicate name checking for: table, relation, column, index, naming strategy, join tables/columns?\n// todo: MetadataArgsStorage: check for duplicate targets too since this check has been removed too\n// todo: check if relation decorator contains primary: true and nullable: true\n// todo: check column length, precision. scale\n// todo: MySQL index can be unique or spatial or fulltext\n\n/**\n * Validates built entity metadatas.\n */\nexport class EntityMetadataValidator {\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Validates all given entity metadatas.\n */\n validateMany(entityMetadatas: EntityMetadata[], driver: Driver) {\n entityMetadatas.forEach((entityMetadata) =>\n this.validate(entityMetadata, entityMetadatas, driver),\n )\n this.validateDependencies(entityMetadatas)\n this.validateEagerRelations(entityMetadatas)\n }\n\n /**\n * Validates given entity metadata.\n */\n validate(\n entityMetadata: EntityMetadata,\n allEntityMetadatas: EntityMetadata[],\n driver: Driver,\n ) {\n // check if table metadata has an id\n if (!entityMetadata.primaryColumns.length && !entityMetadata.isJunction)\n throw new MissingPrimaryColumnError(entityMetadata)\n\n // if entity has multiple primary keys and uses custom constraint name,\n // then all primary keys should have the same constraint name\n if (entityMetadata.primaryColumns.length > 1) {\n const areConstraintNamesEqual = entityMetadata.primaryColumns.every(\n (columnMetadata, i, columnMetadatas) =>\n columnMetadata.primaryKeyConstraintName ===\n columnMetadatas[0].primaryKeyConstraintName,\n )\n if (!areConstraintNamesEqual) {\n throw new TypeORMError(\n `Entity ${entityMetadata.name} has multiple primary columns with different constraint names. Constraint names should be the equal.`,\n )\n }\n }\n\n // validate if table is using inheritance it has a discriminator\n // also validate if discriminator values are not empty and not repeated\n if (\n entityMetadata.inheritancePattern === \"STI\" ||\n entityMetadata.tableType === \"entity-child\"\n ) {\n if (!entityMetadata.discriminatorColumn)\n throw new TypeORMError(\n `Entity ${entityMetadata.name} using single-table inheritance, it should also have a discriminator column. Did you forget to put discriminator column options?`,\n )\n\n if (typeof entityMetadata.discriminatorValue === \"undefined\")\n throw new TypeORMError(\n `Entity ${entityMetadata.name} has an undefined discriminator value. Discriminator value should be defined.`,\n )\n\n const sameDiscriminatorValueEntityMetadata =\n allEntityMetadatas.find((metadata) => {\n return (\n metadata !== entityMetadata &&\n (metadata.inheritancePattern === \"STI\" ||\n metadata.tableType === \"entity-child\") &&\n metadata.tableName === entityMetadata.tableName &&\n metadata.discriminatorValue ===\n entityMetadata.discriminatorValue &&\n metadata.inheritanceTree.some(\n (parent) =>\n entityMetadata.inheritanceTree.indexOf(\n parent,\n ) !== -1,\n )\n )\n })\n if (sameDiscriminatorValueEntityMetadata)\n throw new TypeORMError(\n `Entities ${entityMetadata.name} and ${sameDiscriminatorValueEntityMetadata.name} have the same discriminator values. Make sure they are different while using the @ChildEntity decorator.`,\n )\n }\n\n entityMetadata.relationCounts.forEach((relationCount) => {\n if (\n relationCount.relation.isManyToOne ||\n relationCount.relation.isOneToOne\n )\n throw new TypeORMError(\n `Relation count can not be implemented on ManyToOne or OneToOne relations.`,\n )\n })\n\n if (!(driver.options.type === \"mongodb\")) {\n entityMetadata.columns\n .filter((column) => !column.isVirtualProperty)\n .forEach((column) => {\n const normalizedColumn = driver.normalizeType(\n column,\n ) as ColumnType\n if (\n driver.supportedDataTypes.indexOf(normalizedColumn) ===\n -1\n )\n throw new DataTypeNotSupportedError(\n column,\n normalizedColumn,\n driver.options.type,\n )\n if (\n column.length &&\n driver.withLengthColumnTypes.indexOf(\n normalizedColumn,\n ) === -1\n )\n throw new TypeORMError(\n `Column ${column.propertyName} of Entity ${entityMetadata.name} does not support length property.`,\n )\n if (\n column.type === \"enum\" &&\n !column.enum &&\n !column.enumName\n )\n throw new TypeORMError(\n `Column \"${column.propertyName}\" of Entity \"${entityMetadata.name}\" is defined as enum, but missing \"enum\" or \"enumName\" properties.`,\n )\n })\n }\n\n if (\n DriverUtils.isMySQLFamily(driver) ||\n driver.options.type === \"aurora-mysql\"\n ) {\n const generatedColumns = entityMetadata.columns.filter(\n (column) =>\n column.isGenerated && column.generationStrategy !== \"uuid\",\n )\n if (generatedColumns.length > 1)\n throw new TypeORMError(\n `Error in ${entityMetadata.name} entity. There can be only one auto-increment column in MySql table.`,\n )\n }\n\n // for mysql we are able to not define a default selected database, instead all entities can have their database\n // defined in their decorators. To make everything work either all entities must have database define and we\n // can live without database set in the connection options, either database in the connection options must be set\n if (DriverUtils.isMySQLFamily(driver)) {\n const metadatasWithDatabase = allEntityMetadatas.filter(\n (metadata) => metadata.database,\n )\n if (metadatasWithDatabase.length === 0 && !driver.database)\n throw new NoConnectionOptionError(\"database\")\n }\n\n if (driver.options.type === \"mssql\") {\n const charsetColumns = entityMetadata.columns.filter(\n (column) => column.charset,\n )\n if (charsetColumns.length > 1)\n throw new TypeORMError(\n `Character set specifying is not supported in Sql Server`,\n )\n }\n\n // Postgres supports only STORED generated columns.\n if (driver.options.type === \"postgres\") {\n const virtualColumn = entityMetadata.columns.find(\n (column) =>\n column.asExpression &&\n (!column.generatedType ||\n column.generatedType === \"VIRTUAL\"),\n )\n if (virtualColumn)\n throw new TypeORMError(\n `Column \"${virtualColumn.propertyName}\" of Entity \"${entityMetadata.name}\" is defined as VIRTUAL, but Postgres supports only STORED generated columns.`,\n )\n }\n\n // check if relations are all without initialized properties\n const entityInstance = entityMetadata.create(undefined, {\n fromDeserializer: true,\n })\n entityMetadata.relations.forEach((relation) => {\n if (relation.isManyToMany || relation.isOneToMany) {\n // we skip relations for which persistence is disabled since initialization in them cannot harm somehow\n if (relation.persistenceEnabled === false) return\n\n // get entity relation value and check if its an array\n const relationInitializedValue =\n relation.getEntityValue(entityInstance)\n if (Array.isArray(relationInitializedValue))\n throw new InitializedRelationError(relation)\n }\n })\n\n // validate relations\n entityMetadata.relations.forEach((relation) => {\n // check OnDeleteTypes\n if (\n driver.supportedOnDeleteTypes &&\n relation.onDelete &&\n !driver.supportedOnDeleteTypes.includes(relation.onDelete)\n ) {\n throw new TypeORMError(\n `OnDeleteType \"${relation.onDelete}\" is not supported for ${driver.options.type}!`,\n )\n }\n\n // check OnUpdateTypes\n if (\n driver.supportedOnUpdateTypes &&\n relation.onUpdate &&\n !driver.supportedOnUpdateTypes.includes(relation.onUpdate)\n ) {\n throw new TypeORMError(\n `OnUpdateType \"${relation.onUpdate}\" is not valid for ${driver.options.type}!`,\n )\n }\n\n // check join tables:\n // using JoinTable is possible only on one side of the many-to-many relation\n // todo(dima): fix\n // if (relation.joinTable) {\n // if (!relation.isManyToMany)\n // throw new UsingJoinTableIsNotAllowedError(entityMetadata, relation);\n // // if there is inverse side of the relation, then check if it does not have join table too\n // if (relation.hasInverseSide && relation.inverseRelation.joinTable)\n // throw new UsingJoinTableOnlyOnOneSideAllowedError(entityMetadata, relation);\n // }\n // check join columns:\n // using JoinColumn is possible only on one side of the relation and on one-to-one, many-to-one relation types\n // first check if relation is one-to-one or many-to-one\n // todo(dima): fix\n /*if (relation.joinColumn) {\n\n // join column can be applied only on one-to-one and many-to-one relations\n if (!relation.isOneToOne && !relation.isManyToOne)\n throw new UsingJoinColumnIsNotAllowedError(entityMetadata, relation);\n\n // if there is inverse side of the relation, then check if it does not have join table too\n if (relation.hasInverseSide && relation.inverseRelation.joinColumn && relation.isOneToOne)\n throw new UsingJoinColumnOnlyOnOneSideAllowedError(entityMetadata, relation);\n\n // check if join column really has referenced column\n if (relation.joinColumn && !relation.joinColumn.referencedColumn)\n throw new TypeORMError(`Join column does not have referenced column set`);\n\n }\n\n // if its a one-to-one relation and JoinColumn is missing on both sides of the relation\n // or its one-side relation without JoinColumn we should give an error\n if (!relation.joinColumn && relation.isOneToOne && (!relation.hasInverseSide || !relation.inverseRelation.joinColumn))\n throw new MissingJoinColumnError(entityMetadata, relation);*/\n // if its a many-to-many relation and JoinTable is missing on both sides of the relation\n // or its one-side relation without JoinTable we should give an error\n // todo(dima): fix it\n // if (!relation.joinTable && relation.isManyToMany && (!relation.hasInverseSide || !relation.inverseRelation.joinTable))\n // throw new MissingJoinTableError(entityMetadata, relation);\n // todo: validate if its one-to-one and side which does not have join column MUST have inverse side\n // todo: validate if its many-to-many and side which does not have join table MUST have inverse side\n // todo: if there is a relation, and inverse side is specified only on one side, shall we give error\n // todo: with message like: \"Inverse side is specified only on one side of the relationship. Specify on other side too to prevent confusion\".\n // todo: add validation if there two entities with the same target, and show error message with description of the problem (maybe file was renamed/moved but left in output directory)\n // todo: check if there are multiple columns on the same column applied.\n // todo: check column type if is missing in relational databases (throw new TypeORMError(`Column type of ${type} cannot be determined.`);)\n // todo: include driver-specific checks. for example in mongodb empty prefixes are not allowed\n // todo: if multiple columns with same name - throw exception, including cases when columns are in embeds with same prefixes or without prefix at all\n // todo: if multiple primary key used, at least one of them must be unique or @Index decorator must be set on entity\n // todo: check if entity with duplicate names, some decorators exist\n })\n\n // make sure cascade remove is not set for both sides of relationships (can be set in OneToOne decorators)\n entityMetadata.relations.forEach((relation) => {\n const isCircularCascadeRemove =\n relation.isCascadeRemove &&\n relation.inverseRelation &&\n relation.inverseRelation!.isCascadeRemove\n if (isCircularCascadeRemove)\n throw new TypeORMError(\n `Relation ${entityMetadata.name}#${\n relation.propertyName\n } and ${relation.inverseRelation!.entityMetadata.name}#${\n relation.inverseRelation!.propertyName\n } both has cascade remove set. ` +\n `This may lead to unexpected circular removals. Please set cascade remove only from one side of relationship.`,\n )\n }) // todo: maybe better just deny removal from one to one relation without join column?\n\n entityMetadata.eagerRelations.forEach((relation) => {})\n }\n\n /**\n * Validates dependencies of the entity metadatas.\n */\n protected validateDependencies(entityMetadatas: EntityMetadata[]) {\n const graph = new DepGraph()\n entityMetadatas.forEach((entityMetadata) => {\n graph.addNode(entityMetadata.name)\n })\n entityMetadatas.forEach((entityMetadata) => {\n entityMetadata.relationsWithJoinColumns\n .filter((relation) => !relation.isNullable)\n .forEach((relation) => {\n graph.addDependency(\n entityMetadata.name,\n relation.inverseEntityMetadata.name,\n )\n })\n })\n try {\n graph.overallOrder()\n } catch (err) {\n throw new CircularRelationsError(\n err.toString().replace(\"Error: Dependency Cycle Found: \", \"\"),\n )\n }\n }\n\n /**\n * Validates eager relations to prevent circular dependency in them.\n */\n protected validateEagerRelations(entityMetadatas: EntityMetadata[]) {\n entityMetadatas.forEach((entityMetadata) => {\n entityMetadata.eagerRelations.forEach((relation) => {\n if (\n relation.inverseRelation &&\n relation.inverseRelation.isEager\n )\n throw new TypeORMError(\n `Circular eager relations are disallowed. ` +\n `${entityMetadata.targetName}#${relation.propertyPath} contains \"eager: true\", and its inverse side ` +\n `${relation.inverseEntityMetadata.targetName}#${relation.inverseRelation.propertyPath} contains \"eager: true\" as well.` +\n ` Remove \"eager: true\" from one side of the relation.`,\n )\n })\n })\n }\n}\n"],"sourceRoot":".."}
@@ -2,12 +2,14 @@ import { RelationMetadata } from "../metadata/RelationMetadata";
2
2
  import { DataSource } from "../data-source/DataSource";
3
3
  import { ObjectLiteral } from "../common/ObjectLiteral";
4
4
  import { SelectQueryBuilder } from "./SelectQueryBuilder";
5
+ import { QueryRunner } from "../query-runner/QueryRunner";
5
6
  /**
6
7
  * Loads relation ids for the given entities.
7
8
  */
8
9
  export declare class RelationIdLoader {
9
10
  private connection;
10
- constructor(connection: DataSource);
11
+ protected queryRunner?: QueryRunner | undefined;
12
+ constructor(connection: DataSource, queryRunner?: QueryRunner | undefined);
11
13
  /**
12
14
  * Loads relation ids of the given entity or entities.
13
15
  */
@@ -6,8 +6,9 @@ export class RelationIdLoader {
6
6
  // -------------------------------------------------------------------------
7
7
  // Constructor
8
8
  // -------------------------------------------------------------------------
9
- constructor(connection) {
9
+ constructor(connection, queryRunner) {
10
10
  this.connection = connection;
11
+ this.queryRunner = queryRunner;
11
12
  }
12
13
  // -------------------------------------------------------------------------
13
14
  // Public Methods
@@ -49,7 +50,7 @@ export class RelationIdLoader {
49
50
  ? entitiesOrEntities
50
51
  : [entitiesOrEntities];
51
52
  if (!relatedEntityOrEntities) {
52
- relatedEntityOrEntities = await this.connection.relationLoader.load(relation, entitiesOrEntities, undefined, queryBuilder);
53
+ relatedEntityOrEntities = await this.connection.relationLoader.load(relation, entitiesOrEntities, this.queryRunner, queryBuilder);
53
54
  if (!relatedEntityOrEntities.length)
54
55
  return entities.map((entity) => ({
55
56
  entity: entity,
@@ -170,7 +171,7 @@ export class RelationIdLoader {
170
171
  const inverseColumns = relation.isOwning
171
172
  ? junctionMetadata.inverseColumns
172
173
  : junctionMetadata.ownerColumns;
173
- const qb = this.connection.createQueryBuilder();
174
+ const qb = this.connection.createQueryBuilder(this.queryRunner);
174
175
  // select all columns from junction table
175
176
  columns.forEach((column) => {
176
177
  const columnName = DriverUtils.buildAlias(this.connection.driver, undefined, column.referencedColumn.entityMetadata.name +
@@ -347,7 +348,7 @@ export class RelationIdLoader {
347
348
  return Promise.resolve(relationIdMaps);
348
349
  }
349
350
  // select all columns we need
350
- const qb = this.connection.createQueryBuilder();
351
+ const qb = this.connection.createQueryBuilder(this.queryRunner);
351
352
  relation.entityMetadata.primaryColumns.forEach((primaryColumn) => {
352
353
  const columnName = DriverUtils.buildAlias(this.connection.driver, undefined, primaryColumn.entityMetadata.name +
353
354
  "_" +
@@ -436,7 +437,7 @@ export class RelationIdLoader {
436
437
  }
437
438
  const mainAlias = relation.entityMetadata.targetName;
438
439
  // select all columns we need
439
- const qb = this.connection.createQueryBuilder();
440
+ const qb = this.connection.createQueryBuilder(this.queryRunner);
440
441
  relation.entityMetadata.primaryColumns.forEach((primaryColumn) => {
441
442
  const columnName = DriverUtils.buildAlias(this.connection.driver, undefined, primaryColumn.entityMetadata.name +
442
443
  "_" +
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/query-builder/RelationIdLoader.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAEnD;;GAEG;AACH,MAAM,OAAO,gBAAgB;IACzB,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YAAoB,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;IAAG,CAAC;IAE9C,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;OAEG;IACH,IAAI,CACA,QAA0B,EAC1B,gBAAiD,EACjD,8BAAgE;QAEhE,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,gBAAgB,CAAC;YAC5C,CAAC,CAAC,gBAAgB;YAClB,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAA;QACxB,MAAM,eAAe,GAAG,K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GAAG,eAAe,CAAA;oBAClD,EAAE,CAAC,YAAY,CACX,SAAS,EACT,UAAU,CAAC,gBAAiB,CAAC,cAAc,CACvC,MAAM,CACT,CACJ,CAAA;oBACD,OAAO,CACH,SAAS;wBACT,GAAG;wBACH,UAAU,CAAC,YAAY;wBACvB,MAAM;wBACN,SAAS,CACZ,CAAA;gBACL,CAAC,CAAC;qBACD,IAAI,CAAC,OAAO,CAAC,CAAA;YACtB,CAAC,CAAC;iBACD,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,GAAG,GAAG,SAAS,GAAG,GAAG,CAAC;iBACzC,IAAI,CAAC,MAAM,CAAC,CAAA;SACpB;QAED,gBAAgB;QAChB,OAAO,EAAE;aACJ,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,MAAM,EAAE,SAAS,CAAC;aAC/C,KAAK,CAAC,SAAS,CAAC;aAChB,UAAU,EAAE,CAAA;IACrB,CAAC;CACJ","file":"RelationIdLoader.js","sourcesContent":["import { RelationMetadata } from \"../metadata/RelationMetadata\"\nimport { ColumnMetadata } from \"../metadata/ColumnMetadata\"\nimport { DataSource } from \"../data-source/DataSource\"\nimport { ObjectLiteral } from \"../common/ObjectLiteral\"\nimport { SelectQueryBuilder } from \"./SelectQueryBuilder\"\nimport { DriverUtils } from \"../driver/DriverUtils\"\n\n/**\n * Loads relation ids for the given entities.\n */\nexport class RelationIdLoader {\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(private connection: DataSource) {}\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Loads relation ids of the given entity or entities.\n */\n load(\n relation: RelationMetadata,\n entityOrEntities: ObjectLiteral | ObjectLiteral[],\n relatedEntityOrRelatedEntities?: ObjectLiteral | ObjectLiteral[],\n ): Promise<any[]> {\n const entities = Array.isArray(entityOrEntities)\n ? entityOrEntities\n : [entityOrEntities]\n const relatedEntities = Array.isArray(relatedEntityOrRelatedEntities)\n ? relatedEntityOrRelatedEntities\n : relatedEntityOrRelatedEntities\n ? [relatedEntityOrRelatedEntities]\n : undefined\n\n // load relation ids depend of relation type\n if (relation.isManyToMany) {\n return this.loadForManyToMany(relation, entities, relatedEntities)\n } else if (relation.isManyToOne || relation.isOneToOneOwner) {\n return this.loadForManyToOneAndOneToOneOwner(\n relation,\n entities,\n relatedEntities,\n )\n } else {\n // if (relation.isOneToMany || relation.isOneToOneNotOwner) {\n return this.loadForOneToManyAndOneToOneNotOwner(\n relation,\n entities,\n relatedEntities,\n )\n }\n }\n\n /**\n * Loads relation ids of the given entities and groups them into the object with parent and children.\n *\n * todo: extract this method?\n */\n async loadManyToManyRelationIdsAndGroup<\n E1 extends ObjectLiteral,\n E2 extends ObjectLiteral,\n >(\n relation: RelationMetadata,\n entitiesOrEntities: E1 | E1[],\n relatedEntityOrEntities?: E2 | E2[],\n queryBuilder?: SelectQueryBuilder<any>,\n ): Promise<{ entity: E1; related?: E2 | E2[] }[]> {\n // console.log(\"relation:\", relation.propertyName);\n // console.log(\"entitiesOrEntities\", entitiesOrEntities);\n const isMany = relation.isManyToMany || relation.isOneToMany\n const entities: E1[] = Array.isArray(entitiesOrEntities)\n ? entitiesOrEntities\n : [entitiesOrEntities]\n\n if (!relatedEntityOrEntities) {\n relatedEntityOrEntities = await this.connection.relationLoader.load(\n relation,\n entitiesOrEntities,\n undefined,\n queryBuilder,\n )\n if (!relatedEntityOrEntities.length)\n return entities.map((entity) => ({\n entity: entity,\n related: isMany ? [] : undefined,\n }))\n }\n // const relationIds = await this.load(relation, relatedEntityOrEntities!, entitiesOrEntities);\n const relationIds = await this.load(\n relation,\n entitiesOrEntities,\n relatedEntityOrEntities,\n )\n // console.log(\"entities\", entities);\n // console.log(\"relatedEntityOrEntities\", relatedEntityOrEntities);\n // console.log(\"relationIds\", relationIds);\n\n const relatedEntities: E2[] = Array.isArray(relatedEntityOrEntities)\n ? relatedEntityOrEntities\n : [relatedEntityOrEntities!]\n\n let columns: ColumnMetadata[] = [],\n inverseColumns: ColumnMetadata[] = []\n if (relation.isManyToManyOwner) {\n columns = relation.junctionEntityMetadata!.inverseColumns.map(\n (column) => column.referencedColumn!,\n )\n inverseColumns = relation.junctionEntityMetadata!.ownerColumns.map(\n (column) => column.referencedColumn!,\n )\n } else if (relation.isManyToManyNotOwner) {\n columns = relation.junctionEntityMetadata!.ownerColumns.map(\n (column) => column.referencedColumn!,\n )\n inverseColumns =\n relation.junctionEntityMetadata!.inverseColumns.map(\n (column) => column.referencedColumn!,\n )\n } else if (relation.isManyToOne || relation.isOneToOneOwner) {\n columns = relation.joinColumns.map(\n (column) => column.referencedColumn!,\n )\n inverseColumns = relation.entityMetadata.primaryColumns\n } else if (relation.isOneToMany || relation.isOneToOneNotOwner) {\n columns = relation.inverseRelation!.entityMetadata.primaryColumns\n inverseColumns = relation.inverseRelation!.joinColumns.map(\n (column) => column.referencedColumn!,\n )\n } else {\n }\n\n return entities.map((entity) => {\n const group: { entity: E1; related?: E2 | E2[] } = {\n entity: entity,\n related: isMany ? [] : undefined,\n }\n\n const entityRelationIds = relationIds.filter((relationId) => {\n return inverseColumns.every((column) => {\n return column.compareEntityValue(\n entity,\n relationId[\n column.entityMetadata.name +\n \"_\" +\n column.propertyAliasName\n ],\n )\n })\n })\n if (!entityRelationIds.length) return group\n\n relatedEntities.forEach((relatedEntity) => {\n entityRelationIds.forEach((relationId) => {\n const relatedEntityMatched = columns.every((column) => {\n return column.compareEntityValue(\n relatedEntity,\n relationId[\n DriverUtils.buildAlias(\n this.connection.driver,\n undefined,\n column.entityMetadata.name +\n \"_\" +\n relation.propertyPath.replace(\n \".\",\n \"_\",\n ) +\n \"_\" +\n column.propertyPath.replace(\".\", \"_\"),\n )\n ],\n )\n })\n if (relatedEntityMatched) {\n if (isMany) {\n ;(group.related as E2[]).push(relatedEntity)\n } else {\n group.related = relatedEntity\n }\n }\n })\n })\n return group\n })\n }\n\n /**\n * Loads relation ids of the given entities and maps them into the given entity property.\n async loadManyToManyRelationIdsAndMap(\n relation: RelationMetadata,\n entityOrEntities: ObjectLiteral|ObjectLiteral[],\n mapToEntityOrEntities: ObjectLiteral|ObjectLiteral[],\n propertyName: string\n ): Promise<void> {\n const relationIds = await this.loadManyToManyRelationIds(relation, entityOrEntities, mapToEntityOrEntities);\n const mapToEntities = mapToEntityOrEntities instanceof Array ? mapToEntityOrEntities : [mapToEntityOrEntities];\n const junctionMetadata = relation.junctionEntityMetadata!;\n const mainAlias = junctionMetadata.name;\n const columns = relation.isOwning ? junctionMetadata.inverseColumns : junctionMetadata.ownerColumns;\n const inverseColumns = relation.isOwning ? junctionMetadata.ownerColumns : junctionMetadata.inverseColumns;\n mapToEntities.forEach(mapToEntity => {\n mapToEntity[propertyName] = [];\n relationIds.forEach(relationId => {\n const match = inverseColumns.every(column => {\n return column.referencedColumn!.getEntityValue(mapToEntity) === relationId[mainAlias + \"_\" + column.propertyName];\n });\n if (match) {\n if (columns.length === 1) {\n mapToEntity[propertyName].push(relationId[mainAlias + \"_\" + columns[0].propertyName]);\n } else {\n const value = {};\n columns.forEach(column => {\n column.referencedColumn!.setEntityValue(value, relationId[mainAlias + \"_\" + column.propertyName]);\n });\n mapToEntity[propertyName].push(value);\n }\n }\n });\n });\n }*/\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Loads relation ids for the many-to-many relation.\n */\n protected loadForManyToMany(\n relation: RelationMetadata,\n entities: ObjectLiteral[],\n relatedEntities?: ObjectLiteral[],\n ) {\n const junctionMetadata = relation.junctionEntityMetadata!\n const mainAlias = junctionMetadata.name\n const columns = relation.isOwning\n ? junctionMetadata.ownerColumns\n : junctionMetadata.inverseColumns\n const inverseColumns = relation.isOwning\n ? junctionMetadata.inverseColumns\n : junctionMetadata.ownerColumns\n const qb = this.connection.createQueryBuilder()\n\n // select all columns from junction table\n columns.forEach((column) => {\n const columnName = DriverUtils.buildAlias(\n this.connection.driver,\n undefined,\n column.referencedColumn!.entityMetadata.name +\n \"_\" +\n column.referencedColumn!.propertyPath.replace(\".\", \"_\"),\n )\n qb.addSelect(mainAlias + \".\" + column.propertyPath, columnName)\n })\n inverseColumns.forEach((column) => {\n const columnName = DriverUtils.buildAlias(\n this.connection.driver,\n undefined,\n column.referencedColumn!.entityMetadata.name +\n \"_\" +\n relation.propertyPath.replace(\".\", \"_\") +\n \"_\" +\n column.referencedColumn!.propertyPath.replace(\".\", \"_\"),\n )\n qb.addSelect(mainAlias + \".\" + column.propertyPath, columnName)\n })\n\n // add conditions for the given entities\n let condition1 = \"\"\n if (columns.length === 1) {\n const values = entities.map((entity) =>\n columns[0].referencedColumn!.getEntityValue(entity),\n )\n const areAllNumbers = values.every(\n (value) => typeof value === \"number\",\n )\n\n if (areAllNumbers) {\n condition1 = `${mainAlias}.${\n columns[0].propertyPath\n } IN (${values.join(\", \")})`\n } else {\n qb.setParameter(\"values1\", values)\n condition1 =\n mainAlias +\n \".\" +\n columns[0].propertyPath +\n \" IN (:...values1)\" // todo: use ANY for postgres\n }\n } else {\n condition1 =\n \"(\" +\n entities\n .map((entity, entityIndex) => {\n return columns\n .map((column) => {\n const paramName =\n \"entity1_\" +\n entityIndex +\n \"_\" +\n column.propertyName\n qb.setParameter(\n paramName,\n column.referencedColumn!.getEntityValue(\n entity,\n ),\n )\n return (\n mainAlias +\n \".\" +\n column.propertyPath +\n \" = :\" +\n paramName\n )\n })\n .join(\" AND \")\n })\n .map((condition) => \"(\" + condition + \")\")\n .join(\" OR \") +\n \")\"\n }\n\n // add conditions for the given inverse entities\n let condition2 = \"\"\n if (relatedEntities) {\n if (inverseColumns.length === 1) {\n const values = relatedEntities.map((entity) =>\n inverseColumns[0].referencedColumn!.getEntityValue(entity),\n )\n const areAllNumbers = values.every(\n (value) => typeof value === \"number\",\n )\n\n if (areAllNumbers) {\n condition2 = `${mainAlias}.${\n inverseColumns[0].propertyPath\n } IN (${values.join(\", \")})`\n } else {\n qb.setParameter(\"values2\", values)\n condition2 =\n mainAlias +\n \".\" +\n inverseColumns[0].propertyPath +\n \" IN (:...values2)\" // todo: use ANY for postgres\n }\n } else {\n condition2 =\n \"(\" +\n relatedEntities\n .map((entity, entityIndex) => {\n return inverseColumns\n .map((column) => {\n const paramName =\n \"entity2_\" +\n entityIndex +\n \"_\" +\n column.propertyName\n qb.setParameter(\n paramName,\n column.referencedColumn!.getEntityValue(\n entity,\n ),\n )\n return (\n mainAlias +\n \".\" +\n column.propertyPath +\n \" = :\" +\n paramName\n )\n })\n .join(\" AND \")\n })\n .map((condition) => \"(\" + condition + \")\")\n .join(\" OR \") +\n \")\"\n }\n }\n\n // qb.from(junctionMetadata.target, mainAlias)\n // .where(condition1 + (condition2 ? \" AND \" + condition2 : \"\"));\n //\n // // execute query\n // const { values1, values2 } = qb.getParameters();\n // console.log(`I can do it`, { values1, values2 });\n // if (inverseColumns.length === 1 &&\n // columns.length === 1 &&\n // this.connection.driver instanceof SqliteDriver &&\n // (values1.length + values2.length) > 500 &&\n // values1.length === values2.length) {\n // console.log(`I can do it`);\n // return qb.getRawMany();\n //\n // } else {\n // return qb.getRawMany();\n // }\n\n // execute query\n const condition = [condition1, condition2]\n .filter((v) => v.length > 0)\n .join(\" AND \")\n return qb\n .from(junctionMetadata.target, mainAlias)\n .where(condition)\n .getRawMany()\n }\n\n /**\n * Loads relation ids for the many-to-one and one-to-one owner relations.\n */\n protected loadForManyToOneAndOneToOneOwner(\n relation: RelationMetadata,\n entities: ObjectLiteral[],\n relatedEntities?: ObjectLiteral[],\n ) {\n const mainAlias = relation.entityMetadata.targetName\n\n // console.log(\"entitiesx\", entities);\n // console.log(\"relatedEntitiesx\", relatedEntities);\n const hasAllJoinColumnsInEntity = relation.joinColumns.every(\n (joinColumn) => {\n return !!relation.entityMetadata.nonVirtualColumns.find(\n (column) => column === joinColumn,\n )\n },\n )\n if (relatedEntities && hasAllJoinColumnsInEntity) {\n let relationIdMaps: ObjectLiteral[] = []\n entities.forEach((entity) => {\n let relationIdMap: ObjectLiteral = {}\n relation.entityMetadata.primaryColumns.forEach(\n (primaryColumn) => {\n const key =\n primaryColumn.entityMetadata.name +\n \"_\" +\n primaryColumn.propertyPath.replace(\".\", \"_\")\n relationIdMap[key] =\n primaryColumn.getEntityValue(entity)\n },\n )\n\n relatedEntities.forEach((relatedEntity) => {\n relation.joinColumns.forEach((joinColumn) => {\n const entityColumnValue =\n joinColumn.getEntityValue(entity)\n const relatedEntityColumnValue =\n joinColumn.referencedColumn!.getEntityValue(\n relatedEntity,\n )\n if (\n entityColumnValue === undefined ||\n relatedEntityColumnValue === undefined\n )\n return\n\n if (entityColumnValue === relatedEntityColumnValue) {\n const key =\n joinColumn.referencedColumn!.entityMetadata\n .name +\n \"_\" +\n relation.propertyPath.replace(\".\", \"_\") +\n \"_\" +\n joinColumn.referencedColumn!.propertyPath.replace(\n \".\",\n \"_\",\n )\n relationIdMap[key] = relatedEntityColumnValue\n }\n })\n })\n if (\n Object.keys(relationIdMap).length ===\n relation.entityMetadata.primaryColumns.length +\n relation.joinColumns.length\n ) {\n relationIdMaps.push(relationIdMap)\n }\n })\n // console.log(\"relationIdMap\", relationIdMaps);\n // console.log(\"entities.length\", entities.length);\n if (relationIdMaps.length === entities.length)\n return Promise.resolve(relationIdMaps)\n }\n\n // select all columns we need\n const qb = this.connection.createQueryBuilder()\n relation.entityMetadata.primaryColumns.forEach((primaryColumn) => {\n const columnName = DriverUtils.buildAlias(\n this.connection.driver,\n undefined,\n primaryColumn.entityMetadata.name +\n \"_\" +\n primaryColumn.propertyPath.replace(\".\", \"_\"),\n )\n qb.addSelect(\n mainAlias + \".\" + primaryColumn.propertyPath,\n columnName,\n )\n })\n relation.joinColumns.forEach((column) => {\n const columnName = DriverUtils.buildAlias(\n this.connection.driver,\n undefined,\n column.referencedColumn!.entityMetadata.name +\n \"_\" +\n relation.propertyPath.replace(\".\", \"_\") +\n \"_\" +\n column.referencedColumn!.propertyPath.replace(\".\", \"_\"),\n )\n qb.addSelect(mainAlias + \".\" + column.propertyPath, columnName)\n })\n\n // add condition for entities\n let condition: string = \"\"\n if (relation.entityMetadata.primaryColumns.length === 1) {\n const values = entities.map((entity) =>\n relation.entityMetadata.primaryColumns[0].getEntityValue(\n entity,\n ),\n )\n const areAllNumbers = values.every(\n (value) => typeof value === \"number\",\n )\n\n if (areAllNumbers) {\n condition = `${mainAlias}.${\n relation.entityMetadata.primaryColumns[0].propertyPath\n } IN (${values.join(\", \")})`\n } else {\n qb.setParameter(\"values\", values)\n condition =\n mainAlias +\n \".\" +\n relation.entityMetadata.primaryColumns[0].propertyPath +\n \" IN (:...values)\" // todo: use ANY for postgres\n }\n } else {\n condition = entities\n .map((entity, entityIndex) => {\n return relation.entityMetadata.primaryColumns\n .map((column, columnIndex) => {\n const paramName =\n \"entity\" + entityIndex + \"_\" + columnIndex\n qb.setParameter(\n paramName,\n column.getEntityValue(entity),\n )\n return (\n mainAlias +\n \".\" +\n column.propertyPath +\n \" = :\" +\n paramName\n )\n })\n .join(\" AND \")\n })\n .map((condition) => \"(\" + condition + \")\")\n .join(\" OR \")\n }\n\n // execute query\n return qb\n .from(relation.entityMetadata.target, mainAlias)\n .where(condition)\n .getRawMany()\n }\n\n /**\n * Loads relation ids for the one-to-many and one-to-one not owner relations.\n */\n protected loadForOneToManyAndOneToOneNotOwner(\n relation: RelationMetadata,\n entities: ObjectLiteral[],\n relatedEntities?: ObjectLiteral[],\n ) {\n relation = relation.inverseRelation!\n\n if (\n relation.entityMetadata.primaryColumns.length ===\n relation.joinColumns.length\n ) {\n const sameReferencedColumns =\n relation.entityMetadata.primaryColumns.every((column) => {\n return relation.joinColumns.indexOf(column) !== -1\n })\n if (sameReferencedColumns) {\n return Promise.resolve(\n entities.map((entity) => {\n const result: ObjectLiteral = {}\n relation.joinColumns.forEach(function (joinColumn) {\n const value =\n joinColumn.referencedColumn!.getEntityValue(\n entity,\n )\n const joinColumnName =\n joinColumn.referencedColumn!.entityMetadata\n .name +\n \"_\" +\n joinColumn.referencedColumn!.propertyPath.replace(\n \".\",\n \"_\",\n )\n const primaryColumnName =\n joinColumn.entityMetadata.name +\n \"_\" +\n relation.inverseRelation!.propertyPath.replace(\n \".\",\n \"_\",\n ) +\n \"_\" +\n joinColumn.propertyPath.replace(\".\", \"_\")\n result[joinColumnName] = value\n result[primaryColumnName] = value\n })\n return result\n }),\n )\n }\n }\n\n const mainAlias = relation.entityMetadata.targetName\n\n // select all columns we need\n const qb = this.connection.createQueryBuilder()\n relation.entityMetadata.primaryColumns.forEach((primaryColumn) => {\n const columnName = DriverUtils.buildAlias(\n this.connection.driver,\n undefined,\n primaryColumn.entityMetadata.name +\n \"_\" +\n relation.inverseRelation!.propertyPath.replace(\".\", \"_\") +\n \"_\" +\n primaryColumn.propertyPath.replace(\".\", \"_\"),\n )\n qb.addSelect(\n mainAlias + \".\" + primaryColumn.propertyPath,\n columnName,\n )\n })\n relation.joinColumns.forEach((column) => {\n const columnName = DriverUtils.buildAlias(\n this.connection.driver,\n undefined,\n column.referencedColumn!.entityMetadata.name +\n \"_\" +\n column.referencedColumn!.propertyPath.replace(\".\", \"_\"),\n )\n qb.addSelect(mainAlias + \".\" + column.propertyPath, columnName)\n })\n\n // add condition for entities\n let condition: string = \"\"\n if (relation.joinColumns.length === 1) {\n const values = entities.map((entity) =>\n relation.joinColumns[0].referencedColumn!.getEntityValue(\n entity,\n ),\n )\n const areAllNumbers = values.every(\n (value) => typeof value === \"number\",\n )\n\n if (areAllNumbers) {\n condition = `${mainAlias}.${\n relation.joinColumns[0].propertyPath\n } IN (${values.join(\", \")})`\n } else {\n qb.setParameter(\"values\", values)\n condition =\n mainAlias +\n \".\" +\n relation.joinColumns[0].propertyPath +\n \" IN (:...values)\" // todo: use ANY for postgres\n }\n } else {\n condition = entities\n .map((entity, entityIndex) => {\n return relation.joinColumns\n .map((joinColumn, joinColumnIndex) => {\n const paramName =\n \"entity\" + entityIndex + \"_\" + joinColumnIndex\n qb.setParameter(\n paramName,\n joinColumn.referencedColumn!.getEntityValue(\n entity,\n ),\n )\n return (\n mainAlias +\n \".\" +\n joinColumn.propertyPath +\n \" = :\" +\n paramName\n )\n })\n .join(\" AND \")\n })\n .map((condition) => \"(\" + condition + \")\")\n .join(\" OR \")\n }\n\n // execute query\n return qb\n .from(relation.entityMetadata.target, mainAlias)\n .where(condition)\n .getRawMany()\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../browser/src/query-builder/RelationIdLoader.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAGnD;;GAEG;AACH,MAAM,OAAO,gBAAgB;IACzB,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YACY,UAAsB,EACpB,WAAqC;QADvC,eAAU,GAAV,UAAU,CAAY;QACpB,gBAAW,GAAX,WAAW,CAA0B;IAChD,CAAC;IAEJ,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;OAEG;IACH,IAAI,CACA,QAA0B,EAC1B,gBAAiD,EACjD,8BAAgE;QAEhE,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,gBAAgB,CAAC;YAC5C,CAAC,CAAC,gBAAgB;YAClB,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAA;QACxB,MAAM,eAAe,GAAG,KAAK,CAAC,OAAO,CAAC,8BAA8B,CAAC;YACjE,CAAC,CAAC,8BAA8B;YAChC,CAAC,CAAC,8BAA8B;gBAChC,CAAC,CAAC,CAAC,8BAA8B,CAAC;gBAClC,CAAC,CAAC,SAAS,CAAA;QAEf,4CAA4C;QAC5C,IAAI,QAAQ,CAAC,YAAY,EAAE;YACvB,OAAO,IAAI,CAAC,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAA;SACrE;aAAM,IAAI,QAAQ,CAAC,WAAW,IAAI,QAAQ,CAAC,eAAe,EAAE;YACzD,OAAO,IAAI,CAAC,gCAAgC,CACxC,QAAQ,EACR,QAAQ,EACR,eAAe,CAClB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,GAAG,GAAG,CAAC;iBACzC,IAAI,CAAC,MAAM,CAAC,CAAA;SACpB;QAED,gBAAgB;QAChB,OAAO,EAAE;aACJ,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,MAAM,EAAE,SAAS,CAAC;aAC/C,KAAK,CAAC,SAAS,CAAC;aAChB,UAAU,EAAE,CAAA;IACrB,CAAC;CACJ","file":"RelationIdLoader.js","sourcesContent":["import { RelationMetadata } from \"../metadata/RelationMetadata\"\nimport { ColumnMetadata } from \"../metadata/ColumnMetadata\"\nimport { DataSource } from \"../data-source/DataSource\"\nimport { ObjectLiteral } from \"../common/ObjectLiteral\"\nimport { SelectQueryBuilder } from \"./SelectQueryBuilder\"\nimport { DriverUtils } from \"../driver/DriverUtils\"\nimport { QueryRunner } from \"../query-runner/QueryRunner\"\n\n/**\n * Loads relation ids for the given entities.\n */\nexport class RelationIdLoader {\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(\n private connection: DataSource,\n protected queryRunner?: QueryRunner | undefined,\n ) {}\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Loads relation ids of the given entity or entities.\n */\n load(\n relation: RelationMetadata,\n entityOrEntities: ObjectLiteral | ObjectLiteral[],\n relatedEntityOrRelatedEntities?: ObjectLiteral | ObjectLiteral[],\n ): Promise<any[]> {\n const entities = Array.isArray(entityOrEntities)\n ? entityOrEntities\n : [entityOrEntities]\n const relatedEntities = Array.isArray(relatedEntityOrRelatedEntities)\n ? relatedEntityOrRelatedEntities\n : relatedEntityOrRelatedEntities\n ? [relatedEntityOrRelatedEntities]\n : undefined\n\n // load relation ids depend of relation type\n if (relation.isManyToMany) {\n return this.loadForManyToMany(relation, entities, relatedEntities)\n } else if (relation.isManyToOne || relation.isOneToOneOwner) {\n return this.loadForManyToOneAndOneToOneOwner(\n relation,\n entities,\n relatedEntities,\n )\n } else {\n // if (relation.isOneToMany || relation.isOneToOneNotOwner) {\n return this.loadForOneToManyAndOneToOneNotOwner(\n relation,\n entities,\n relatedEntities,\n )\n }\n }\n\n /**\n * Loads relation ids of the given entities and groups them into the object with parent and children.\n *\n * todo: extract this method?\n */\n async loadManyToManyRelationIdsAndGroup<\n E1 extends ObjectLiteral,\n E2 extends ObjectLiteral,\n >(\n relation: RelationMetadata,\n entitiesOrEntities: E1 | E1[],\n relatedEntityOrEntities?: E2 | E2[],\n queryBuilder?: SelectQueryBuilder<any>,\n ): Promise<{ entity: E1; related?: E2 | E2[] }[]> {\n // console.log(\"relation:\", relation.propertyName);\n // console.log(\"entitiesOrEntities\", entitiesOrEntities);\n const isMany = relation.isManyToMany || relation.isOneToMany\n const entities: E1[] = Array.isArray(entitiesOrEntities)\n ? entitiesOrEntities\n : [entitiesOrEntities]\n\n if (!relatedEntityOrEntities) {\n relatedEntityOrEntities = await this.connection.relationLoader.load(\n relation,\n entitiesOrEntities,\n this.queryRunner,\n queryBuilder,\n )\n if (!relatedEntityOrEntities.length)\n return entities.map((entity) => ({\n entity: entity,\n related: isMany ? [] : undefined,\n }))\n }\n // const relationIds = await this.load(relation, relatedEntityOrEntities!, entitiesOrEntities);\n const relationIds = await this.load(\n relation,\n entitiesOrEntities,\n relatedEntityOrEntities,\n )\n // console.log(\"entities\", entities);\n // console.log(\"relatedEntityOrEntities\", relatedEntityOrEntities);\n // console.log(\"relationIds\", relationIds);\n\n const relatedEntities: E2[] = Array.isArray(relatedEntityOrEntities)\n ? relatedEntityOrEntities\n : [relatedEntityOrEntities!]\n\n let columns: ColumnMetadata[] = [],\n inverseColumns: ColumnMetadata[] = []\n if (relation.isManyToManyOwner) {\n columns = relation.junctionEntityMetadata!.inverseColumns.map(\n (column) => column.referencedColumn!,\n )\n inverseColumns = relation.junctionEntityMetadata!.ownerColumns.map(\n (column) => column.referencedColumn!,\n )\n } else if (relation.isManyToManyNotOwner) {\n columns = relation.junctionEntityMetadata!.ownerColumns.map(\n (column) => column.referencedColumn!,\n )\n inverseColumns =\n relation.junctionEntityMetadata!.inverseColumns.map(\n (column) => column.referencedColumn!,\n )\n } else if (relation.isManyToOne || relation.isOneToOneOwner) {\n columns = relation.joinColumns.map(\n (column) => column.referencedColumn!,\n )\n inverseColumns = relation.entityMetadata.primaryColumns\n } else if (relation.isOneToMany || relation.isOneToOneNotOwner) {\n columns = relation.inverseRelation!.entityMetadata.primaryColumns\n inverseColumns = relation.inverseRelation!.joinColumns.map(\n (column) => column.referencedColumn!,\n )\n } else {\n }\n\n return entities.map((entity) => {\n const group: { entity: E1; related?: E2 | E2[] } = {\n entity: entity,\n related: isMany ? [] : undefined,\n }\n\n const entityRelationIds = relationIds.filter((relationId) => {\n return inverseColumns.every((column) => {\n return column.compareEntityValue(\n entity,\n relationId[\n column.entityMetadata.name +\n \"_\" +\n column.propertyAliasName\n ],\n )\n })\n })\n if (!entityRelationIds.length) return group\n\n relatedEntities.forEach((relatedEntity) => {\n entityRelationIds.forEach((relationId) => {\n const relatedEntityMatched = columns.every((column) => {\n return column.compareEntityValue(\n relatedEntity,\n relationId[\n DriverUtils.buildAlias(\n this.connection.driver,\n undefined,\n column.entityMetadata.name +\n \"_\" +\n relation.propertyPath.replace(\n \".\",\n \"_\",\n ) +\n \"_\" +\n column.propertyPath.replace(\".\", \"_\"),\n )\n ],\n )\n })\n if (relatedEntityMatched) {\n if (isMany) {\n ;(group.related as E2[]).push(relatedEntity)\n } else {\n group.related = relatedEntity\n }\n }\n })\n })\n return group\n })\n }\n\n /**\n * Loads relation ids of the given entities and maps them into the given entity property.\n async loadManyToManyRelationIdsAndMap(\n relation: RelationMetadata,\n entityOrEntities: ObjectLiteral|ObjectLiteral[],\n mapToEntityOrEntities: ObjectLiteral|ObjectLiteral[],\n propertyName: string\n ): Promise<void> {\n const relationIds = await this.loadManyToManyRelationIds(relation, entityOrEntities, mapToEntityOrEntities);\n const mapToEntities = mapToEntityOrEntities instanceof Array ? mapToEntityOrEntities : [mapToEntityOrEntities];\n const junctionMetadata = relation.junctionEntityMetadata!;\n const mainAlias = junctionMetadata.name;\n const columns = relation.isOwning ? junctionMetadata.inverseColumns : junctionMetadata.ownerColumns;\n const inverseColumns = relation.isOwning ? junctionMetadata.ownerColumns : junctionMetadata.inverseColumns;\n mapToEntities.forEach(mapToEntity => {\n mapToEntity[propertyName] = [];\n relationIds.forEach(relationId => {\n const match = inverseColumns.every(column => {\n return column.referencedColumn!.getEntityValue(mapToEntity) === relationId[mainAlias + \"_\" + column.propertyName];\n });\n if (match) {\n if (columns.length === 1) {\n mapToEntity[propertyName].push(relationId[mainAlias + \"_\" + columns[0].propertyName]);\n } else {\n const value = {};\n columns.forEach(column => {\n column.referencedColumn!.setEntityValue(value, relationId[mainAlias + \"_\" + column.propertyName]);\n });\n mapToEntity[propertyName].push(value);\n }\n }\n });\n });\n }*/\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Loads relation ids for the many-to-many relation.\n */\n protected loadForManyToMany(\n relation: RelationMetadata,\n entities: ObjectLiteral[],\n relatedEntities?: ObjectLiteral[],\n ) {\n const junctionMetadata = relation.junctionEntityMetadata!\n const mainAlias = junctionMetadata.name\n const columns = relation.isOwning\n ? junctionMetadata.ownerColumns\n : junctionMetadata.inverseColumns\n const inverseColumns = relation.isOwning\n ? junctionMetadata.inverseColumns\n : junctionMetadata.ownerColumns\n const qb = this.connection.createQueryBuilder(this.queryRunner)\n\n // select all columns from junction table\n columns.forEach((column) => {\n const columnName = DriverUtils.buildAlias(\n this.connection.driver,\n undefined,\n column.referencedColumn!.entityMetadata.name +\n \"_\" +\n column.referencedColumn!.propertyPath.replace(\".\", \"_\"),\n )\n qb.addSelect(mainAlias + \".\" + column.propertyPath, columnName)\n })\n inverseColumns.forEach((column) => {\n const columnName = DriverUtils.buildAlias(\n this.connection.driver,\n undefined,\n column.referencedColumn!.entityMetadata.name +\n \"_\" +\n relation.propertyPath.replace(\".\", \"_\") +\n \"_\" +\n column.referencedColumn!.propertyPath.replace(\".\", \"_\"),\n )\n qb.addSelect(mainAlias + \".\" + column.propertyPath, columnName)\n })\n\n // add conditions for the given entities\n let condition1 = \"\"\n if (columns.length === 1) {\n const values = entities.map((entity) =>\n columns[0].referencedColumn!.getEntityValue(entity),\n )\n const areAllNumbers = values.every(\n (value) => typeof value === \"number\",\n )\n\n if (areAllNumbers) {\n condition1 = `${mainAlias}.${\n columns[0].propertyPath\n } IN (${values.join(\", \")})`\n } else {\n qb.setParameter(\"values1\", values)\n condition1 =\n mainAlias +\n \".\" +\n columns[0].propertyPath +\n \" IN (:...values1)\" // todo: use ANY for postgres\n }\n } else {\n condition1 =\n \"(\" +\n entities\n .map((entity, entityIndex) => {\n return columns\n .map((column) => {\n const paramName =\n \"entity1_\" +\n entityIndex +\n \"_\" +\n column.propertyName\n qb.setParameter(\n paramName,\n column.referencedColumn!.getEntityValue(\n entity,\n ),\n )\n return (\n mainAlias +\n \".\" +\n column.propertyPath +\n \" = :\" +\n paramName\n )\n })\n .join(\" AND \")\n })\n .map((condition) => \"(\" + condition + \")\")\n .join(\" OR \") +\n \")\"\n }\n\n // add conditions for the given inverse entities\n let condition2 = \"\"\n if (relatedEntities) {\n if (inverseColumns.length === 1) {\n const values = relatedEntities.map((entity) =>\n inverseColumns[0].referencedColumn!.getEntityValue(entity),\n )\n const areAllNumbers = values.every(\n (value) => typeof value === \"number\",\n )\n\n if (areAllNumbers) {\n condition2 = `${mainAlias}.${\n inverseColumns[0].propertyPath\n } IN (${values.join(\", \")})`\n } else {\n qb.setParameter(\"values2\", values)\n condition2 =\n mainAlias +\n \".\" +\n inverseColumns[0].propertyPath +\n \" IN (:...values2)\" // todo: use ANY for postgres\n }\n } else {\n condition2 =\n \"(\" +\n relatedEntities\n .map((entity, entityIndex) => {\n return inverseColumns\n .map((column) => {\n const paramName =\n \"entity2_\" +\n entityIndex +\n \"_\" +\n column.propertyName\n qb.setParameter(\n paramName,\n column.referencedColumn!.getEntityValue(\n entity,\n ),\n )\n return (\n mainAlias +\n \".\" +\n column.propertyPath +\n \" = :\" +\n paramName\n )\n })\n .join(\" AND \")\n })\n .map((condition) => \"(\" + condition + \")\")\n .join(\" OR \") +\n \")\"\n }\n }\n\n // qb.from(junctionMetadata.target, mainAlias)\n // .where(condition1 + (condition2 ? \" AND \" + condition2 : \"\"));\n //\n // // execute query\n // const { values1, values2 } = qb.getParameters();\n // console.log(`I can do it`, { values1, values2 });\n // if (inverseColumns.length === 1 &&\n // columns.length === 1 &&\n // this.connection.driver instanceof SqliteDriver &&\n // (values1.length + values2.length) > 500 &&\n // values1.length === values2.length) {\n // console.log(`I can do it`);\n // return qb.getRawMany();\n //\n // } else {\n // return qb.getRawMany();\n // }\n\n // execute query\n const condition = [condition1, condition2]\n .filter((v) => v.length > 0)\n .join(\" AND \")\n return qb\n .from(junctionMetadata.target, mainAlias)\n .where(condition)\n .getRawMany()\n }\n\n /**\n * Loads relation ids for the many-to-one and one-to-one owner relations.\n */\n protected loadForManyToOneAndOneToOneOwner(\n relation: RelationMetadata,\n entities: ObjectLiteral[],\n relatedEntities?: ObjectLiteral[],\n ) {\n const mainAlias = relation.entityMetadata.targetName\n\n // console.log(\"entitiesx\", entities);\n // console.log(\"relatedEntitiesx\", relatedEntities);\n const hasAllJoinColumnsInEntity = relation.joinColumns.every(\n (joinColumn) => {\n return !!relation.entityMetadata.nonVirtualColumns.find(\n (column) => column === joinColumn,\n )\n },\n )\n if (relatedEntities && hasAllJoinColumnsInEntity) {\n let relationIdMaps: ObjectLiteral[] = []\n entities.forEach((entity) => {\n let relationIdMap: ObjectLiteral = {}\n relation.entityMetadata.primaryColumns.forEach(\n (primaryColumn) => {\n const key =\n primaryColumn.entityMetadata.name +\n \"_\" +\n primaryColumn.propertyPath.replace(\".\", \"_\")\n relationIdMap[key] =\n primaryColumn.getEntityValue(entity)\n },\n )\n\n relatedEntities.forEach((relatedEntity) => {\n relation.joinColumns.forEach((joinColumn) => {\n const entityColumnValue =\n joinColumn.getEntityValue(entity)\n const relatedEntityColumnValue =\n joinColumn.referencedColumn!.getEntityValue(\n relatedEntity,\n )\n if (\n entityColumnValue === undefined ||\n relatedEntityColumnValue === undefined\n )\n return\n\n if (entityColumnValue === relatedEntityColumnValue) {\n const key =\n joinColumn.referencedColumn!.entityMetadata\n .name +\n \"_\" +\n relation.propertyPath.replace(\".\", \"_\") +\n \"_\" +\n joinColumn.referencedColumn!.propertyPath.replace(\n \".\",\n \"_\",\n )\n relationIdMap[key] = relatedEntityColumnValue\n }\n })\n })\n if (\n Object.keys(relationIdMap).length ===\n relation.entityMetadata.primaryColumns.length +\n relation.joinColumns.length\n ) {\n relationIdMaps.push(relationIdMap)\n }\n })\n // console.log(\"relationIdMap\", relationIdMaps);\n // console.log(\"entities.length\", entities.length);\n if (relationIdMaps.length === entities.length)\n return Promise.resolve(relationIdMaps)\n }\n\n // select all columns we need\n const qb = this.connection.createQueryBuilder(this.queryRunner)\n relation.entityMetadata.primaryColumns.forEach((primaryColumn) => {\n const columnName = DriverUtils.buildAlias(\n this.connection.driver,\n undefined,\n primaryColumn.entityMetadata.name +\n \"_\" +\n primaryColumn.propertyPath.replace(\".\", \"_\"),\n )\n qb.addSelect(\n mainAlias + \".\" + primaryColumn.propertyPath,\n columnName,\n )\n })\n relation.joinColumns.forEach((column) => {\n const columnName = DriverUtils.buildAlias(\n this.connection.driver,\n undefined,\n column.referencedColumn!.entityMetadata.name +\n \"_\" +\n relation.propertyPath.replace(\".\", \"_\") +\n \"_\" +\n column.referencedColumn!.propertyPath.replace(\".\", \"_\"),\n )\n qb.addSelect(mainAlias + \".\" + column.propertyPath, columnName)\n })\n\n // add condition for entities\n let condition: string = \"\"\n if (relation.entityMetadata.primaryColumns.length === 1) {\n const values = entities.map((entity) =>\n relation.entityMetadata.primaryColumns[0].getEntityValue(\n entity,\n ),\n )\n const areAllNumbers = values.every(\n (value) => typeof value === \"number\",\n )\n\n if (areAllNumbers) {\n condition = `${mainAlias}.${\n relation.entityMetadata.primaryColumns[0].propertyPath\n } IN (${values.join(\", \")})`\n } else {\n qb.setParameter(\"values\", values)\n condition =\n mainAlias +\n \".\" +\n relation.entityMetadata.primaryColumns[0].propertyPath +\n \" IN (:...values)\" // todo: use ANY for postgres\n }\n } else {\n condition = entities\n .map((entity, entityIndex) => {\n return relation.entityMetadata.primaryColumns\n .map((column, columnIndex) => {\n const paramName =\n \"entity\" + entityIndex + \"_\" + columnIndex\n qb.setParameter(\n paramName,\n column.getEntityValue(entity),\n )\n return (\n mainAlias +\n \".\" +\n column.propertyPath +\n \" = :\" +\n paramName\n )\n })\n .join(\" AND \")\n })\n .map((condition) => \"(\" + condition + \")\")\n .join(\" OR \")\n }\n\n // execute query\n return qb\n .from(relation.entityMetadata.target, mainAlias)\n .where(condition)\n .getRawMany()\n }\n\n /**\n * Loads relation ids for the one-to-many and one-to-one not owner relations.\n */\n protected loadForOneToManyAndOneToOneNotOwner(\n relation: RelationMetadata,\n entities: ObjectLiteral[],\n relatedEntities?: ObjectLiteral[],\n ) {\n relation = relation.inverseRelation!\n\n if (\n relation.entityMetadata.primaryColumns.length ===\n relation.joinColumns.length\n ) {\n const sameReferencedColumns =\n relation.entityMetadata.primaryColumns.every((column) => {\n return relation.joinColumns.indexOf(column) !== -1\n })\n if (sameReferencedColumns) {\n return Promise.resolve(\n entities.map((entity) => {\n const result: ObjectLiteral = {}\n relation.joinColumns.forEach(function (joinColumn) {\n const value =\n joinColumn.referencedColumn!.getEntityValue(\n entity,\n )\n const joinColumnName =\n joinColumn.referencedColumn!.entityMetadata\n .name +\n \"_\" +\n joinColumn.referencedColumn!.propertyPath.replace(\n \".\",\n \"_\",\n )\n const primaryColumnName =\n joinColumn.entityMetadata.name +\n \"_\" +\n relation.inverseRelation!.propertyPath.replace(\n \".\",\n \"_\",\n ) +\n \"_\" +\n joinColumn.propertyPath.replace(\".\", \"_\")\n result[joinColumnName] = value\n result[primaryColumnName] = value\n })\n return result\n }),\n )\n }\n }\n\n const mainAlias = relation.entityMetadata.targetName\n\n // select all columns we need\n const qb = this.connection.createQueryBuilder(this.queryRunner)\n relation.entityMetadata.primaryColumns.forEach((primaryColumn) => {\n const columnName = DriverUtils.buildAlias(\n this.connection.driver,\n undefined,\n primaryColumn.entityMetadata.name +\n \"_\" +\n relation.inverseRelation!.propertyPath.replace(\".\", \"_\") +\n \"_\" +\n primaryColumn.propertyPath.replace(\".\", \"_\"),\n )\n qb.addSelect(\n mainAlias + \".\" + primaryColumn.propertyPath,\n columnName,\n )\n })\n relation.joinColumns.forEach((column) => {\n const columnName = DriverUtils.buildAlias(\n this.connection.driver,\n undefined,\n column.referencedColumn!.entityMetadata.name +\n \"_\" +\n column.referencedColumn!.propertyPath.replace(\".\", \"_\"),\n )\n qb.addSelect(mainAlias + \".\" + column.propertyPath, columnName)\n })\n\n // add condition for entities\n let condition: string = \"\"\n if (relation.joinColumns.length === 1) {\n const values = entities.map((entity) =>\n relation.joinColumns[0].referencedColumn!.getEntityValue(\n entity,\n ),\n )\n const areAllNumbers = values.every(\n (value) => typeof value === \"number\",\n )\n\n if (areAllNumbers) {\n condition = `${mainAlias}.${\n relation.joinColumns[0].propertyPath\n } IN (${values.join(\", \")})`\n } else {\n qb.setParameter(\"values\", values)\n condition =\n mainAlias +\n \".\" +\n relation.joinColumns[0].propertyPath +\n \" IN (:...values)\" // todo: use ANY for postgres\n }\n } else {\n condition = entities\n .map((entity, entityIndex) => {\n return relation.joinColumns\n .map((joinColumn, joinColumnIndex) => {\n const paramName =\n \"entity\" + entityIndex + \"_\" + joinColumnIndex\n qb.setParameter(\n paramName,\n joinColumn.referencedColumn!.getEntityValue(\n entity,\n ),\n )\n return (\n mainAlias +\n \".\" +\n joinColumn.propertyPath +\n \" = :\" +\n paramName\n )\n })\n .join(\" AND \")\n })\n .map((condition) => \"(\" + condition + \")\")\n .join(\" OR \")\n }\n\n // execute query\n return qb\n .from(relation.entityMetadata.target, mainAlias)\n .where(condition)\n .getRawMany()\n }\n}\n"],"sourceRoot":".."}
@@ -7,6 +7,7 @@ import { JoinAttribute } from "./JoinAttribute";
7
7
  import { RelationIdAttribute } from "./relation-id/RelationIdAttribute";
8
8
  import { RelationCountAttribute } from "./relation-count/RelationCountAttribute";
9
9
  import { RelationIdLoader } from "./relation-id/RelationIdLoader";
10
+ import { RelationIdLoader as QueryStrategyRelationIdLoader } from "./RelationIdLoader";
10
11
  import { RelationIdMetadataToAttributeTransformer } from "./relation-id/RelationIdMetadataToAttributeTransformer";
11
12
  import { RelationCountLoader } from "./relation-count/RelationCountLoader";
12
13
  import { RelationCountMetadataToAttributeTransformer } from "./relation-count/RelationCountMetadataToAttributeTransformer";
@@ -2042,6 +2043,7 @@ export class SelectQueryBuilder extends QueryBuilder {
2042
2043
  }
2043
2044
  }
2044
2045
  if (this.expressionMap.relationLoadStrategy === "query") {
2046
+ const queryStrategyRelationIdLoader = new QueryStrategyRelationIdLoader(this.connection, queryRunner);
2045
2047
  await Promise.all(this.relationMetadatas.map(async (relation) => {
2046
2048
  const relationTarget = relation.inverseEntityMetadata.target;
2047
2049
  const relationAlias = relation.inverseEntityMetadata.targetName;
@@ -2068,7 +2070,7 @@ export class SelectQueryBuilder extends QueryBuilder {
2068
2070
  relationLoadStrategy: this.findOptions.relationLoadStrategy,
2069
2071
  });
2070
2072
  if (entities.length > 0) {
2071
- const relatedEntityGroups = await this.connection.relationIdLoader.loadManyToManyRelationIdsAndGroup(relation, entities, undefined, queryBuilder);
2073
+ const relatedEntityGroups = await queryStrategyRelationIdLoader.loadManyToManyRelationIdsAndGroup(relation, entities, undefined, queryBuilder);
2072
2074
  entities.forEach((entity) => {
2073
2075
  const relatedEntityGroup = relatedEntityGroups.find((group) => group.entity === entity);
2074
2076
  if (relatedEntityGroup) {