typeorm 0.2.39-dev.ef33cf4 → 0.2.40-dev.ae858ad

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 (84) hide show
  1. package/README.md +0 -3
  2. package/browser/driver/cockroachdb/CockroachDriver.js +23 -14
  3. package/browser/driver/cockroachdb/CockroachDriver.js.map +1 -1
  4. package/browser/driver/cockroachdb/CockroachQueryRunner.js +63 -69
  5. package/browser/driver/cockroachdb/CockroachQueryRunner.js.map +1 -1
  6. package/browser/driver/cordova/CordovaDriver.d.ts +1 -1
  7. package/browser/driver/cordova/CordovaDriver.js +25 -18
  8. package/browser/driver/cordova/CordovaDriver.js.map +1 -1
  9. package/browser/driver/cordova/CordovaQueryRunner.js +50 -43
  10. package/browser/driver/cordova/CordovaQueryRunner.js.map +1 -1
  11. package/browser/driver/postgres/PostgresDriver.d.ts +2 -2
  12. package/browser/driver/postgres/PostgresDriver.js +31 -40
  13. package/browser/driver/postgres/PostgresDriver.js.map +1 -1
  14. package/browser/driver/postgres/PostgresQueryRunner.js +7 -15
  15. package/browser/driver/postgres/PostgresQueryRunner.js.map +1 -1
  16. package/browser/driver/sap/SapQueryRunner.js +10 -28
  17. package/browser/driver/sap/SapQueryRunner.js.map +1 -1
  18. package/browser/driver/sqljs/SqljsDriver.js +5 -22
  19. package/browser/driver/sqljs/SqljsDriver.js.map +1 -1
  20. package/browser/driver/sqljs/SqljsQueryRunner.js +9 -10
  21. package/browser/driver/sqljs/SqljsQueryRunner.js.map +1 -1
  22. package/browser/find-options/FindOptionsUtils.d.ts +2 -0
  23. package/browser/find-options/FindOptionsUtils.js +19 -1
  24. package/browser/find-options/FindOptionsUtils.js.map +1 -1
  25. package/browser/migration/MigrationExecutor.d.ts +1 -1
  26. package/browser/migration/MigrationExecutor.js +2 -14
  27. package/browser/migration/MigrationExecutor.js.map +1 -1
  28. package/browser/persistence/SubjectExecutor.js +3 -3
  29. package/browser/persistence/SubjectExecutor.js.map +1 -1
  30. package/browser/persistence/subject-builder/OneToManySubjectBuilder.js +10 -4
  31. package/browser/persistence/subject-builder/OneToManySubjectBuilder.js.map +1 -1
  32. package/browser/query-builder/QueryExpressionMap.d.ts +6 -0
  33. package/browser/query-builder/QueryExpressionMap.js.map +1 -1
  34. package/browser/query-builder/SelectQueryBuilder.d.ts +7 -1
  35. package/browser/query-builder/SelectQueryBuilder.js +37 -5
  36. package/browser/query-builder/SelectQueryBuilder.js.map +1 -1
  37. package/browser/query-runner/BaseQueryRunner.js +3 -2
  38. package/browser/query-runner/BaseQueryRunner.js.map +1 -1
  39. package/browser/repository/TreeRepository.d.ts +3 -3
  40. package/browser/repository/TreeRepository.js +28 -39
  41. package/browser/repository/TreeRepository.js.map +1 -1
  42. package/commands/InitCommand.js +2 -1
  43. package/commands/InitCommand.js.map +1 -1
  44. package/driver/cockroachdb/CockroachDriver.js +23 -14
  45. package/driver/cockroachdb/CockroachDriver.js.map +1 -1
  46. package/driver/cockroachdb/CockroachQueryRunner.js +63 -69
  47. package/driver/cockroachdb/CockroachQueryRunner.js.map +1 -1
  48. package/driver/cordova/CordovaDriver.d.ts +1 -1
  49. package/driver/cordova/CordovaDriver.js +25 -18
  50. package/driver/cordova/CordovaDriver.js.map +1 -1
  51. package/driver/cordova/CordovaQueryRunner.js +50 -43
  52. package/driver/cordova/CordovaQueryRunner.js.map +1 -1
  53. package/driver/postgres/PostgresDriver.d.ts +2 -2
  54. package/driver/postgres/PostgresDriver.js +31 -40
  55. package/driver/postgres/PostgresDriver.js.map +1 -1
  56. package/driver/postgres/PostgresQueryRunner.js +7 -15
  57. package/driver/postgres/PostgresQueryRunner.js.map +1 -1
  58. package/driver/sap/SapQueryRunner.js +10 -28
  59. package/driver/sap/SapQueryRunner.js.map +1 -1
  60. package/driver/sqljs/SqljsDriver.js +5 -22
  61. package/driver/sqljs/SqljsDriver.js.map +1 -1
  62. package/driver/sqljs/SqljsQueryRunner.js +9 -10
  63. package/driver/sqljs/SqljsQueryRunner.js.map +1 -1
  64. package/find-options/FindOptionsUtils.d.ts +2 -0
  65. package/find-options/FindOptionsUtils.js +19 -1
  66. package/find-options/FindOptionsUtils.js.map +1 -1
  67. package/migration/MigrationExecutor.d.ts +1 -1
  68. package/migration/MigrationExecutor.js +2 -14
  69. package/migration/MigrationExecutor.js.map +1 -1
  70. package/package.json +1 -1
  71. package/persistence/SubjectExecutor.js +3 -3
  72. package/persistence/SubjectExecutor.js.map +1 -1
  73. package/persistence/subject-builder/OneToManySubjectBuilder.js +10 -4
  74. package/persistence/subject-builder/OneToManySubjectBuilder.js.map +1 -1
  75. package/query-builder/QueryExpressionMap.d.ts +6 -0
  76. package/query-builder/QueryExpressionMap.js.map +1 -1
  77. package/query-builder/SelectQueryBuilder.d.ts +7 -1
  78. package/query-builder/SelectQueryBuilder.js +37 -5
  79. package/query-builder/SelectQueryBuilder.js.map +1 -1
  80. package/query-runner/BaseQueryRunner.js +3 -2
  81. package/query-runner/BaseQueryRunner.js.map +1 -1
  82. package/repository/TreeRepository.d.ts +3 -3
  83. package/repository/TreeRepository.js +27 -38
  84. package/repository/TreeRepository.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/persistence/subject-builder/OneToManySubjectBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,YAAY,CAAC;AACnC,OAAO,EAAC,QAAQ,EAAC,MAAM,qBAAqB,CAAC;AAE7C,OAAO,EAAC,cAAc,EAAC,MAAM,+BAA+B,CAAC;AAG7D;;;;;;;;;;GAUG;AACH;IAEI,wEAAwE;IACxE,cAAc;IACd,wEAAwE;IAExE,iCAAsB,QAAmB;QAAnB,aAAQ,GAAR,QAAQ,CAAW;IACzC,CAAC;IAED,wEAAwE;IACxE,iBAAiB;IACjB,wEAAwE;IAExE;;OAEG;IACH,uCAAK,GAAL;QAAA,iBAWC;QAVG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAA,OAAO;YACzB,OAAO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AQ,CAAC,eAAgB;oBACnC,KAAK,EAAE,OAAO;iBACjB,CAAC,CAAC;aACN;YAED,+EAA+E;YAC/E,0FAA0F;YAC1F,2FAA2F;YAC3F,qFAAqF;YACrF,kEAAkE;YAClE,iCAAiC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAC1D,CAAC,CAAC,CAAC;QAEH,6HAA6H;QAC7H,cAAc;aACT,UAAU,CAAC,gCAAgC,EAAE,iCAAiC,CAAC;aAC/E,OAAO,CAAC,UAAA,8BAA8B;YAEnC,+FAA+F;YAC/F,iHAAiH;YACjH,0FAA0F;YAC1F,IAAM,2BAA2B,GAAG,IAAI,OAAO,CAAC;gBAC5C,QAAQ,EAAE,QAAQ,CAAC,qBAAqB;gBACxC,aAAa,EAAE,OAAO;gBACtB,UAAU,EAAE,8BAA8B;aAC7C,CAAC,CAAC;YAEH,IAAI,CAAC,QAAQ,CAAC,eAAe,IAAI,QAAQ,CAAC,eAAe,CAAC,iBAAiB,KAAK,SAAS,EAAE;gBACvF,2BAA2B,CAAC,YAAY,GAAG,IAAI,CAAC;gBAChD,2BAA2B,CAAC,UAAU,GAAG,CAAC;wBACtC,QAAQ,EAAE,QAAQ,CAAC,eAAgB;wBACnC,KAAK,EAAE,IAAI;qBACd,CAAC,CAAC;aACN;iBAAM,IAAI,QAAQ,CAAC,eAAe,CAAC,iBAAiB,KAAK,QAAQ,EAAE;gBAChE,2BAA2B,CAAC,aAAa,GAAG,IAAI,CAAC;aACpD;YAED,KAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;IACX,CAAC;IAEL,8BAAC;AAAD,CAvKA,AAuKC,IAAA","file":"OneToManySubjectBuilder.js","sourcesContent":["import {Subject} from \"../Subject\";\nimport {OrmUtils} from \"../../util/OrmUtils\";\nimport {ObjectLiteral} from \"../../common/ObjectLiteral\";\nimport {EntityMetadata} from \"../../metadata/EntityMetadata\";\nimport {RelationMetadata} from \"../../metadata/RelationMetadata\";\n\n/**\n * Builds operations needs to be executed for one-to-many relations of the given subjects.\n *\n * by example: post contains one-to-many relation with category in the property called \"categories\", e.g.\n * @OneToMany(type => Category, category => category.post) categories: Category[]\n * If user adds categories into the post and saves post we need to bind them.\n * This operation requires updation of category table since its owner of the relation and contains a join column.\n *\n * note: this class shares lot of things with OneToOneInverseSideOperationBuilder, so when you change this class\n * make sure to reflect changes there as well.\n */\nexport class OneToManySubjectBuilder {\n\n // ---------------------------------------------------------------------\n // Constructor\n // ---------------------------------------------------------------------\n\n constructor(protected subjects: Subject[]) {\n }\n\n // ---------------------------------------------------------------------\n // Public Methods\n // ---------------------------------------------------------------------\n\n /**\n * Builds all required operations.\n */\n build(): void {\n this.subjects.forEach(subject => {\n subject.metadata.oneToManyRelations.forEach(relation => {\n\n // skip relations for which persistence is disabled\n if (relation.persistenceEnabled === false)\n return;\n\n this.buildForSubjectRelation(subject, relation);\n });\n });\n }\n\n // ---------------------------------------------------------------------\n // Protected Methods\n // ---------------------------------------------------------------------\n\n /**\n * Builds operations for a given subject and relation.\n *\n * by example: subject is \"post\" entity we are saving here and relation is \"categories\" inside it here.\n */\n protected buildForSubjectRelation(subject: Subject, relation: RelationMetadata) {\n\n // prepare objects (relation id maps) for the database entity\n // note: subject.databaseEntity contains relations with loaded relation ids only\n // by example: since subject is a post, we are expecting to get all post's categories saved in the database here,\n // particularly their relation ids, e.g. category ids stored in the database\n let relatedEntityDatabaseRelationIds: ObjectLiteral[] = [];\n if (subject.databaseEntity) { // related entities in the database can exist only if this entity (post) is saved\n relatedEntityDatabaseRelationIds = relation.getEntityValue(subject.databaseEntity);\n }\n\n // get related entities of persisted entity\n // by example: get categories from the passed to persist post entity\n let relatedEntities: ObjectLiteral[] = relation.getEntityValue(subject.entity!);\n if (relatedEntities === null) // we treat relations set to null as removed, so we don't skip it\n relatedEntities = [] as ObjectLiteral[];\n if (relatedEntities === undefined) // if relation is undefined then nothing to update\n return;\n\n // extract only relation ids from the related entities, since we only need them for comparision\n // by example: extract from categories only relation ids (category id, or let's say category title, depend on join column options)\n const relatedPersistedEntityRelationIds: ObjectLiteral[] = [];\n relatedEntities.forEach(relatedEntity => { // by example: relatedEntity is a category here\n let relationIdMap = relation.inverseEntityMetadata!.getEntityIdMap(relatedEntity); // by example: relationIdMap is category.id map here, e.g. { id: ... }\n\n // try to find a subject of this related entity, maybe it was loaded or was marked for persistence\n let relatedEntitySubject = this.subjects.find(subject => {\n return subject.entity === relatedEntity;\n });\n\n // if subject with entity was found take subject identifier as relation id map since it may contain extra properties resolved\n if (relatedEntitySubject)\n relationIdMap = relatedEntitySubject.identifier;\n\n // if relationIdMap is undefined then it means user binds object which is not saved in the database yet\n // by example: if post contains categories which does not have ids yet (because they are new)\n // it means they are always newly inserted and relation update operation always must be created for them\n // it does not make sense to perform difference operation for them for both add and remove actions\n if (!relationIdMap) {\n\n // we decided to remove this error because it brings complications when saving object with non-saved entities\n // if (!relatedEntitySubject)\n // throw new TypeORMError(`One-to-many relation \"${relation.entityMetadata.name}.${relation.propertyPath}\" contains ` +\n // `entities which do not exist in the database yet, thus they cannot be bind in the database. ` +\n // `Please setup cascade insertion or save entities before binding it.`);\n if (!relatedEntitySubject)\n return;\n\n // okay, so related subject exist and its marked for insertion, then add a new change map\n // by example: this will tell category to insert into its post relation our post we are working with\n // relatedEntitySubject is newly inserted CategorySubject\n // relation.inverseRelation is ManyToOne relation inside Category\n // subject is Post needs to be inserted into Category\n relatedEntitySubject.changeMaps.push({\n relation: relation.inverseRelation!,\n value: subject\n });\n\n return;\n }\n\n // check if this binding really exist in the database\n // by example: find our category if its already bind in the database\n const relationIdInDatabaseSubjectRelation = relatedEntityDatabaseRelationIds.find(relatedDatabaseEntityRelationId => {\n return OrmUtils.compareIds(relationIdMap, relatedDatabaseEntityRelationId);\n });\n\n // if relationIdMap DOES NOT exist in the subject's relation in the database it means its a new relation and we need to \"bind\" them\n // by example: this will tell category to insert into its post relation our post we are working with\n // relatedEntitySubject is newly inserted CategorySubject\n // relation.inverseRelation is ManyToOne relation inside Category\n // subject is Post needs to be inserted into Category\n if (!relationIdInDatabaseSubjectRelation) {\n\n // if there is no relatedEntitySubject then it means \"category\" wasn't persisted,\n // but since we are going to update \"category\" table (since its an owning side of relation with join column)\n // we create a new subject here:\n if (!relatedEntitySubject) {\n relatedEntitySubject = new Subject({\n metadata: relation.inverseEntityMetadata,\n parentSubject: subject,\n canBeUpdated: true,\n identifier: relationIdMap\n });\n this.subjects.push(relatedEntitySubject);\n }\n\n relatedEntitySubject.changeMaps.push({\n relation: relation.inverseRelation!,\n value: subject\n });\n }\n\n // if related entity has relation id then we add it to the list of relation ids\n // this list will be used later to compare with database relation ids to find a difference\n // what exist in this array and does not exist in the database are newly inserted relations\n // what does not exist in this array, but exist in the database are removed relations\n // removed relations are set to null from inverse side of relation\n relatedPersistedEntityRelationIds.push(relationIdMap);\n });\n\n // find what related entities were added and what were removed based on difference between what we save and what database has\n EntityMetadata\n .difference(relatedEntityDatabaseRelationIds, relatedPersistedEntityRelationIds)\n .forEach(removedRelatedEntityRelationId => { // by example: removedRelatedEntityRelationId is category that was bind in the database before, but now its unbind\n\n // todo: probably we can improve this in the future by finding entity with column those values,\n // todo: maybe it was already in persistence process. This is possible due to unique requirements of join columns\n // we create a new subject which operations will be executed in subject operation executor\n const removedRelatedEntitySubject = new Subject({\n metadata: relation.inverseEntityMetadata,\n parentSubject: subject,\n identifier: removedRelatedEntityRelationId,\n });\n\n if (!relation.inverseRelation || relation.inverseRelation.orphanedRowAction === \"nullify\") {\n removedRelatedEntitySubject.canBeUpdated = true;\n removedRelatedEntitySubject.changeMaps = [{\n relation: relation.inverseRelation!,\n value: null\n }];\n } else if (relation.inverseRelation.orphanedRowAction === \"delete\") {\n removedRelatedEntitySubject.mustBeRemoved = true;\n }\n\n this.subjects.push(removedRelatedEntitySubject);\n });\n }\n\n}\n"],"sourceRoot":"../.."}
1
+ {"version":3,"sources":["../browser/src/persistence/subject-builder/OneToManySubjectB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AAC;YAEH,IAAI,CAAC,QAAQ,CAAC,eAAe,IAAI,QAAQ,CAAC,eAAe,CAAC,iBAAiB,KAAK,SAAS,EAAE;gBACvF,2BAA2B,CAAC,YAAY,GAAG,IAAI,CAAC;gBAChD,2BAA2B,CAAC,UAAU,GAAG,CAAC;wBACtC,QAAQ,EAAE,QAAQ,CAAC,eAAgB;wBACnC,KAAK,EAAE,IAAI;qBACd,CAAC,CAAC;aACN;iBAAM,IAAI,QAAQ,CAAC,eAAe,CAAC,iBAAiB,KAAK,QAAQ,EAAE;gBAChE,2BAA2B,CAAC,aAAa,GAAG,IAAI,CAAC;aACpD;YAED,KAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;IACX,CAAC;IAEL,8BAAC;AAAD,CA9KA,AA8KC,IAAA","file":"OneToManySubjectBuilder.js","sourcesContent":["import {Subject} from \"../Subject\";\nimport {OrmUtils} from \"../../util/OrmUtils\";\nimport {ObjectLiteral} from \"../../common/ObjectLiteral\";\nimport {EntityMetadata} from \"../../metadata/EntityMetadata\";\nimport {RelationMetadata} from \"../../metadata/RelationMetadata\";\n\n/**\n * Builds operations needs to be executed for one-to-many relations of the given subjects.\n *\n * by example: post contains one-to-many relation with category in the property called \"categories\", e.g.\n * @OneToMany(type => Category, category => category.post) categories: Category[]\n * If user adds categories into the post and saves post we need to bind them.\n * This operation requires updation of category table since its owner of the relation and contains a join column.\n *\n * note: this class shares lot of things with OneToOneInverseSideOperationBuilder, so when you change this class\n * make sure to reflect changes there as well.\n */\nexport class OneToManySubjectBuilder {\n\n // ---------------------------------------------------------------------\n // Constructor\n // ---------------------------------------------------------------------\n\n constructor(protected subjects: Subject[]) {\n }\n\n // ---------------------------------------------------------------------\n // Public Methods\n // ---------------------------------------------------------------------\n\n /**\n * Builds all required operations.\n */\n build(): void {\n this.subjects.forEach(subject => {\n subject.metadata.oneToManyRelations.forEach(relation => {\n\n // skip relations for which persistence is disabled\n if (relation.persistenceEnabled === false)\n return;\n\n this.buildForSubjectRelation(subject, relation);\n });\n });\n }\n\n // ---------------------------------------------------------------------\n // Protected Methods\n // ---------------------------------------------------------------------\n\n /**\n * Builds operations for a given subject and relation.\n *\n * by example: subject is \"post\" entity we are saving here and relation is \"categories\" inside it here.\n */\n protected buildForSubjectRelation(subject: Subject, relation: RelationMetadata) {\n // prepare objects (relation id maps) for the database entity\n // by example: since subject is a post, we are expecting to get all post's categories saved in the database here,\n // particularly their relation ids, e.g. category ids stored in the database\n\n\t\t// in most cases relatedEntityDatabaseValues will contain only the entity key properties.\n\t\t// this is because subject.databaseEntity contains relations with loaded relation ids only.\n\t\t// however if the entity uses the afterLoad hook to calculate any properties, the fetched \"key object\" might include ADDITIONAL properties.\n\t\t// to handle such situations, we pass the data to relation.inverseEntityMetadata.getEntityIdMap to extract the key without any other properties.\n\n let relatedEntityDatabaseRelationIds: ObjectLiteral[] = [];\n if (subject.databaseEntity) { // related entities in the database can exist only if this entity (post) is saved\n const relatedEntityDatabaseRelation: ObjectLiteral[] | undefined = relation.getEntityValue(subject.databaseEntity)\n if (relatedEntityDatabaseRelation) {\n relatedEntityDatabaseRelationIds = relatedEntityDatabaseRelation.map((entity) => relation.inverseEntityMetadata.getEntityIdMap(entity)!);\n }\n }\n\n // get related entities of persisted entity\n // by example: get categories from the passed to persist post entity\n let relatedEntities: ObjectLiteral[] = relation.getEntityValue(subject.entity!);\n if (relatedEntities === null) // we treat relations set to null as removed, so we don't skip it\n relatedEntities = [] as ObjectLiteral[];\n if (relatedEntities === undefined) // if relation is undefined then nothing to update\n return;\n\n // extract only relation ids from the related entities, since we only need them for comparison\n // by example: extract from categories only relation ids (category id, or let's say category title, depend on join column options)\n const relatedPersistedEntityRelationIds: ObjectLiteral[] = [];\n relatedEntities.forEach(relatedEntity => { // by example: relatedEntity is a category here\n let relationIdMap = relation.inverseEntityMetadata!.getEntityIdMap(relatedEntity); // by example: relationIdMap is category.id map here, e.g. { id: ... }\n\n // try to find a subject of this related entity, maybe it was loaded or was marked for persistence\n let relatedEntitySubject = this.subjects.find(subject => {\n return subject.entity === relatedEntity;\n });\n\n // if subject with entity was found take subject identifier as relation id map since it may contain extra properties resolved\n if (relatedEntitySubject)\n relationIdMap = relatedEntitySubject.identifier;\n\n // if relationIdMap is undefined then it means user binds object which is not saved in the database yet\n // by example: if post contains categories which does not have ids yet (because they are new)\n // it means they are always newly inserted and relation update operation always must be created for them\n // it does not make sense to perform difference operation for them for both add and remove actions\n if (!relationIdMap) {\n\n // we decided to remove this error because it brings complications when saving object with non-saved entities\n // if (!relatedEntitySubject)\n // throw new TypeORMError(`One-to-many relation \"${relation.entityMetadata.name}.${relation.propertyPath}\" contains ` +\n // `entities which do not exist in the database yet, thus they cannot be bind in the database. ` +\n // `Please setup cascade insertion or save entities before binding it.`);\n if (!relatedEntitySubject)\n return;\n\n // okay, so related subject exist and its marked for insertion, then add a new change map\n // by example: this will tell category to insert into its post relation our post we are working with\n // relatedEntitySubject is newly inserted CategorySubject\n // relation.inverseRelation is ManyToOne relation inside Category\n // subject is Post needs to be inserted into Category\n relatedEntitySubject.changeMaps.push({\n relation: relation.inverseRelation!,\n value: subject\n });\n\n return;\n }\n\n // check if this binding really exist in the database\n // by example: find our category if its already bind in the database\n const relationIdInDatabaseSubjectRelation = relatedEntityDatabaseRelationIds.find(relatedDatabaseEntityRelationId => {\n return OrmUtils.compareIds(relationIdMap, relatedDatabaseEntityRelationId);\n });\n\n // if relationIdMap DOES NOT exist in the subject's relation in the database it means its a new relation and we need to \"bind\" them\n // by example: this will tell category to insert into its post relation our post we are working with\n // relatedEntitySubject is newly inserted CategorySubject\n // relation.inverseRelation is ManyToOne relation inside Category\n // subject is Post needs to be inserted into Category\n if (!relationIdInDatabaseSubjectRelation) {\n\n // if there is no relatedEntitySubject then it means \"category\" wasn't persisted,\n // but since we are going to update \"category\" table (since its an owning side of relation with join column)\n // we create a new subject here:\n if (!relatedEntitySubject) {\n relatedEntitySubject = new Subject({\n metadata: relation.inverseEntityMetadata,\n parentSubject: subject,\n canBeUpdated: true,\n identifier: relationIdMap\n });\n this.subjects.push(relatedEntitySubject);\n }\n\n relatedEntitySubject.changeMaps.push({\n relation: relation.inverseRelation!,\n value: subject\n });\n }\n\n // if related entity has relation id then we add it to the list of relation ids\n // this list will be used later to compare with database relation ids to find a difference\n // what exist in this array and does not exist in the database are newly inserted relations\n // what does not exist in this array, but exist in the database are removed relations\n // removed relations are set to null from inverse side of relation\n relatedPersistedEntityRelationIds.push(relationIdMap);\n });\n\n // find what related entities were added and what were removed based on difference between what we save and what database has\n EntityMetadata\n .difference(relatedEntityDatabaseRelationIds, relatedPersistedEntityRelationIds)\n .forEach(removedRelatedEntityRelationId => { // by example: removedRelatedEntityRelationId is category that was bind in the database before, but now its unbind\n\n // todo: probably we can improve this in the future by finding entity with column those values,\n // todo: maybe it was already in persistence process. This is possible due to unique requirements of join columns\n // we create a new subject which operations will be executed in subject operation executor\n const removedRelatedEntitySubject = new Subject({\n metadata: relation.inverseEntityMetadata,\n parentSubject: subject,\n identifier: removedRelatedEntityRelationId,\n });\n\n if (!relation.inverseRelation || relation.inverseRelation.orphanedRowAction === \"nullify\") {\n removedRelatedEntitySubject.canBeUpdated = true;\n removedRelatedEntitySubject.changeMaps = [{\n relation: relation.inverseRelation!,\n value: null\n }];\n } else if (relation.inverseRelation.orphanedRowAction === \"delete\") {\n removedRelatedEntitySubject.mustBeRemoved = true;\n }\n\n this.subjects.push(removedRelatedEntitySubject);\n });\n }\n\n}\n"],"sourceRoot":"../.."}
@@ -127,6 +127,12 @@ export declare class QueryExpressionMap {
127
127
  * Number of rows to take using pagination.
128
128
  */
129
129
  take?: number;
130
+ /**
131
+ * Use certain index for the query.
132
+ *
133
+ * SELECT * FROM table_name USE INDEX (col1_index, col2_index) WHERE col1=1 AND col2=2 AND col3=3;
134
+ */
135
+ useIndex?: string;
130
136
  /**
131
137
  * Locking mode.
132
138
  */
@@ -1 +1 @@
1
- {"version":3,"sources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AAAD,CA1bA,AA0bC,IAAA","file":"QueryExpressionMap.js","sourcesContent":["import {Alias} from \"./Alias\";\nimport {ObjectLiteral} from \"../common/ObjectLiteral\";\nimport {OrderByCondition} from \"../find-options/OrderByCondition\";\nimport {JoinAttribute} from \"./JoinAttribute\";\nimport {RelationIdAttribute} from \"./relation-id/RelationIdAttribute\";\nimport {RelationCountAttribute} from \"./relation-count/RelationCountAttribute\";\nimport {Connection} from \"../connection/Connection\";\nimport {EntityMetadata} from \"../metadata/EntityMetadata\";\nimport {SelectQuery} from \"./SelectQuery\";\nimport {ColumnMetadata} from \"../metadata/ColumnMetadata\";\nimport {RelationMetadata} from \"../metadata/RelationMetadata\";\nimport {SelectQueryBuilderOption} from \"./SelectQueryBuilderOption\";\nimport { TypeORMError } from \"../error\";\nimport { WhereClause } from \"./WhereClause\";\n\n/**\n * Contains all properties of the QueryBuilder that needs to be build a final query.\n */\nexport class QueryExpressionMap {\n\n // -------------------------------------------------------------------------\n // Public Properties\n // -------------------------------------------------------------------------\n\n /**\n * Indicates if QueryBuilder used to select entities and not a raw results.\n */\n queryEntity: boolean = false;\n\n /**\n * Main alias is a main selection object selected by QueryBuilder.\n */\n mainAlias?: Alias;\n\n /**\n * All aliases (including main alias) used in the query.\n */\n aliases: Alias[] = [];\n\n /**\n * Represents query type. QueryBuilder is able to build SELECT, UPDATE and DELETE queries.\n */\n queryType: \"select\"|\"update\"|\"delete\"|\"insert\"|\"relation\"|\"soft-delete\"|\"restore\" = \"select\";\n\n /**\n * Data needs to be SELECT-ed.\n */\n selects: SelectQuery[] = [];\n\n /**\n * Max execution time in millisecond.\n */\n maxExecutionTime: number = 0;\n\n /**\n * Whether SELECT is DISTINCT.\n */\n selectDistinct: boolean = false;\n\n /**\n * SELECT DISTINCT ON query (postgres).\n */\n selectDistinctOn: string[] = [];\n\n /**\n * FROM-s to be selected.\n */\n // froms: { target: string, alias: string }[] = [];\n\n /**\n * If update query was used, it needs \"update set\" - properties which will be updated by this query.\n * If insert query was used, it needs \"insert set\" - values that needs to be inserted.\n */\n valuesSet?: ObjectLiteral|ObjectLiteral[];\n\n /**\n * Optional returning (or output) clause for insert, update or delete queries.\n */\n returning: string|string[];\n\n /**\n * Extra returning columns to be added to the returning statement if driver supports it.\n */\n extraReturningColumns: ColumnMetadata[] = [];\n\n /**\n * Optional on conflict statement used in insertion query in postgres.\n */\n onConflict: string = \"\";\n\n /**\n * Optional on ignore statement used in insertion query in databases.\n */\n onIgnore: boolean = false;\n\n /**\n * Optional on update statement used in insertion query in databases.\n */\n onUpdate: {\n conflict?: string | string[],\n columns?: string[],\n overwrite?: string[],\n };\n\n /**\n * JOIN queries.\n */\n joinAttributes: JoinAttribute[] = [];\n\n /**\n * RelationId queries.\n */\n relationIdAttributes: RelationIdAttribute[] = [];\n\n /**\n * Relation count queries.\n */\n relationCountAttributes: RelationCountAttribute[] = [];\n\n /**\n * WHERE queries.\n */\n wheres: WhereClause[] = [];\n\n /**\n * HAVING queries.\n */\n havings: { type: \"simple\"|\"and\"|\"or\", condition: string }[] = [];\n\n /**\n * ORDER BY queries.\n */\n orderBys: OrderByCondition = {};\n\n /**\n * GROUP BY queries.\n */\n groupBys: string[] = [];\n\n /**\n * LIMIT query.\n */\n limit?: number;\n\n /**\n * OFFSET query.\n */\n offset?: number;\n\n /**\n * Number of rows to skip of result using pagination.\n */\n skip?: number;\n\n /**\n * Number of rows to take using pagination.\n */\n take?: number;\n\n /**\n * Locking mode.\n */\n lockMode?: \"optimistic\"|\"pessimistic_read\"|\"pessimistic_write\"|\"dirty_read\"|\"pessimistic_partial_write\"|\"pessimistic_write_or_fail\"|\"for_no_key_update\";\n\n /**\n * Current version of the entity, used for locking.\n */\n lockVersion?: number|Date;\n\n /**\n * Tables to be specified in the \"FOR UPDATE OF\" clause, referred by their alias\n */\n lockTables?: string[];\n\n /**\n * Indicates if soft-deleted rows should be included in entity result.\n * By default the soft-deleted rows are not included.\n */\n withDeleted: boolean = false;\n\n /**\n * Parameters used to be escaped in final query.\n */\n parameters: ObjectLiteral = {};\n\n /**\n * Indicates if alias, table names and column names will be ecaped by driver, or not.\n *\n * todo: rename to isQuotingDisabled, also think if it should be named \"escaping\"\n */\n disableEscaping: boolean = true;\n\n /**\n * Indicates if virtual columns should be included in entity result.\n *\n * todo: what to do with it? is it properly used? what about persistence?\n */\n enableRelationIdValues: boolean = false;\n\n /**\n * Extra where condition appended to the end of original where conditions with AND keyword.\n * Original condition will be wrapped into brackets.\n */\n extraAppendedAndWhereCondition: string = \"\";\n\n /**\n * Indicates if query builder creates a subquery.\n */\n subQuery: boolean = false;\n\n /**\n * Indicates if property names are prefixed with alias names during property replacement.\n * By default this is enabled, however we need this because aliases are not supported in UPDATE and DELETE queries,\n * but user can use them in WHERE expressions.\n */\n aliasNamePrefixingEnabled: boolean = true;\n\n /**\n * Indicates if query result cache is enabled or not.\n */\n cache: boolean = false;\n\n /**\n * Time in milliseconds in which cache will expire.\n * If not set then global caching time will be used.\n */\n cacheDuration: number;\n\n /**\n * Cache id.\n * Used to identifier your cache queries.\n */\n cacheId: string;\n\n /**\n * Options that define QueryBuilder behaviour.\n */\n options: SelectQueryBuilderOption[] = [];\n\n /**\n * Property path of relation to work with.\n * Used in relational query builder.\n */\n relationPropertyPath: string;\n\n /**\n * Entity (target) which relations will be updated.\n */\n of: any|any[];\n\n /**\n * List of columns where data should be inserted.\n * Used in INSERT query.\n */\n insertColumns: string[] = [];\n\n /**\n * Used if user wants to update or delete a specific entities.\n */\n whereEntities: ObjectLiteral[] = [];\n\n /**\n * Indicates if entity must be updated after insertion / updation.\n * This may produce extra query or use RETURNING / OUTPUT statement (depend on database).\n */\n updateEntity: boolean = true;\n\n /**\n * Indicates if listeners and subscribers must be called before and after query execution.\n */\n callListeners: boolean = true;\n\n /**\n * Indicates if query must be wrapped into transaction.\n */\n useTransaction: boolean = false;\n\n /**\n * Extra parameters.\n *\n * @deprecated Use standard parameters instead\n */\n nativeParameters: ObjectLiteral = {};\n\n /**\n * Query Comment to include extra information for debugging or other purposes.\n */\n comment?: string;\n\n /**\n * Items from an entity that have been locally generated & are recorded here for later use.\n * Examples include the UUID generation when the database does not natively support it.\n * These are included in the entity index order.\n */\n locallyGenerated: { [key: number]: ObjectLiteral } = {};\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(protected connection: Connection) {\n }\n\n // -------------------------------------------------------------------------\n // Accessors\n // -------------------------------------------------------------------------\n\n /**\n * Get all ORDER BY queries - if order by is specified by user then it uses them,\n * otherwise it uses default entity order by if it was set.\n */\n get allOrderBys() {\n if (!Object.keys(this.orderBys).length && this.mainAlias!.hasMetadata && this.options.indexOf(\"disable-global-order\") === -1) {\n const entityOrderBy = this.mainAlias!.metadata.orderBy || {};\n return Object.keys(entityOrderBy).reduce((orderBy, key) => {\n orderBy[this.mainAlias!.name + \".\" + key] = entityOrderBy[key];\n return orderBy;\n }, {} as OrderByCondition);\n }\n\n return this.orderBys;\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates a main alias and adds it to the current expression map.\n */\n setMainAlias(alias: Alias): Alias {\n\n // if main alias is already set then remove it from the array\n // if (this.mainAlias)\n // this.aliases.splice(this.aliases.indexOf(this.mainAlias));\n\n // set new main alias\n this.mainAlias = alias;\n\n return alias;\n }\n\n /**\n * Creates a new alias and adds it to the current expression map.\n */\n createAlias(options: { type: \"from\"|\"select\"|\"join\"|\"other\", name?: string, target?: Function|string, tablePath?: string, subQuery?: string, metadata?: EntityMetadata }): Alias {\n\n let aliasName = options.name;\n if (!aliasName && options.tablePath)\n aliasName = options.tablePath;\n if (!aliasName && options.target instanceof Function)\n aliasName = options.target.name;\n if (!aliasName && typeof options.target === \"string\")\n aliasName = options.target;\n\n const alias = new Alias();\n alias.type = options.type;\n if (aliasName)\n alias.name = aliasName;\n if (options.metadata)\n alias.metadata = options.metadata;\n if (options.target && !alias.hasMetadata)\n alias.metadata = this.connection.getMetadata(options.target);\n if (options.tablePath)\n alias.tablePath = options.tablePath;\n if (options.subQuery)\n alias.subQuery = options.subQuery;\n\n this.aliases.push(alias);\n return alias;\n }\n\n /**\n * Finds alias with the given name.\n * If alias was not found it throw an exception.\n */\n findAliasByName(aliasName: string): Alias {\n const alias = this.aliases.find(alias => alias.name === aliasName);\n if (!alias)\n throw new TypeORMError(`\"${aliasName}\" alias was not found. Maybe you forgot to join it?`);\n\n return alias;\n }\n\n findColumnByAliasExpression(aliasExpression: string): ColumnMetadata|undefined {\n const [aliasName, propertyPath] = aliasExpression.split(\".\");\n const alias = this.findAliasByName(aliasName);\n return alias.metadata.findColumnWithPropertyName(propertyPath);\n }\n\n /**\n * Gets relation metadata of the relation this query builder works with.\n *\n * todo: add proper exceptions\n */\n get relationMetadata(): RelationMetadata {\n if (!this.mainAlias)\n throw new TypeORMError(`Entity to work with is not specified!`); // todo: better message\n\n const relationMetadata = this.mainAlias.metadata.findRelationWithPropertyPath(this.relationPropertyPath);\n if (!relationMetadata)\n throw new TypeORMError(`Relation ${this.relationPropertyPath} was not found in entity ${this.mainAlias.name}`); // todo: better message\n\n return relationMetadata;\n }\n\n /**\n * Copies all properties of the current QueryExpressionMap into a new one.\n * Useful when QueryBuilder needs to create a copy of itself.\n */\n clone(): QueryExpressionMap {\n const map = new QueryExpressionMap(this.connection);\n map.queryType = this.queryType;\n map.selects = this.selects.map(select => select);\n map.maxExecutionTime = this.maxExecutionTime;\n map.selectDistinct = this.selectDistinct;\n map.selectDistinctOn = this.selectDistinctOn;\n this.aliases.forEach(alias => map.aliases.push(new Alias(alias)));\n map.mainAlias = this.mainAlias;\n map.valuesSet = this.valuesSet;\n map.returning = this.returning;\n map.onConflict = this.onConflict;\n map.onIgnore = this.onIgnore;\n map.onUpdate = this.onUpdate;\n map.joinAttributes = this.joinAttributes.map(join => new JoinAttribute(this.connection, this, join));\n map.relationIdAttributes = this.relationIdAttributes.map(relationId => new RelationIdAttribute(this, relationId));\n map.relationCountAttributes = this.relationCountAttributes.map(relationCount => new RelationCountAttribute(this, relationCount));\n map.wheres = this.wheres.map(where => ({ ...where }));\n map.havings = this.havings.map(having => ({ ...having }));\n map.orderBys = Object.assign({}, this.orderBys);\n map.groupBys = this.groupBys.map(groupBy => groupBy);\n map.limit = this.limit;\n map.offset = this.offset;\n map.skip = this.skip;\n map.take = this.take;\n map.lockMode = this.lockMode;\n map.lockVersion = this.lockVersion;\n map.lockTables = this.lockTables;\n map.withDeleted = this.withDeleted;\n map.parameters = Object.assign({}, this.parameters);\n map.disableEscaping = this.disableEscaping;\n map.enableRelationIdValues = this.enableRelationIdValues;\n map.extraAppendedAndWhereCondition = this.extraAppendedAndWhereCondition;\n map.subQuery = this.subQuery;\n map.aliasNamePrefixingEnabled = this.aliasNamePrefixingEnabled;\n map.cache = this.cache;\n map.cacheId = this.cacheId;\n map.cacheDuration = this.cacheDuration;\n map.relationPropertyPath = this.relationPropertyPath;\n map.of = this.of;\n map.insertColumns = this.insertColumns;\n map.whereEntities = this.whereEntities;\n map.updateEntity = this.updateEntity;\n map.callListeners = this.callListeners;\n map.useTransaction = this.useTransaction;\n map.nativeParameters = Object.assign({}, this.nativeParameters);\n map.comment = this.comment;\n return map;\n }\n\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../browser/src/query-builder/QueryExpressionMap.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAG9B,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAC,mBAAmB,EAAC,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAC,sBAAsB,EAAC,MAAM,yCAAyC,CAAC;AAO/E,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAGxC;;GAEG;AACH;IA6RI,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,4BAAsB,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;QA/R5C,4EAA4E;QAC5E,oBAAoB;QACpB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AI,CAAC,yBAAyB,CAAC;QAC/D,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACvB,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC3B,GAAG,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC;QACvC,GAAG,CAAC,oBAAoB,GAAG,IAAI,CAAC,oBAAoB,CAAC;QACrD,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;QACjB,GAAG,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC;QACvC,GAAG,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC;QACvC,GAAG,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC;QACrC,GAAG,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC;QACvC,GAAG,CAAC,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC;QACzC,GAAG,CAAC,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;QAChE,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC3B,OAAO,GAAG,CAAC;IACf,CAAC;IAEL,yBAAC;AAAD,CAjcA,AAicC,IAAA","file":"QueryExpressionMap.js","sourcesContent":["import {Alias} from \"./Alias\";\nimport {ObjectLiteral} from \"../common/ObjectLiteral\";\nimport {OrderByCondition} from \"../find-options/OrderByCondition\";\nimport {JoinAttribute} from \"./JoinAttribute\";\nimport {RelationIdAttribute} from \"./relation-id/RelationIdAttribute\";\nimport {RelationCountAttribute} from \"./relation-count/RelationCountAttribute\";\nimport {Connection} from \"../connection/Connection\";\nimport {EntityMetadata} from \"../metadata/EntityMetadata\";\nimport {SelectQuery} from \"./SelectQuery\";\nimport {ColumnMetadata} from \"../metadata/ColumnMetadata\";\nimport {RelationMetadata} from \"../metadata/RelationMetadata\";\nimport {SelectQueryBuilderOption} from \"./SelectQueryBuilderOption\";\nimport { TypeORMError } from \"../error\";\nimport { WhereClause } from \"./WhereClause\";\n\n/**\n * Contains all properties of the QueryBuilder that needs to be build a final query.\n */\nexport class QueryExpressionMap {\n\n // -------------------------------------------------------------------------\n // Public Properties\n // -------------------------------------------------------------------------\n\n /**\n * Indicates if QueryBuilder used to select entities and not a raw results.\n */\n queryEntity: boolean = false;\n\n /**\n * Main alias is a main selection object selected by QueryBuilder.\n */\n mainAlias?: Alias;\n\n /**\n * All aliases (including main alias) used in the query.\n */\n aliases: Alias[] = [];\n\n /**\n * Represents query type. QueryBuilder is able to build SELECT, UPDATE and DELETE queries.\n */\n queryType: \"select\"|\"update\"|\"delete\"|\"insert\"|\"relation\"|\"soft-delete\"|\"restore\" = \"select\";\n\n /**\n * Data needs to be SELECT-ed.\n */\n selects: SelectQuery[] = [];\n\n /**\n * Max execution time in millisecond.\n */\n maxExecutionTime: number = 0;\n\n /**\n * Whether SELECT is DISTINCT.\n */\n selectDistinct: boolean = false;\n\n /**\n * SELECT DISTINCT ON query (postgres).\n */\n selectDistinctOn: string[] = [];\n\n /**\n * FROM-s to be selected.\n */\n // froms: { target: string, alias: string }[] = [];\n\n /**\n * If update query was used, it needs \"update set\" - properties which will be updated by this query.\n * If insert query was used, it needs \"insert set\" - values that needs to be inserted.\n */\n valuesSet?: ObjectLiteral|ObjectLiteral[];\n\n /**\n * Optional returning (or output) clause for insert, update or delete queries.\n */\n returning: string|string[];\n\n /**\n * Extra returning columns to be added to the returning statement if driver supports it.\n */\n extraReturningColumns: ColumnMetadata[] = [];\n\n /**\n * Optional on conflict statement used in insertion query in postgres.\n */\n onConflict: string = \"\";\n\n /**\n * Optional on ignore statement used in insertion query in databases.\n */\n onIgnore: boolean = false;\n\n /**\n * Optional on update statement used in insertion query in databases.\n */\n onUpdate: {\n conflict?: string | string[],\n columns?: string[],\n overwrite?: string[],\n };\n\n /**\n * JOIN queries.\n */\n joinAttributes: JoinAttribute[] = [];\n\n /**\n * RelationId queries.\n */\n relationIdAttributes: RelationIdAttribute[] = [];\n\n /**\n * Relation count queries.\n */\n relationCountAttributes: RelationCountAttribute[] = [];\n\n /**\n * WHERE queries.\n */\n wheres: WhereClause[] = [];\n\n /**\n * HAVING queries.\n */\n havings: { type: \"simple\"|\"and\"|\"or\", condition: string }[] = [];\n\n /**\n * ORDER BY queries.\n */\n orderBys: OrderByCondition = {};\n\n /**\n * GROUP BY queries.\n */\n groupBys: string[] = [];\n\n /**\n * LIMIT query.\n */\n limit?: number;\n\n /**\n * OFFSET query.\n */\n offset?: number;\n\n /**\n * Number of rows to skip of result using pagination.\n */\n skip?: number;\n\n /**\n * Number of rows to take using pagination.\n */\n take?: number;\n\n /**\n * Use certain index for the query.\n *\n * SELECT * FROM table_name USE INDEX (col1_index, col2_index) WHERE col1=1 AND col2=2 AND col3=3;\n */\n useIndex?: string;\n\n /**\n * Locking mode.\n */\n lockMode?: \"optimistic\"|\"pessimistic_read\"|\"pessimistic_write\"|\"dirty_read\"|\"pessimistic_partial_write\"|\"pessimistic_write_or_fail\"|\"for_no_key_update\";\n\n /**\n * Current version of the entity, used for locking.\n */\n lockVersion?: number|Date;\n\n /**\n * Tables to be specified in the \"FOR UPDATE OF\" clause, referred by their alias\n */\n lockTables?: string[];\n\n /**\n * Indicates if soft-deleted rows should be included in entity result.\n * By default the soft-deleted rows are not included.\n */\n withDeleted: boolean = false;\n\n /**\n * Parameters used to be escaped in final query.\n */\n parameters: ObjectLiteral = {};\n\n /**\n * Indicates if alias, table names and column names will be ecaped by driver, or not.\n *\n * todo: rename to isQuotingDisabled, also think if it should be named \"escaping\"\n */\n disableEscaping: boolean = true;\n\n /**\n * Indicates if virtual columns should be included in entity result.\n *\n * todo: what to do with it? is it properly used? what about persistence?\n */\n enableRelationIdValues: boolean = false;\n\n /**\n * Extra where condition appended to the end of original where conditions with AND keyword.\n * Original condition will be wrapped into brackets.\n */\n extraAppendedAndWhereCondition: string = \"\";\n\n /**\n * Indicates if query builder creates a subquery.\n */\n subQuery: boolean = false;\n\n /**\n * Indicates if property names are prefixed with alias names during property replacement.\n * By default this is enabled, however we need this because aliases are not supported in UPDATE and DELETE queries,\n * but user can use them in WHERE expressions.\n */\n aliasNamePrefixingEnabled: boolean = true;\n\n /**\n * Indicates if query result cache is enabled or not.\n */\n cache: boolean = false;\n\n /**\n * Time in milliseconds in which cache will expire.\n * If not set then global caching time will be used.\n */\n cacheDuration: number;\n\n /**\n * Cache id.\n * Used to identifier your cache queries.\n */\n cacheId: string;\n\n /**\n * Options that define QueryBuilder behaviour.\n */\n options: SelectQueryBuilderOption[] = [];\n\n /**\n * Property path of relation to work with.\n * Used in relational query builder.\n */\n relationPropertyPath: string;\n\n /**\n * Entity (target) which relations will be updated.\n */\n of: any|any[];\n\n /**\n * List of columns where data should be inserted.\n * Used in INSERT query.\n */\n insertColumns: string[] = [];\n\n /**\n * Used if user wants to update or delete a specific entities.\n */\n whereEntities: ObjectLiteral[] = [];\n\n /**\n * Indicates if entity must be updated after insertion / updation.\n * This may produce extra query or use RETURNING / OUTPUT statement (depend on database).\n */\n updateEntity: boolean = true;\n\n /**\n * Indicates if listeners and subscribers must be called before and after query execution.\n */\n callListeners: boolean = true;\n\n /**\n * Indicates if query must be wrapped into transaction.\n */\n useTransaction: boolean = false;\n\n /**\n * Extra parameters.\n *\n * @deprecated Use standard parameters instead\n */\n nativeParameters: ObjectLiteral = {};\n\n /**\n * Query Comment to include extra information for debugging or other purposes.\n */\n comment?: string;\n\n /**\n * Items from an entity that have been locally generated & are recorded here for later use.\n * Examples include the UUID generation when the database does not natively support it.\n * These are included in the entity index order.\n */\n locallyGenerated: { [key: number]: ObjectLiteral } = {};\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(protected connection: Connection) {\n }\n\n // -------------------------------------------------------------------------\n // Accessors\n // -------------------------------------------------------------------------\n\n /**\n * Get all ORDER BY queries - if order by is specified by user then it uses them,\n * otherwise it uses default entity order by if it was set.\n */\n get allOrderBys() {\n if (!Object.keys(this.orderBys).length && this.mainAlias!.hasMetadata && this.options.indexOf(\"disable-global-order\") === -1) {\n const entityOrderBy = this.mainAlias!.metadata.orderBy || {};\n return Object.keys(entityOrderBy).reduce((orderBy, key) => {\n orderBy[this.mainAlias!.name + \".\" + key] = entityOrderBy[key];\n return orderBy;\n }, {} as OrderByCondition);\n }\n\n return this.orderBys;\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates a main alias and adds it to the current expression map.\n */\n setMainAlias(alias: Alias): Alias {\n\n // if main alias is already set then remove it from the array\n // if (this.mainAlias)\n // this.aliases.splice(this.aliases.indexOf(this.mainAlias));\n\n // set new main alias\n this.mainAlias = alias;\n\n return alias;\n }\n\n /**\n * Creates a new alias and adds it to the current expression map.\n */\n createAlias(options: { type: \"from\"|\"select\"|\"join\"|\"other\", name?: string, target?: Function|string, tablePath?: string, subQuery?: string, metadata?: EntityMetadata }): Alias {\n\n let aliasName = options.name;\n if (!aliasName && options.tablePath)\n aliasName = options.tablePath;\n if (!aliasName && options.target instanceof Function)\n aliasName = options.target.name;\n if (!aliasName && typeof options.target === \"string\")\n aliasName = options.target;\n\n const alias = new Alias();\n alias.type = options.type;\n if (aliasName)\n alias.name = aliasName;\n if (options.metadata)\n alias.metadata = options.metadata;\n if (options.target && !alias.hasMetadata)\n alias.metadata = this.connection.getMetadata(options.target);\n if (options.tablePath)\n alias.tablePath = options.tablePath;\n if (options.subQuery)\n alias.subQuery = options.subQuery;\n\n this.aliases.push(alias);\n return alias;\n }\n\n /**\n * Finds alias with the given name.\n * If alias was not found it throw an exception.\n */\n findAliasByName(aliasName: string): Alias {\n const alias = this.aliases.find(alias => alias.name === aliasName);\n if (!alias)\n throw new TypeORMError(`\"${aliasName}\" alias was not found. Maybe you forgot to join it?`);\n\n return alias;\n }\n\n findColumnByAliasExpression(aliasExpression: string): ColumnMetadata|undefined {\n const [aliasName, propertyPath] = aliasExpression.split(\".\");\n const alias = this.findAliasByName(aliasName);\n return alias.metadata.findColumnWithPropertyName(propertyPath);\n }\n\n /**\n * Gets relation metadata of the relation this query builder works with.\n *\n * todo: add proper exceptions\n */\n get relationMetadata(): RelationMetadata {\n if (!this.mainAlias)\n throw new TypeORMError(`Entity to work with is not specified!`); // todo: better message\n\n const relationMetadata = this.mainAlias.metadata.findRelationWithPropertyPath(this.relationPropertyPath);\n if (!relationMetadata)\n throw new TypeORMError(`Relation ${this.relationPropertyPath} was not found in entity ${this.mainAlias.name}`); // todo: better message\n\n return relationMetadata;\n }\n\n /**\n * Copies all properties of the current QueryExpressionMap into a new one.\n * Useful when QueryBuilder needs to create a copy of itself.\n */\n clone(): QueryExpressionMap {\n const map = new QueryExpressionMap(this.connection);\n map.queryType = this.queryType;\n map.selects = this.selects.map(select => select);\n map.maxExecutionTime = this.maxExecutionTime;\n map.selectDistinct = this.selectDistinct;\n map.selectDistinctOn = this.selectDistinctOn;\n this.aliases.forEach(alias => map.aliases.push(new Alias(alias)));\n map.mainAlias = this.mainAlias;\n map.valuesSet = this.valuesSet;\n map.returning = this.returning;\n map.onConflict = this.onConflict;\n map.onIgnore = this.onIgnore;\n map.onUpdate = this.onUpdate;\n map.joinAttributes = this.joinAttributes.map(join => new JoinAttribute(this.connection, this, join));\n map.relationIdAttributes = this.relationIdAttributes.map(relationId => new RelationIdAttribute(this, relationId));\n map.relationCountAttributes = this.relationCountAttributes.map(relationCount => new RelationCountAttribute(this, relationCount));\n map.wheres = this.wheres.map(where => ({ ...where }));\n map.havings = this.havings.map(having => ({ ...having }));\n map.orderBys = Object.assign({}, this.orderBys);\n map.groupBys = this.groupBys.map(groupBy => groupBy);\n map.limit = this.limit;\n map.offset = this.offset;\n map.skip = this.skip;\n map.take = this.take;\n map.lockMode = this.lockMode;\n map.lockVersion = this.lockVersion;\n map.lockTables = this.lockTables;\n map.withDeleted = this.withDeleted;\n map.parameters = Object.assign({}, this.parameters);\n map.disableEscaping = this.disableEscaping;\n map.enableRelationIdValues = this.enableRelationIdValues;\n map.extraAppendedAndWhereCondition = this.extraAppendedAndWhereCondition;\n map.subQuery = this.subQuery;\n map.aliasNamePrefixingEnabled = this.aliasNamePrefixingEnabled;\n map.cache = this.cache;\n map.cacheId = this.cacheId;\n map.cacheDuration = this.cacheDuration;\n map.relationPropertyPath = this.relationPropertyPath;\n map.of = this.of;\n map.insertColumns = this.insertColumns;\n map.whereEntities = this.whereEntities;\n map.updateEntity = this.updateEntity;\n map.callListeners = this.callListeners;\n map.useTransaction = this.useTransaction;\n map.nativeParameters = Object.assign({}, this.nativeParameters);\n map.comment = this.comment;\n return map;\n }\n\n}\n"],"sourceRoot":".."}
@@ -483,6 +483,12 @@ export declare class SelectQueryBuilder<Entity> extends QueryBuilder<Entity> imp
483
483
  * Sets number of entities to skip.
484
484
  */
485
485
  skip(skip?: number): this;
486
+ /**
487
+ * Set certain index to be used by the query.
488
+ *
489
+ * @param index Name of index to be used.
490
+ */
491
+ useIndex(index: string): this;
486
492
  /**
487
493
  * Sets locking mode.
488
494
  */
@@ -597,7 +603,7 @@ export declare class SelectQueryBuilder<Entity> extends QueryBuilder<Entity> imp
597
603
  entities: Entity[];
598
604
  raw: any[];
599
605
  }>;
600
- protected createOrderByCombinedWithSelectExpression(parentAlias: string): [string, OrderByCondition];
606
+ protected createOrderByCombinedWithSelectExpression(parentAlias: string): [string, OrderByCondition, string];
601
607
  /**
602
608
  * Loads raw results from the database.
603
609
  */
@@ -505,6 +505,15 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
505
505
  throw new TypeORMError("Provided \"skip\" value is not a number. Please provide a numeric value.");
506
506
  return this;
507
507
  };
508
+ /**
509
+ * Set certain index to be used by the query.
510
+ *
511
+ * @param index Name of index to be used.
512
+ */
513
+ SelectQueryBuilder.prototype.useIndex = function (index) {
514
+ this.expressionMap.useIndex = index;
515
+ return this;
516
+ };
508
517
  /**
509
518
  * Sets locking mode.
510
519
  */
@@ -1031,6 +1040,13 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
1031
1040
  break;
1032
1041
  }
1033
1042
  }
1043
+ // Use certain index
1044
+ var useIndex = "";
1045
+ if (this.expressionMap.useIndex) {
1046
+ if (this.connection.driver instanceof MysqlDriver) {
1047
+ useIndex = " USE INDEX (" + this.expressionMap.useIndex + ")";
1048
+ }
1049
+ }
1034
1050
  // create a selection query
1035
1051
  var froms = this.expressionMap.aliases
1036
1052
  .filter(function (alias) { return alias.type === "from" && (alias.tablePath || alias.subQuery); })
@@ -1041,7 +1057,7 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
1041
1057
  });
1042
1058
  var select = this.createSelectDistinctExpression();
1043
1059
  var selection = allSelects.map(function (select) { return select.selection + (select.aliasName ? " AS " + _this.escape(select.aliasName) : ""); }).join(", ");
1044
- return select + selection + " FROM " + froms.join(", ") + lock;
1060
+ return select + selection + " FROM " + froms.join(", ") + lock + useIndex;
1045
1061
  };
1046
1062
  /**
1047
1063
  * Creates select | select distinct part of SQL query.
@@ -1458,7 +1474,7 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
1458
1474
  */
1459
1475
  SelectQueryBuilder.prototype.executeEntitiesAndRawResults = function (queryRunner) {
1460
1476
  return __awaiter(this, void 0, void 0, function () {
1461
- var metadata, relationIdLoader, relationCountLoader, relationIdMetadataTransformer, relationCountMetadataTransformer, rawResults, entities, _a, selects, orderBys_1, metadata_1, mainAliasName_1, querySelects, condition, parameters_1, alias_1, ids, areAllNumbers, rawRelationIdResults, rawRelationCountResults, transformer;
1477
+ var metadata, relationIdLoader, relationCountLoader, relationIdMetadataTransformer, relationCountMetadataTransformer, rawResults, entities, _a, selects, orderBys_1, subquerySelect, metadata_1, mainAliasName_1, querySelects, condition, parameters_1, alias_1, ids, areAllNumbers, rawRelationIdResults, rawRelationCountResults, transformer;
1462
1478
  var _this = this;
1463
1479
  return __generator(this, function (_b) {
1464
1480
  switch (_b.label) {
@@ -1480,7 +1496,7 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
1480
1496
  relationCountMetadataTransformer.transform();
1481
1497
  rawResults = [], entities = [];
1482
1498
  if (!((this.expressionMap.skip || this.expressionMap.take) && this.expressionMap.joinAttributes.length > 0)) return [3 /*break*/, 4];
1483
- _a = __read(this.createOrderByCombinedWithSelectExpression("distinctAlias"), 2), selects = _a[0], orderBys_1 = _a[1];
1499
+ _a = __read(this.createOrderByCombinedWithSelectExpression("distinctAlias"), 3), selects = _a[0], orderBys_1 = _a[1], subquerySelect = _a[2];
1484
1500
  metadata_1 = this.expressionMap.mainAlias.metadata;
1485
1501
  mainAliasName_1 = this.expressionMap.mainAlias.name;
1486
1502
  querySelects = metadata_1.primaryColumns.map(function (primaryColumn) {
@@ -1494,7 +1510,7 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
1494
1510
  return [4 /*yield*/, new SelectQueryBuilder(this.connection, queryRunner)
1495
1511
  .select("DISTINCT " + querySelects.join(", "))
1496
1512
  .addSelect(selects)
1497
- .from("(" + this.clone().orderBy().getQuery() + ")", "distinctAlias")
1513
+ .from("(" + this.clone().orderBy().addSelect(subquerySelect).getQuery() + ")", "distinctAlias")
1498
1514
  .offset(this.expressionMap.skip)
1499
1515
  .limit(this.expressionMap.take)
1500
1516
  .orderBy(orderBys_1)
@@ -1604,7 +1620,23 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
1604
1620
  }
1605
1621
  }
1606
1622
  });
1607
- return [selectString, orderByObject];
1623
+ var subquerySelectString = Object.keys(orderBys)
1624
+ .filter(function (orderCriteria) { return orderCriteria.includes("."); })
1625
+ .map(function (orderCriteria) {
1626
+ var criteriaParts = orderCriteria.split(".");
1627
+ var aliasName = criteriaParts[0];
1628
+ var propertyPath = criteriaParts.slice(1).join(".");
1629
+ var alias = _this.expressionMap.findAliasByName(aliasName);
1630
+ if (alias.type !== "join") {
1631
+ return "";
1632
+ }
1633
+ var column = alias.metadata.findColumnWithPropertyPath(propertyPath);
1634
+ var property = _this.escape(alias.name) + "." + _this.escape(column.databaseName);
1635
+ var propertyAlias = _this.escape(DriverUtils.buildAlias(_this.connection.driver, aliasName, column.databaseName));
1636
+ return [property, "AS", propertyAlias].join(" ");
1637
+ })
1638
+ .join(", ");
1639
+ return [selectString, orderByObject, subquerySelectString];
1608
1640
  };
1609
1641
  /**
1610
1642
  * Loads raw results from the database.