typeorm 0.3.11-dev.6eb674b → 0.3.11-dev.81fc9a9

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 (135) hide show
  1. package/README.md +2 -2
  2. package/browser/data-source/DataSource.js +2 -2
  3. package/browser/data-source/DataSource.js.map +1 -1
  4. package/browser/driver/better-sqlite3/BetterSqlite3QueryRunner.js +0 -6
  5. package/browser/driver/better-sqlite3/BetterSqlite3QueryRunner.js.map +1 -1
  6. package/browser/driver/postgres/PostgresQueryRunner.d.ts +17 -1
  7. package/browser/driver/postgres/PostgresQueryRunner.js +97 -0
  8. package/browser/driver/postgres/PostgresQueryRunner.js.map +1 -1
  9. package/browser/driver/react-native/ReactNativeQueryRunner.js +4 -4
  10. package/browser/driver/react-native/ReactNativeQueryRunner.js.map +1 -1
  11. package/browser/driver/sqlite/SqliteConnectionOptions.d.ts +6 -0
  12. package/browser/driver/sqlite/SqliteConnectionOptions.js.map +1 -1
  13. package/browser/driver/sqlite/SqliteDriver.js +18 -6
  14. package/browser/driver/sqlite/SqliteDriver.js.map +1 -1
  15. package/browser/driver/sqlite-abstract/AbstractSqliteDriver.js +6 -0
  16. package/browser/driver/sqlite-abstract/AbstractSqliteDriver.js.map +1 -1
  17. package/browser/entity-manager/EntityManager.js +3 -1
  18. package/browser/entity-manager/EntityManager.js.map +1 -1
  19. package/browser/find-options/FindOperatorType.d.ts +1 -1
  20. package/browser/find-options/FindOperatorType.js.map +1 -1
  21. package/browser/find-options/FindOptionsOrder.d.ts +1 -1
  22. package/browser/find-options/FindOptionsOrder.js.map +1 -1
  23. package/browser/find-options/FindOptionsRelations.d.ts +1 -1
  24. package/browser/find-options/FindOptionsRelations.js.map +1 -1
  25. package/browser/find-options/FindOptionsSelect.d.ts +1 -1
  26. package/browser/find-options/FindOptionsSelect.js.map +1 -1
  27. package/browser/find-options/FindOptionsWhere.d.ts +2 -2
  28. package/browser/find-options/FindOptionsWhere.js.map +1 -1
  29. package/browser/find-options/operator/And.d.ts +2 -0
  30. package/browser/find-options/operator/And.js +6 -0
  31. package/browser/find-options/operator/And.js.map +1 -0
  32. package/browser/index.d.ts +1 -0
  33. package/browser/index.js +1 -0
  34. package/browser/index.js.map +1 -1
  35. package/browser/migration/MigrationExecutor.js +1 -1
  36. package/browser/migration/MigrationExecutor.js.map +1 -1
  37. package/browser/naming-strategy/NamingStrategyInterface.d.ts +2 -1
  38. package/browser/naming-strategy/NamingStrategyInterface.js.map +1 -1
  39. package/browser/persistence/tree/MaterializedPathSubjectExecutor.d.ts +1 -0
  40. package/browser/persistence/tree/MaterializedPathSubjectExecutor.js +19 -4
  41. package/browser/persistence/tree/MaterializedPathSubjectExecutor.js.map +1 -1
  42. package/browser/query-builder/QueryBuilder.js +9 -0
  43. package/browser/query-builder/QueryBuilder.js.map +1 -1
  44. package/browser/query-builder/RelationLoader.js +1 -0
  45. package/browser/query-builder/RelationLoader.js.map +1 -1
  46. package/browser/query-builder/SelectQueryBuilder.js +1 -5
  47. package/browser/query-builder/SelectQueryBuilder.js.map +1 -1
  48. package/browser/query-builder/WhereClause.d.ts +1 -1
  49. package/browser/query-builder/WhereClause.js.map +1 -1
  50. package/browser/query-runner/BaseQueryRunner.d.ts +1 -1
  51. package/browser/query-runner/BaseQueryRunner.js.map +1 -1
  52. package/browser/repository/Repository.d.ts +1 -1
  53. package/browser/repository/Repository.js.map +1 -1
  54. package/browser/repository/TreeRepository.d.ts +0 -4
  55. package/browser/repository/TreeRepository.js +0 -11
  56. package/browser/repository/TreeRepository.js.map +1 -1
  57. package/browser/repository/UpsertOptions.d.ts +3 -1
  58. package/browser/repository/UpsertOptions.js.map +1 -1
  59. package/browser/schema-builder/RdbmsSchemaBuilder.d.ts +4 -0
  60. package/browser/schema-builder/RdbmsSchemaBuilder.js +74 -2
  61. package/browser/schema-builder/RdbmsSchemaBuilder.js.map +1 -1
  62. package/browser/schema-builder/view/View.d.ts +13 -1
  63. package/browser/schema-builder/view/View.js +16 -0
  64. package/browser/schema-builder/view/View.js.map +1 -1
  65. package/browser/util/TreeRepositoryUtils.js +16 -6
  66. package/browser/util/TreeRepositoryUtils.js.map +1 -1
  67. package/commands/MigrationRevertCommand.js +1 -0
  68. package/commands/MigrationRevertCommand.js.map +1 -1
  69. package/data-source/DataSource.js +2 -2
  70. package/data-source/DataSource.js.map +1 -1
  71. package/driver/better-sqlite3/BetterSqlite3QueryRunner.js +0 -6
  72. package/driver/better-sqlite3/BetterSqlite3QueryRunner.js.map +1 -1
  73. package/driver/postgres/PostgresQueryRunner.d.ts +17 -1
  74. package/driver/postgres/PostgresQueryRunner.js +97 -0
  75. package/driver/postgres/PostgresQueryRunner.js.map +1 -1
  76. package/driver/react-native/ReactNativeQueryRunner.js +4 -4
  77. package/driver/react-native/ReactNativeQueryRunner.js.map +1 -1
  78. package/driver/sqlite/SqliteConnectionOptions.d.ts +6 -0
  79. package/driver/sqlite/SqliteConnectionOptions.js.map +1 -1
  80. package/driver/sqlite/SqliteDriver.js +18 -6
  81. package/driver/sqlite/SqliteDriver.js.map +1 -1
  82. package/driver/sqlite-abstract/AbstractSqliteDriver.js +6 -0
  83. package/driver/sqlite-abstract/AbstractSqliteDriver.js.map +1 -1
  84. package/entity-manager/EntityManager.js +3 -1
  85. package/entity-manager/EntityManager.js.map +1 -1
  86. package/find-options/FindOperatorType.d.ts +1 -1
  87. package/find-options/FindOperatorType.js.map +1 -1
  88. package/find-options/FindOptionsOrder.d.ts +1 -1
  89. package/find-options/FindOptionsOrder.js.map +1 -1
  90. package/find-options/FindOptionsRelations.d.ts +1 -1
  91. package/find-options/FindOptionsRelations.js.map +1 -1
  92. package/find-options/FindOptionsSelect.d.ts +1 -1
  93. package/find-options/FindOptionsSelect.js.map +1 -1
  94. package/find-options/FindOptionsWhere.d.ts +2 -2
  95. package/find-options/FindOptionsWhere.js.map +1 -1
  96. package/find-options/operator/And.d.ts +2 -0
  97. package/find-options/operator/And.js +10 -0
  98. package/find-options/operator/And.js.map +1 -0
  99. package/index.d.ts +1 -0
  100. package/index.js +1 -0
  101. package/index.js.map +1 -1
  102. package/index.mjs +2 -0
  103. package/migration/MigrationExecutor.js +1 -1
  104. package/migration/MigrationExecutor.js.map +1 -1
  105. package/naming-strategy/NamingStrategyInterface.d.ts +2 -1
  106. package/naming-strategy/NamingStrategyInterface.js.map +1 -1
  107. package/package.json +1 -1
  108. package/persistence/tree/MaterializedPathSubjectExecutor.d.ts +1 -0
  109. package/persistence/tree/MaterializedPathSubjectExecutor.js +19 -4
  110. package/persistence/tree/MaterializedPathSubjectExecutor.js.map +1 -1
  111. package/query-builder/QueryBuilder.js +9 -0
  112. package/query-builder/QueryBuilder.js.map +1 -1
  113. package/query-builder/RelationLoader.js +1 -0
  114. package/query-builder/RelationLoader.js.map +1 -1
  115. package/query-builder/SelectQueryBuilder.js +1 -5
  116. package/query-builder/SelectQueryBuilder.js.map +1 -1
  117. package/query-builder/WhereClause.d.ts +1 -1
  118. package/query-builder/WhereClause.js.map +1 -1
  119. package/query-runner/BaseQueryRunner.d.ts +1 -1
  120. package/query-runner/BaseQueryRunner.js.map +1 -1
  121. package/repository/Repository.d.ts +1 -1
  122. package/repository/Repository.js.map +1 -1
  123. package/repository/TreeRepository.d.ts +0 -4
  124. package/repository/TreeRepository.js +0 -11
  125. package/repository/TreeRepository.js.map +1 -1
  126. package/repository/UpsertOptions.d.ts +3 -1
  127. package/repository/UpsertOptions.js.map +1 -1
  128. package/schema-builder/RdbmsSchemaBuilder.d.ts +4 -0
  129. package/schema-builder/RdbmsSchemaBuilder.js +74 -2
  130. package/schema-builder/RdbmsSchemaBuilder.js.map +1 -1
  131. package/schema-builder/view/View.d.ts +13 -1
  132. package/schema-builder/view/View.js +16 -0
  133. package/schema-builder/view/View.js.map +1 -1
  134. package/util/TreeRepositoryUtils.js +16 -6
  135. package/util/TreeRepositoryUtils.js.map +1 -1
@@ -8,27 +8,34 @@ export class TreeRepositoryUtils {
8
8
  // -------------------------------------------------------------------------
9
9
  static createRelationMaps(manager, metadata, alias, rawResults) {
10
10
  return rawResults.map((rawResult) => {
11
+ var _a;
11
12
  const joinColumn = metadata.treeParentRelation.joinColumns[0];
13
+ const referencedColumn = (_a = joinColumn.referencedColumn) !== null && _a !== void 0 ? _a : metadata.primaryColumns[0];
12
14
  // fixes issue #2518, default to databaseName property when givenDatabaseName is not set
13
15
  const joinColumnName = joinColumn.givenDatabaseName || joinColumn.databaseName;
14
- const id = rawResult[alias + "_" + metadata.primaryColumns[0].databaseName];
16
+ const referencedColumnName = referencedColumn.givenDatabaseName ||
17
+ referencedColumn.databaseName;
18
+ const id = rawResult[alias + "_" + referencedColumnName];
15
19
  const parentId = rawResult[alias + "_" + joinColumnName];
16
20
  return {
17
- id: manager.connection.driver.prepareHydratedValue(id, metadata.primaryColumns[0]),
21
+ id: manager.connection.driver.prepareHydratedValue(id, referencedColumn),
18
22
  parentId: manager.connection.driver.prepareHydratedValue(parentId, joinColumn),
19
23
  };
20
24
  });
21
25
  }
22
26
  static buildChildrenEntityTree(metadata, entity, entities, relationMaps, options) {
27
+ var _a;
23
28
  const childProperty = metadata.treeChildrenRelation.propertyName;
24
29
  if (options.depth === 0) {
25
30
  entity[childProperty] = [];
26
31
  return;
27
32
  }
28
- const parentEntityId = metadata.primaryColumns[0].getEntityValue(entity);
33
+ const joinColumn = metadata.treeParentRelation.joinColumns[0];
34
+ const referencedColumn = (_a = joinColumn.referencedColumn) !== null && _a !== void 0 ? _a : metadata.primaryColumns[0];
35
+ const parentEntityId = referencedColumn.getEntityValue(entity);
29
36
  const childRelationMaps = relationMaps.filter((relationMap) => relationMap.parentId === parentEntityId);
30
37
  const childIds = new Set(childRelationMaps.map((relationMap) => relationMap.id));
31
- entity[childProperty] = entities.filter((entity) => childIds.has(metadata.primaryColumns[0].getEntityValue(entity)));
38
+ entity[childProperty] = entities.filter((entity) => childIds.has(referencedColumn.getEntityValue(entity)));
32
39
  entity[childProperty].forEach((childEntity) => {
33
40
  TreeRepositoryUtils.buildChildrenEntityTree(metadata, childEntity, entities, relationMaps, {
34
41
  ...options,
@@ -37,13 +44,16 @@ export class TreeRepositoryUtils {
37
44
  });
38
45
  }
39
46
  static buildParentEntityTree(metadata, entity, entities, relationMaps) {
47
+ var _a;
40
48
  const parentProperty = metadata.treeParentRelation.propertyName;
41
- const entityId = metadata.primaryColumns[0].getEntityValue(entity);
49
+ const joinColumn = metadata.treeParentRelation.joinColumns[0];
50
+ const referencedColumn = (_a = joinColumn.referencedColumn) !== null && _a !== void 0 ? _a : metadata.primaryColumns[0];
51
+ const entityId = referencedColumn.getEntityValue(entity);
42
52
  const parentRelationMap = relationMaps.find((relationMap) => relationMap.id === entityId);
43
53
  const parentEntity = entities.find((entity) => {
44
54
  if (!parentRelationMap)
45
55
  return false;
46
- return (metadata.primaryColumns[0].getEntityValue(entity) ===
56
+ return (referencedColumn.getEntityValue(entity) ===
47
57
  parentRelationMap.parentId);
48
58
  });
49
59
  if (parentEntity) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/util/TreeRepositoryUtils.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,OAAO,mBAAmB;IAC5B,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E,MAAM,CAAC,kBAAkB,CACrB,OAAsB,EACtB,QAAwB,EACxB,KAAa,EACb,UAAiB;QAEjB,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE;YAChC,MAAM,UAAU,GAAG,QAAQ,CAAC,kBAAmB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAA;YAC9D,wFAAwF;YACxF,MAAM,cAAc,GAChB,UAAU,CAAC,iBAAiB,IAAI,UAAU,CAAC,YAAY,CAAA;YAC3D,MAAM,EAAE,GACJ,SAAS,CAAC,KAAK,GAAG,GAAG,GAAG,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAA;YACpE,MAAM,QAAQ,GAAG,SAAS,CAAC,KAA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C,uBAAuB,CACvC,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,YAAY,EACZ;gBACI,GAAG,OAAO;gBACV,KAAK,EAAE,OAAO,CAAC,KAAK,GAAG,CAAC;aAC3B,CACJ,CAAA;QACL,CAAC,CAAC,CAAA;IACN,CAAC;IAED,MAAM,CAAC,qBAAqB,CACxB,QAAwB,EACxB,MAAW,EACX,QAAe,EACf,YAA0C;QAE1C,MAAM,cAAc,GAAG,QAAQ,CAAC,kBAAmB,CAAC,YAAY,CAAA;QAChE,MAAM,QAAQ,GAAG,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,CAAA;QAClE,MAAM,iBAAiB,GAAG,YAAY,CAAC,IAAI,CACvC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,EAAE,KAAK,QAAQ,CAC/C,CAAA;QACD,MAAM,YAAY,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;YAC1C,IAAI,CAAC,iBAAiB;gBAAE,OAAO,KAAK,CAAA;YAEpC,OAAO,CACH,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC;gBACjD,iBAAiB,CAAC,QAAQ,CAC7B,CAAA;QACL,CAAC,CAAC,CAAA;QACF,IAAI,YAAY,EAAE;YACd,MAAM,CAAC,cAAc,CAAC,GAAG,YAAY,CAAA;YACrC,mBAAmB,CAAC,qBAAqB,CACrC,QAAQ,EACR,MAAM,CAAC,cAAc,CAAC,EACtB,QAAQ,EACR,YAAY,CACf,CAAA;SACJ;IACL,CAAC;CACJ","file":"TreeRepositoryUtils.js","sourcesContent":["import { EntityManager } from \"../entity-manager/EntityManager\"\nimport { EntityMetadata } from \"../metadata/EntityMetadata\"\nimport { FindTreesOptions } from \"../repository/FindTreesOptions\"\n\n/**\n * Provides utilities for manipulating tree structures.\n *\n */\nexport class TreeRepositoryUtils {\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n static createRelationMaps(\n manager: EntityManager,\n metadata: EntityMetadata,\n alias: string,\n rawResults: any[],\n ): { id: any; parentId: any }[] {\n return rawResults.map((rawResult) => {\n const joinColumn = metadata.treeParentRelation!.joinColumns[0]\n // fixes issue #2518, default to databaseName property when givenDatabaseName is not set\n const joinColumnName =\n joinColumn.givenDatabaseName || joinColumn.databaseName\n const id =\n rawResult[alias + \"_\" + metadata.primaryColumns[0].databaseName]\n const parentId = rawResult[alias + \"_\" + joinColumnName]\n return {\n id: manager.connection.driver.prepareHydratedValue(\n id,\n metadata.primaryColumns[0],\n ),\n parentId: manager.connection.driver.prepareHydratedValue(\n parentId,\n joinColumn,\n ),\n }\n })\n }\n\n static buildChildrenEntityTree(\n metadata: EntityMetadata,\n entity: any,\n entities: any[],\n relationMaps: { id: any; parentId: any }[],\n options: FindTreesOptions & { depth: number },\n ): void {\n const childProperty = metadata.treeChildrenRelation!.propertyName\n if (options.depth === 0) {\n entity[childProperty] = []\n return\n }\n const parentEntityId = metadata.primaryColumns[0].getEntityValue(entity)\n const childRelationMaps = relationMaps.filter(\n (relationMap) => relationMap.parentId === parentEntityId,\n )\n const childIds = new Set(\n childRelationMaps.map((relationMap) => relationMap.id),\n )\n entity[childProperty] = entities.filter((entity) =>\n childIds.has(metadata.primaryColumns[0].getEntityValue(entity)),\n )\n entity[childProperty].forEach((childEntity: any) => {\n TreeRepositoryUtils.buildChildrenEntityTree(\n metadata,\n childEntity,\n entities,\n relationMaps,\n {\n ...options,\n depth: options.depth - 1,\n },\n )\n })\n }\n\n static buildParentEntityTree(\n metadata: EntityMetadata,\n entity: any,\n entities: any[],\n relationMaps: { id: any; parentId: any }[],\n ): void {\n const parentProperty = metadata.treeParentRelation!.propertyName\n const entityId = metadata.primaryColumns[0].getEntityValue(entity)\n const parentRelationMap = relationMaps.find(\n (relationMap) => relationMap.id === entityId,\n )\n const parentEntity = entities.find((entity) => {\n if (!parentRelationMap) return false\n\n return (\n metadata.primaryColumns[0].getEntityValue(entity) ===\n parentRelationMap.parentId\n )\n })\n if (parentEntity) {\n entity[parentProperty] = parentEntity\n TreeRepositoryUtils.buildParentEntityTree(\n metadata,\n entity[parentProperty],\n entities,\n relationMaps,\n )\n }\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../browser/src/util/TreeRepositoryUtils.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,OAAO,mBAAmB;IAC5B,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E,MAAM,CAAC,kBAAkB,CACrB,OAAsB,EACtB,QAAwB,EACxB,KAAa,EACb,UAAiB;QAEjB,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE;;YAChC,MAAM,UAAU,GAAG,QAAQ,CAAC,kBAAmB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAA;YAC9D,MAAM,gBAAgB,GAClB,MAAA,UAAU,CAAC,gBAAgB,mCAAI,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,CAAA;YAC7D,wFAAwF;YACxF,MAAM,cAAc,GAChB,UAAU,CAAC,iBAAiB,IAAI,UAAU,CAAC,YAAY,CAAA;YAC3D,MAAM,oBAAoB,GACtB,gBAAgB,CAAC,iBAAiB;gBAClC,gBAAgB,CAAC,YAAY,CAAA;YACjC,MAAM,EAAE,GAAG,SAAS,CAAC,KAAK,GAAG,GAAG,GAAG,oBAAoB,CAAC,CAAA;YACxD,MAAM,QAAQ,GAAG,SAAS,CAAC,KAAK,GAAG,GAAG,GAAG,cAAc,CAAC,CAAA;YACxD,OAAO;gBACH,EAAE,EAAE,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,oBAAoB,CAC9C,EAAE,EACF,gBAAgB,CACnB;gBACD,QAAQ,EAAE,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,oBAAoB,CACpD,QAAQ,EACR,UAAU,CACb;aACJ,CAAA;QACL,CAAC,CAAC,CAAA;IAC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ACN,CAAC;IAED,MAAM,CAAC,qBAAqB,CACxB,QAAwB,EACxB,MAAW,EACX,QAAe,EACf,YAA0C;;QAE1C,MAAM,cAAc,GAAG,QAAQ,CAAC,kBAAmB,CAAC,YAAY,CAAA;QAChE,MAAM,UAAU,GAAG,QAAQ,CAAC,kBAAmB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAA;QAC9D,MAAM,gBAAgB,GAClB,MAAA,UAAU,CAAC,gBAAgB,mCAAI,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,CAAA;QAC7D,MAAM,QAAQ,GAAG,gBAAgB,CAAC,cAAc,CAAC,MAAM,CAAC,CAAA;QACxD,MAAM,iBAAiB,GAAG,YAAY,CAAC,IAAI,CACvC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,EAAE,KAAK,QAAQ,CAC/C,CAAA;QACD,MAAM,YAAY,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;YAC1C,IAAI,CAAC,iBAAiB;gBAAE,OAAO,KAAK,CAAA;YAEpC,OAAO,CACH,gBAAgB,CAAC,cAAc,CAAC,MAAM,CAAC;gBACvC,iBAAiB,CAAC,QAAQ,CAC7B,CAAA;QACL,CAAC,CAAC,CAAA;QACF,IAAI,YAAY,EAAE;YACd,MAAM,CAAC,cAAc,CAAC,GAAG,YAAY,CAAA;YACrC,mBAAmB,CAAC,qBAAqB,CACrC,QAAQ,EACR,MAAM,CAAC,cAAc,CAAC,EACtB,QAAQ,EACR,YAAY,CACf,CAAA;SACJ;IACL,CAAC;CACJ","file":"TreeRepositoryUtils.js","sourcesContent":["import { EntityManager } from \"../entity-manager/EntityManager\"\nimport { EntityMetadata } from \"../metadata/EntityMetadata\"\nimport { FindTreesOptions } from \"../repository/FindTreesOptions\"\n\n/**\n * Provides utilities for manipulating tree structures.\n *\n */\nexport class TreeRepositoryUtils {\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n static createRelationMaps(\n manager: EntityManager,\n metadata: EntityMetadata,\n alias: string,\n rawResults: any[],\n ): { id: any; parentId: any }[] {\n return rawResults.map((rawResult) => {\n const joinColumn = metadata.treeParentRelation!.joinColumns[0]\n const referencedColumn =\n joinColumn.referencedColumn ?? metadata.primaryColumns[0]\n // fixes issue #2518, default to databaseName property when givenDatabaseName is not set\n const joinColumnName =\n joinColumn.givenDatabaseName || joinColumn.databaseName\n const referencedColumnName =\n referencedColumn.givenDatabaseName ||\n referencedColumn.databaseName\n const id = rawResult[alias + \"_\" + referencedColumnName]\n const parentId = rawResult[alias + \"_\" + joinColumnName]\n return {\n id: manager.connection.driver.prepareHydratedValue(\n id,\n referencedColumn,\n ),\n parentId: manager.connection.driver.prepareHydratedValue(\n parentId,\n joinColumn,\n ),\n }\n })\n }\n\n static buildChildrenEntityTree(\n metadata: EntityMetadata,\n entity: any,\n entities: any[],\n relationMaps: { id: any; parentId: any }[],\n options: FindTreesOptions & { depth: number },\n ): void {\n const childProperty = metadata.treeChildrenRelation!.propertyName\n if (options.depth === 0) {\n entity[childProperty] = []\n return\n }\n const joinColumn = metadata.treeParentRelation!.joinColumns[0]\n const referencedColumn =\n joinColumn.referencedColumn ?? metadata.primaryColumns[0]\n const parentEntityId = referencedColumn.getEntityValue(entity)\n const childRelationMaps = relationMaps.filter(\n (relationMap) => relationMap.parentId === parentEntityId,\n )\n const childIds = new Set(\n childRelationMaps.map((relationMap) => relationMap.id),\n )\n entity[childProperty] = entities.filter((entity) =>\n childIds.has(referencedColumn.getEntityValue(entity)),\n )\n entity[childProperty].forEach((childEntity: any) => {\n TreeRepositoryUtils.buildChildrenEntityTree(\n metadata,\n childEntity,\n entities,\n relationMaps,\n {\n ...options,\n depth: options.depth - 1,\n },\n )\n })\n }\n\n static buildParentEntityTree(\n metadata: EntityMetadata,\n entity: any,\n entities: any[],\n relationMaps: { id: any; parentId: any }[],\n ): void {\n const parentProperty = metadata.treeParentRelation!.propertyName\n const joinColumn = metadata.treeParentRelation!.joinColumns[0]\n const referencedColumn =\n joinColumn.referencedColumn ?? metadata.primaryColumns[0]\n const entityId = referencedColumn.getEntityValue(entity)\n const parentRelationMap = relationMaps.find(\n (relationMap) => relationMap.id === entityId,\n )\n const parentEntity = entities.find((entity) => {\n if (!parentRelationMap) return false\n\n return (\n referencedColumn.getEntityValue(entity) ===\n parentRelationMap.parentId\n )\n })\n if (parentEntity) {\n entity[parentProperty] = parentEntity\n TreeRepositoryUtils.buildParentEntityTree(\n metadata,\n entity[parentProperty],\n entities,\n relationMaps,\n )\n }\n }\n}\n"],"sourceRoot":".."}
@@ -48,6 +48,7 @@ class MigrationRevertCommand {
48
48
  await dataSource.initialize();
49
49
  const options = {
50
50
  transaction: (_a = dataSource.options.migrationsTransactionMode) !== null && _a !== void 0 ? _a : "all",
51
+ fake: !!args.f,
51
52
  };
52
53
  switch (args.t) {
53
54
  case "all":
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/commands/MigrationRevertCommand.ts"],"names":[],"mappings":";;;;AAEA,6DAAyD;AACzD,wDAAuB;AACvB,8DAA6B;AAC7B,iDAA6C;AAE7C;;GAEG;AACH,MAAa,sBAAsB;IAAnC;QACI,YAAO,GAAG,kBAAkB,CAAA;QAC5B,aAAQ,GAAG,kCAAkC,CAAA;IAuEjD,CAAC;IArEG,OAAO,CAAC,IAAgB;QACpB,OAAO,IAAI;aACN,MAAM,CAAC,YAAY,EAAE;YAClB,KAAK,EAAE,GAAG;YACV,QAAQ,EACJ,6DAA6D;YACjE,YAAY,EAAE,IAAI;SACrB,CAAC;aACD,MAAM,CAAC,aAAa,EAAE;YACnB,KAAK,EAAE,GAAG;YACV,OAAO,EAAE,SAAS;YAClB,QAAQ,EACJ,0FAA0F;SACjG,CAAC;aACD,MAAM,CAAC,MAAM,EAAE;YACZ,KAAK,EAAE,GAAG;YACV,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,KAAK;YACd,QAAQ,EAAE,+BAA+B;SAC5C,CAAC,CAAA;IACV,CAAC;I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A;SAClB;IACL,CAAC;CACJ;AAzED,wDAyEC","file":"MigrationRevertCommand.js","sourcesContent":["import { DataSource } from \"../data-source/DataSource\"\nimport * as yargs from \"yargs\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport path from \"path\"\nimport process from \"process\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Reverts last migration command.\n */\nexport class MigrationRevertCommand implements yargs.CommandModule {\n command = \"migration:revert\"\n describe = \"Reverts last executed migration.\"\n\n builder(args: yargs.Argv) {\n return args\n .option(\"dataSource\", {\n alias: \"d\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\n })\n .option(\"transaction\", {\n alias: \"t\",\n default: \"default\",\n describe:\n \"Indicates if transaction should be used or not for migration revert. Enabled by default.\",\n })\n .option(\"fake\", {\n alias: \"f\",\n type: \"boolean\",\n default: false,\n describe: \"Fakes reverting the migration\",\n })\n }\n\n async handler(args: yargs.Arguments) {\n let dataSource: DataSource | undefined = undefined\n try {\n dataSource = await CommandUtils.loadDataSource(\n path.resolve(process.cwd(), args.dataSource as string),\n )\n dataSource.setOptions({\n subscribers: [],\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: [\"query\", \"error\", \"schema\"],\n })\n await dataSource.initialize()\n\n const options = {\n transaction:\n dataSource.options.migrationsTransactionMode ??\n (\"all\" as \"all\" | \"none\" | \"each\"),\n }\n\n switch (args.t) {\n case \"all\":\n options.transaction = \"all\"\n break\n case \"none\":\n case \"false\":\n options.transaction = \"none\"\n break\n case \"each\":\n options.transaction = \"each\"\n break\n default:\n // noop\n }\n\n await dataSource.undoLastMigration(options)\n await dataSource.destroy()\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during migration revert:\", err)\n\n if (dataSource && dataSource.isInitialized)\n await dataSource.destroy()\n\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/commands/MigrationRevertCommand.ts"],"names":[],"mappings":";;;;AAEA,6DAAyD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AAA;YAED,QAAQ,IAAI,CAAC,CAAC,EAAE;gBACZ,KAAK,KAAK;oBACN,OAAO,CAAC,WAAW,GAAG,KAAK,CAAA;oBAC3B,MAAK;gBACT,KAAK,MAAM,CAAC;gBACZ,KAAK,OAAO;oBACR,OAAO,CAAC,WAAW,GAAG,MAAM,CAAA;oBAC5B,MAAK;gBACT,KAAK,MAAM;oBACP,OAAO,CAAC,WAAW,GAAG,MAAM,CAAA;oBAC5B,MAAK;gBACT,QAAQ;gBACR,OAAO;aACV;YAED,MAAM,UAAU,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAA;YAC3C,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;SAC7B;QAAC,OAAO,GAAG,EAAE;YACV,6BAAa,CAAC,SAAS,CAAC,gCAAgC,EAAE,GAAG,CAAC,CAAA;YAE9D,IAAI,UAAU,IAAI,UAAU,CAAC,aAAa;gBACtC,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;YAE9B,iBAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SAClB;IACL,CAAC;CACJ;AA1ED,wDA0EC","file":"MigrationRevertCommand.js","sourcesContent":["import { DataSource } from \"../data-source/DataSource\"\nimport * as yargs from \"yargs\"\nimport { PlatformTools } from \"../platform/PlatformTools\"\nimport path from \"path\"\nimport process from \"process\"\nimport { CommandUtils } from \"./CommandUtils\"\n\n/**\n * Reverts last migration command.\n */\nexport class MigrationRevertCommand implements yargs.CommandModule {\n command = \"migration:revert\"\n describe = \"Reverts last executed migration.\"\n\n builder(args: yargs.Argv) {\n return args\n .option(\"dataSource\", {\n alias: \"d\",\n describe:\n \"Path to the file where your DataSource instance is defined.\",\n demandOption: true,\n })\n .option(\"transaction\", {\n alias: \"t\",\n default: \"default\",\n describe:\n \"Indicates if transaction should be used or not for migration revert. Enabled by default.\",\n })\n .option(\"fake\", {\n alias: \"f\",\n type: \"boolean\",\n default: false,\n describe: \"Fakes reverting the migration\",\n })\n }\n\n async handler(args: yargs.Arguments) {\n let dataSource: DataSource | undefined = undefined\n try {\n dataSource = await CommandUtils.loadDataSource(\n path.resolve(process.cwd(), args.dataSource as string),\n )\n dataSource.setOptions({\n subscribers: [],\n synchronize: false,\n migrationsRun: false,\n dropSchema: false,\n logging: [\"query\", \"error\", \"schema\"],\n })\n await dataSource.initialize()\n\n const options = {\n transaction:\n dataSource.options.migrationsTransactionMode ??\n (\"all\" as \"all\" | \"none\" | \"each\"),\n fake: !!args.f,\n }\n\n switch (args.t) {\n case \"all\":\n options.transaction = \"all\"\n break\n case \"none\":\n case \"false\":\n options.transaction = \"none\"\n break\n case \"each\":\n options.transaction = \"each\"\n break\n default:\n // noop\n }\n\n await dataSource.undoLastMigration(options)\n await dataSource.destroy()\n } catch (err) {\n PlatformTools.logCmdErr(\"Error during migration revert:\", err)\n\n if (dataSource && dataSource.isInitialized)\n await dataSource.destroy()\n\n process.exit(1)\n }\n }\n}\n"],"sourceRoot":".."}
@@ -123,8 +123,6 @@ class DataSource {
123
123
  // connect to the cache-specific database if cache is enabled
124
124
  if (this.queryResultCache)
125
125
  await this.queryResultCache.connect();
126
- // set connected status for the current connection
127
- ObjectUtils_1.ObjectUtils.assign(this, { isInitialized: true });
128
126
  try {
129
127
  // build all metadatas registered in the current connection
130
128
  await this.buildMetadatas();
@@ -147,6 +145,8 @@ class DataSource {
147
145
  await this.close();
148
146
  throw error;
149
147
  }
148
+ // set connected status for the current connection
149
+ ObjectUtils_1.ObjectUtils.assign(this, { isInitialized: true });
150
150
  return this;
151
151
  }
152
152
  /**
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/data-source/DataSource.ts"],"names":[],"mappings":";;;AAMA,oFAAgF;AAChF,oCAKiB;AAMjB,sEAAkE;AAIlE,yFAAqF;AAErF,iFAA6E;AAC7E,2DAAuD;AACvD,uFAAmF;AAEnF,4EAAwE;AACxE,2DAAuD;AACvD,8EAA0E;AAG1E,oEAAgE;AAChE,qDAAiD;AAGjD,oCAAuC;AACvC,wEAAoE;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;QAED,0CAA0C;QAC1C,KAAK,IAAI,cAAc,IAAI,eAAe,EAAE;YACxC,IACI,iCAAe,CAAC,uBAAuB,CAAC,cAAc,CAAC,MAAM,CAAC,EAChE;gBACE,cAAc,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAA;aAC5C;SACJ;IACL,CAAC;CACJ;AA7oBD,gCA6oBC","file":"DataSource.js","sourcesContent":["import { Driver } from \"../driver/Driver\"\nimport { Repository } from \"../repository/Repository\"\nimport { EntitySubscriberInterface } from \"../subscriber/EntitySubscriberInterface\"\nimport { EntityTarget } from \"../common/EntityTarget\"\nimport { ObjectType } from \"../common/ObjectType\"\nimport { EntityManager } from \"../entity-manager/EntityManager\"\nimport { DefaultNamingStrategy } from \"../naming-strategy/DefaultNamingStrategy\"\nimport {\n CannotConnectAlreadyConnectedError,\n CannotExecuteNotConnectedError,\n EntityMetadataNotFoundError,\n QueryRunnerProviderAlreadyReleasedError,\n} from \"../error\"\nimport { TreeRepository } from \"../repository/TreeRepository\"\nimport { NamingStrategyInterface } from \"../naming-strategy/NamingStrategyInterface\"\nimport { EntityMetadata } from \"../metadata/EntityMetadata\"\nimport { Logger } from \"../logger/Logger\"\nimport { MigrationInterface } from \"../migration/MigrationInterface\"\nimport { MigrationExecutor } from \"../migration/MigrationExecutor\"\nimport { Migration } from \"../migration/Migration\"\nimport { MongoRepository } from \"../repository/MongoRepository\"\nimport { MongoEntityManager } from \"../entity-manager/MongoEntityManager\"\nimport { EntityMetadataValidator } from \"../metadata-builder/EntityMetadataValidator\"\nimport { DataSourceOptions } from \"./DataSourceOptions\"\nimport { EntityManagerFactory } from \"../entity-manager/EntityManagerFactory\"\nimport { DriverFactory } from \"../driver/DriverFactory\"\nimport { ConnectionMetadataBuilder } from \"../connection/ConnectionMetadataBuilder\"\nimport { QueryRunner } from \"../query-runner/QueryRunner\"\nimport { SelectQueryBuilder } from \"../query-builder/SelectQueryBuilder\"\nimport { LoggerFactory } from \"../logger/LoggerFactory\"\nimport { QueryResultCacheFactory } from \"../cache/QueryResultCacheFactory\"\nimport { QueryResultCache } from \"../cache/QueryResultCache\"\nimport { SqljsEntityManager } from \"../entity-manager/SqljsEntityManager\"\nimport { RelationLoader } from \"../query-builder/RelationLoader\"\nimport { ObjectUtils } from \"../util/ObjectUtils\"\nimport { IsolationLevel } from \"../driver/types/IsolationLevel\"\nimport { ReplicationMode } from \"../driver/types/ReplicationMode\"\nimport { TypeORMError } from \"../error\"\nimport { RelationIdLoader } from \"../query-builder/RelationIdLoader\"\nimport { DriverUtils } from \"../driver/DriverUtils\"\nimport { InstanceChecker } from \"../util/InstanceChecker\"\nimport { ObjectLiteral } from \"../common/ObjectLiteral\"\n\n/**\n * DataSource is a pre-defined connection configuration to a specific database.\n * You can have multiple data sources connected (with multiple connections in it),\n * connected to multiple databases in your application.\n *\n * Before, it was called `Connection`, but now `Connection` is deprecated\n * because `Connection` isn't the best name for what it's actually is.\n */\nexport class DataSource {\n readonly \"@instanceof\" = Symbol.for(\"DataSource\")\n\n // -------------------------------------------------------------------------\n // Public Readonly Properties\n // -------------------------------------------------------------------------\n\n /**\n * Connection name.\n *\n * @deprecated we don't need names anymore since we are going to drop all related methods relying on this property.\n */\n readonly name: string\n\n /**\n * Connection options.\n */\n readonly options: DataSourceOptions\n\n /**\n * Indicates if DataSource is initialized or not.\n */\n readonly isInitialized: boolean\n\n /**\n * Database driver used by this connection.\n */\n driver: Driver\n\n /**\n * EntityManager of this connection.\n */\n readonly manager: EntityManager\n\n /**\n * Naming strategy used in the connection.\n */\n namingStrategy: NamingStrategyInterface\n\n /**\n * Name for the metadata table\n */\n readonly metadataTableName: string\n\n /**\n * Logger used to log orm events.\n */\n logger: Logger\n\n /**\n * Migration instances that are registered for this connection.\n */\n readonly migrations: MigrationInterface[] = []\n\n /**\n * Entity subscriber instances that are registered for this connection.\n */\n readonly subscribers: EntitySubscriberInterface<any>[] = []\n\n /**\n * All entity metadatas that are registered for this connection.\n */\n readonly entityMetadatas: EntityMetadata[] = []\n\n /**\n * Used to work with query result cache.\n */\n queryResultCache?: QueryResultCache\n\n /**\n * Used to load relations and work with lazy relations.\n */\n readonly relationLoader: RelationLoader\n\n readonly relationIdLoader: RelationIdLoader\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(options: DataSourceOptions) {\n this.name = options.name || \"default\"\n this.options = options\n this.logger = new LoggerFactory().create(\n this.options.logger,\n this.options.logging,\n )\n this.driver = new DriverFactory().create(this)\n this.manager = this.createEntityManager()\n this.namingStrategy =\n options.namingStrategy || new DefaultNamingStrategy()\n this.metadataTableName = options.metadataTableName || \"typeorm_metadata\"\n this.queryResultCache = options.cache\n ? new QueryResultCacheFactory(this).create()\n : undefined\n this.relationLoader = new RelationLoader(this)\n this.relationIdLoader = new RelationIdLoader(this)\n this.isInitialized = false\n }\n\n // -------------------------------------------------------------------------\n // Public Accessors\n // -------------------------------------------------------------------------\n\n /**\n Indicates if DataSource is initialized or not.\n *\n * @deprecated use .isInitialized instead\n */\n get isConnected() {\n return this.isInitialized\n }\n\n /**\n * Gets the mongodb entity manager that allows to perform mongodb-specific repository operations\n * with any entity in this connection.\n *\n * Available only in mongodb connections.\n */\n get mongoManager(): MongoEntityManager {\n if (!InstanceChecker.isMongoEntityManager(this.manager))\n throw new TypeORMError(\n `MongoEntityManager is only available for MongoDB databases.`,\n )\n\n return this.manager as MongoEntityManager\n }\n\n /**\n * Gets a sql.js specific Entity Manager that allows to perform special load and save operations\n *\n * Available only in connection with the sqljs driver.\n */\n get sqljsManager(): SqljsEntityManager {\n if (!InstanceChecker.isSqljsEntityManager(this.manager))\n throw new TypeORMError(\n `SqljsEntityManager is only available for Sqljs databases.`,\n )\n\n return this.manager\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n /**\n * Updates current connection options with provided options.\n */\n setOptions(options: Partial<DataSourceOptions>): this {\n Object.assign(this.options, options)\n\n if (options.logger || options.logging) {\n this.logger = new LoggerFactory().create(\n options.logger || this.options.logger,\n options.logging || this.options.logging,\n )\n }\n\n if (options.namingStrategy) {\n this.namingStrategy = options.namingStrategy\n }\n\n if (options.cache) {\n this.queryResultCache = new QueryResultCacheFactory(this).create()\n }\n\n return this\n }\n\n /**\n * Performs connection to the database.\n * This method should be called once on application bootstrap.\n * This method not necessarily creates database connection (depend on database type),\n * but it also can setup a connection pool with database to use.\n */\n async initialize(): Promise<this> {\n if (this.isInitialized)\n throw new CannotConnectAlreadyConnectedError(this.name)\n\n // connect to the database via its driver\n await this.driver.connect()\n\n // connect to the cache-specific database if cache is enabled\n if (this.queryResultCache) await this.queryResultCache.connect()\n\n // set connected status for the current connection\n ObjectUtils.assign(this, { isInitialized: true })\n\n try {\n // build all metadatas registered in the current connection\n await this.buildMetadatas()\n\n await this.driver.afterConnect()\n\n // if option is set - drop schema once connection is done\n if (this.options.dropSchema) await this.dropDatabase()\n\n // if option is set - automatically synchronize a schema\n if (this.options.migrationsRun)\n await this.runMigrations({\n transaction: this.options.migrationsTransactionMode,\n })\n\n // if option is set - automatically synchronize a schema\n if (this.options.synchronize) await this.synchronize()\n } catch (error) {\n // if for some reason build metadata fail (for example validation error during entity metadata check)\n // connection needs to be closed\n await this.close()\n throw error\n }\n\n return this\n }\n\n /**\n * Performs connection to the database.\n * This method should be called once on application bootstrap.\n * This method not necessarily creates database connection (depend on database type),\n * but it also can setup a connection pool with database to use.\n *\n * @deprecated use .initialize method instead\n */\n async connect(): Promise<this> {\n return this.initialize()\n }\n\n /**\n * Closes connection with the database.\n * Once connection is closed, you cannot use repositories or perform any operations except opening connection again.\n */\n async destroy(): Promise<void> {\n if (!this.isInitialized)\n throw new CannotExecuteNotConnectedError(this.name)\n\n await this.driver.disconnect()\n\n // disconnect from the cache-specific database if cache was enabled\n if (this.queryResultCache) await this.queryResultCache.disconnect()\n\n ObjectUtils.assign(this, { isInitialized: false })\n }\n\n /**\n * Closes connection with the database.\n * Once connection is closed, you cannot use repositories or perform any operations except opening connection again.\n *\n * @deprecated use .destroy method instead\n */\n async close(): Promise<void> {\n return this.destroy()\n }\n\n /**\n * Creates database schema for all entities registered in this connection.\n * Can be used only after connection to the database is established.\n *\n * @param dropBeforeSync If set to true then it drops the database with all its tables and data\n */\n async synchronize(dropBeforeSync: boolean = false): Promise<void> {\n if (!this.isInitialized)\n throw new CannotExecuteNotConnectedError(this.name)\n\n if (dropBeforeSync) await this.dropDatabase()\n\n const schemaBuilder = this.driver.createSchemaBuilder()\n await schemaBuilder.build()\n }\n\n /**\n * Drops the database and all its data.\n * Be careful with this method on production since this method will erase all your database tables and their data.\n * Can be used only after connection to the database is established.\n */\n // TODO rename\n async dropDatabase(): Promise<void> {\n const queryRunner = this.createQueryRunner()\n try {\n if (\n this.driver.options.type === \"mssql\" ||\n DriverUtils.isMySQLFamily(this.driver) ||\n this.driver.options.type === \"aurora-mysql\" ||\n DriverUtils.isSQLiteFamily(this.driver)\n ) {\n const databases: string[] = []\n this.entityMetadatas.forEach((metadata) => {\n if (\n metadata.database &&\n databases.indexOf(metadata.database) === -1\n )\n databases.push(metadata.database)\n })\n if (databases.length === 0 && this.driver.database) {\n databases.push(this.driver.database)\n }\n\n if (databases.length === 0) {\n await queryRunner.clearDatabase()\n } else {\n for (const database of databases) {\n await queryRunner.clearDatabase(database)\n }\n }\n } else {\n await queryRunner.clearDatabase()\n }\n } finally {\n await queryRunner.release()\n }\n }\n\n /**\n * Runs all pending migrations.\n * Can be used only after connection to the database is established.\n */\n async runMigrations(options?: {\n transaction?: \"all\" | \"none\" | \"each\"\n fake?: boolean\n }): Promise<Migration[]> {\n if (!this.isInitialized)\n throw new CannotExecuteNotConnectedError(this.name)\n\n const migrationExecutor = new MigrationExecutor(this)\n migrationExecutor.transaction =\n (options && options.transaction) || \"all\"\n migrationExecutor.fake = (options && options.fake) || false\n\n const successMigrations =\n await migrationExecutor.executePendingMigrations()\n return successMigrations\n }\n\n /**\n * Reverts last executed migration.\n * Can be used only after connection to the database is established.\n */\n async undoLastMigration(options?: {\n transaction?: \"all\" | \"none\" | \"each\"\n fake?: boolean\n }): Promise<void> {\n if (!this.isInitialized)\n throw new CannotExecuteNotConnectedError(this.name)\n\n const migrationExecutor = new MigrationExecutor(this)\n migrationExecutor.transaction =\n (options && options.transaction) || \"all\"\n migrationExecutor.fake = (options && options.fake) || false\n\n await migrationExecutor.undoLastMigration()\n }\n\n /**\n * Lists all migrations and whether they have been run.\n * Returns true if there are pending migrations\n */\n async showMigrations(): Promise<boolean> {\n if (!this.isInitialized) {\n throw new CannotExecuteNotConnectedError(this.name)\n }\n const migrationExecutor = new MigrationExecutor(this)\n return await migrationExecutor.showMigrations()\n }\n\n /**\n * Checks if entity metadata exist for the given entity class, target name or table name.\n */\n hasMetadata(target: EntityTarget<any>): boolean {\n return !!this.findMetadata(target)\n }\n\n /**\n * Gets entity metadata for the given entity class or schema name.\n */\n getMetadata(target: EntityTarget<any>): EntityMetadata {\n const metadata = this.findMetadata(target)\n if (!metadata) throw new EntityMetadataNotFoundError(target)\n\n return metadata\n }\n\n /**\n * Gets repository for the given entity.\n */\n getRepository<Entity extends ObjectLiteral>(\n target: EntityTarget<Entity>,\n ): Repository<Entity> {\n return this.manager.getRepository(target)\n }\n\n /**\n * Gets tree repository for the given entity class or name.\n * Only tree-type entities can have a TreeRepository, like ones decorated with @Tree decorator.\n */\n getTreeRepository<Entity extends ObjectLiteral>(\n target: EntityTarget<Entity>,\n ): TreeRepository<Entity> {\n return this.manager.getTreeRepository(target)\n }\n\n /**\n * Gets mongodb-specific repository for the given entity class or name.\n * Works only if connection is mongodb-specific.\n */\n getMongoRepository<Entity extends ObjectLiteral>(\n target: EntityTarget<Entity>,\n ): MongoRepository<Entity> {\n if (!(this.driver.options.type === \"mongodb\"))\n throw new TypeORMError(\n `You can use getMongoRepository only for MongoDB connections.`,\n )\n\n return this.manager.getRepository(target) as any\n }\n\n /**\n * Gets custom entity repository marked with @EntityRepository decorator.\n *\n * @deprecated use Repository.extend function to create a custom repository\n */\n getCustomRepository<T>(customRepository: ObjectType<T>): T {\n return this.manager.getCustomRepository(customRepository)\n }\n\n /**\n * Wraps given function execution (and all operations made there) into a transaction.\n * All database operations must be executed using provided entity manager.\n */\n async transaction<T>(\n runInTransaction: (entityManager: EntityManager) => Promise<T>,\n ): Promise<T>\n async transaction<T>(\n isolationLevel: IsolationLevel,\n runInTransaction: (entityManager: EntityManager) => Promise<T>,\n ): Promise<T>\n async transaction<T>(\n isolationOrRunInTransaction:\n | IsolationLevel\n | ((entityManager: EntityManager) => Promise<T>),\n runInTransactionParam?: (entityManager: EntityManager) => Promise<T>,\n ): Promise<any> {\n return this.manager.transaction(\n isolationOrRunInTransaction as any,\n runInTransactionParam as any,\n )\n }\n\n /**\n * Executes raw SQL query and returns raw database results.\n */\n async query(\n query: string,\n parameters?: any[],\n queryRunner?: QueryRunner,\n ): Promise<any> {\n if (InstanceChecker.isMongoEntityManager(this.manager))\n throw new TypeORMError(`Queries aren't supported by MongoDB.`)\n\n if (queryRunner && queryRunner.isReleased)\n throw new QueryRunnerProviderAlreadyReleasedError()\n\n const usedQueryRunner = queryRunner || this.createQueryRunner()\n\n try {\n return await usedQueryRunner.query(query, parameters) // await is needed here because we are using finally\n } finally {\n if (!queryRunner) await usedQueryRunner.release()\n }\n }\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n createQueryBuilder<Entity extends ObjectLiteral>(\n entityClass: EntityTarget<Entity>,\n alias: string,\n queryRunner?: QueryRunner,\n ): SelectQueryBuilder<Entity>\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n createQueryBuilder(queryRunner?: QueryRunner): SelectQueryBuilder<any>\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n createQueryBuilder<Entity extends ObjectLiteral>(\n entityOrRunner?: EntityTarget<Entity> | QueryRunner,\n alias?: string,\n queryRunner?: QueryRunner,\n ): SelectQueryBuilder<Entity> {\n if (InstanceChecker.isMongoEntityManager(this.manager))\n throw new TypeORMError(`Query Builder is not supported by MongoDB.`)\n\n if (alias) {\n alias = DriverUtils.buildAlias(this.driver, alias)\n const metadata = this.getMetadata(\n entityOrRunner as EntityTarget<Entity>,\n )\n return new SelectQueryBuilder(this, queryRunner)\n .select(alias)\n .from(metadata.target, alias)\n } else {\n return new SelectQueryBuilder(\n this,\n entityOrRunner as QueryRunner | undefined,\n )\n }\n }\n\n /**\n * Creates a query runner used for perform queries on a single database connection.\n * Using query runners you can control your queries to execute using single database connection and\n * manually control your database transaction.\n *\n * Mode is used in replication mode and indicates whatever you want to connect\n * to master database or any of slave databases.\n * If you perform writes you must use master database,\n * if you perform reads you can use slave databases.\n */\n createQueryRunner(mode: ReplicationMode = \"master\"): QueryRunner {\n const queryRunner = this.driver.createQueryRunner(mode)\n const manager = this.createEntityManager(queryRunner)\n Object.assign(queryRunner, { manager: manager })\n return queryRunner\n }\n\n /**\n * Gets entity metadata of the junction table (many-to-many table).\n */\n getManyToManyMetadata(\n entityTarget: EntityTarget<any>,\n relationPropertyPath: string,\n ) {\n const relationMetadata =\n this.getMetadata(entityTarget).findRelationWithPropertyPath(\n relationPropertyPath,\n )\n if (!relationMetadata)\n throw new TypeORMError(\n `Relation \"${relationPropertyPath}\" was not found in ${entityTarget} entity.`,\n )\n if (!relationMetadata.isManyToMany)\n throw new TypeORMError(\n `Relation \"${entityTarget}#${relationPropertyPath}\" does not have a many-to-many relationship.` +\n `You can use this method only on many-to-many relations.`,\n )\n\n return relationMetadata.junctionEntityMetadata\n }\n\n /**\n * Creates an Entity Manager for the current connection with the help of the EntityManagerFactory.\n */\n createEntityManager(queryRunner?: QueryRunner): EntityManager {\n return new EntityManagerFactory().create(this, queryRunner)\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Finds exist entity metadata by the given entity class, target name or table name.\n */\n protected findMetadata(\n target: EntityTarget<any>,\n ): EntityMetadata | undefined {\n return this.entityMetadatas.find((metadata) => {\n if (metadata.target === target) return true\n if (InstanceChecker.isEntitySchema(target)) {\n return metadata.name === target.options.name\n }\n if (typeof target === \"string\") {\n if (target.indexOf(\".\") !== -1) {\n return metadata.tablePath === target\n } else {\n return (\n metadata.name === target ||\n metadata.tableName === target\n )\n }\n }\n if (\n ObjectUtils.isObject(target) &&\n typeof target.name === \"string\"\n ) {\n if (target.name.indexOf(\".\") !== -1) {\n return metadata.tablePath === target.name\n } else {\n return (\n metadata.name === target.name ||\n metadata.tableName === target.name\n )\n }\n }\n\n return false\n })\n }\n\n /**\n * Builds metadatas for all registered classes inside this connection.\n */\n protected async buildMetadatas(): Promise<void> {\n const connectionMetadataBuilder = new ConnectionMetadataBuilder(this)\n const entityMetadataValidator = new EntityMetadataValidator()\n\n // create subscribers instances if they are not disallowed from high-level (for example they can disallowed from migrations run process)\n const flattenedSubscribers = ObjectUtils.mixedListToArray(\n this.options.subscribers || [],\n )\n const subscribers = await connectionMetadataBuilder.buildSubscribers(\n flattenedSubscribers,\n )\n ObjectUtils.assign(this, { subscribers: subscribers })\n\n // build entity metadatas\n const flattenedEntities = ObjectUtils.mixedListToArray(\n this.options.entities || [],\n )\n const entityMetadatas =\n await connectionMetadataBuilder.buildEntityMetadatas(\n flattenedEntities,\n )\n ObjectUtils.assign(this, { entityMetadatas: entityMetadatas })\n\n // create migration instances\n const flattenedMigrations = ObjectUtils.mixedListToArray(\n this.options.migrations || [],\n )\n const migrations = await connectionMetadataBuilder.buildMigrations(\n flattenedMigrations,\n )\n ObjectUtils.assign(this, { migrations: migrations })\n\n // validate all created entity metadatas to make sure user created entities are valid and correct\n entityMetadataValidator.validateMany(\n this.entityMetadatas.filter(\n (metadata) => metadata.tableType !== \"view\",\n ),\n this.driver,\n )\n\n // set current data source to the entities\n for (let entityMetadata of entityMetadatas) {\n if (\n InstanceChecker.isBaseEntityConstructor(entityMetadata.target)\n ) {\n entityMetadata.target.useDataSource(this)\n }\n }\n }\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../../src/data-source/DataSource.ts"],"names":[],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U,EAAE,UAAU,EAAE,CAAC,CAAA;QAEpD,iGAAiG;QACjG,uBAAuB,CAAC,YAAY,CAChC,IAAI,CAAC,eAAe,CAAC,MAAM,CACvB,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,SAAS,KAAK,MAAM,CAC9C,EACD,IAAI,CAAC,MAAM,CACd,CAAA;QAED,0CAA0C;QAC1C,KAAK,IAAI,cAAc,IAAI,eAAe,EAAE;YACxC,IACI,iCAAe,CAAC,uBAAuB,CAAC,cAAc,CAAC,MAAM,CAAC,EAChE;gBACE,cAAc,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAA;aAC5C;SACJ;IACL,CAAC;CACJ;AA7oBD,gCA6oBC","file":"DataSource.js","sourcesContent":["import { Driver } from \"../driver/Driver\"\nimport { Repository } from \"../repository/Repository\"\nimport { EntitySubscriberInterface } from \"../subscriber/EntitySubscriberInterface\"\nimport { EntityTarget } from \"../common/EntityTarget\"\nimport { ObjectType } from \"../common/ObjectType\"\nimport { EntityManager } from \"../entity-manager/EntityManager\"\nimport { DefaultNamingStrategy } from \"../naming-strategy/DefaultNamingStrategy\"\nimport {\n CannotConnectAlreadyConnectedError,\n CannotExecuteNotConnectedError,\n EntityMetadataNotFoundError,\n QueryRunnerProviderAlreadyReleasedError,\n} from \"../error\"\nimport { TreeRepository } from \"../repository/TreeRepository\"\nimport { NamingStrategyInterface } from \"../naming-strategy/NamingStrategyInterface\"\nimport { EntityMetadata } from \"../metadata/EntityMetadata\"\nimport { Logger } from \"../logger/Logger\"\nimport { MigrationInterface } from \"../migration/MigrationInterface\"\nimport { MigrationExecutor } from \"../migration/MigrationExecutor\"\nimport { Migration } from \"../migration/Migration\"\nimport { MongoRepository } from \"../repository/MongoRepository\"\nimport { MongoEntityManager } from \"../entity-manager/MongoEntityManager\"\nimport { EntityMetadataValidator } from \"../metadata-builder/EntityMetadataValidator\"\nimport { DataSourceOptions } from \"./DataSourceOptions\"\nimport { EntityManagerFactory } from \"../entity-manager/EntityManagerFactory\"\nimport { DriverFactory } from \"../driver/DriverFactory\"\nimport { ConnectionMetadataBuilder } from \"../connection/ConnectionMetadataBuilder\"\nimport { QueryRunner } from \"../query-runner/QueryRunner\"\nimport { SelectQueryBuilder } from \"../query-builder/SelectQueryBuilder\"\nimport { LoggerFactory } from \"../logger/LoggerFactory\"\nimport { QueryResultCacheFactory } from \"../cache/QueryResultCacheFactory\"\nimport { QueryResultCache } from \"../cache/QueryResultCache\"\nimport { SqljsEntityManager } from \"../entity-manager/SqljsEntityManager\"\nimport { RelationLoader } from \"../query-builder/RelationLoader\"\nimport { ObjectUtils } from \"../util/ObjectUtils\"\nimport { IsolationLevel } from \"../driver/types/IsolationLevel\"\nimport { ReplicationMode } from \"../driver/types/ReplicationMode\"\nimport { TypeORMError } from \"../error\"\nimport { RelationIdLoader } from \"../query-builder/RelationIdLoader\"\nimport { DriverUtils } from \"../driver/DriverUtils\"\nimport { InstanceChecker } from \"../util/InstanceChecker\"\nimport { ObjectLiteral } from \"../common/ObjectLiteral\"\n\n/**\n * DataSource is a pre-defined connection configuration to a specific database.\n * You can have multiple data sources connected (with multiple connections in it),\n * connected to multiple databases in your application.\n *\n * Before, it was called `Connection`, but now `Connection` is deprecated\n * because `Connection` isn't the best name for what it's actually is.\n */\nexport class DataSource {\n readonly \"@instanceof\" = Symbol.for(\"DataSource\")\n\n // -------------------------------------------------------------------------\n // Public Readonly Properties\n // -------------------------------------------------------------------------\n\n /**\n * Connection name.\n *\n * @deprecated we don't need names anymore since we are going to drop all related methods relying on this property.\n */\n readonly name: string\n\n /**\n * Connection options.\n */\n readonly options: DataSourceOptions\n\n /**\n * Indicates if DataSource is initialized or not.\n */\n readonly isInitialized: boolean\n\n /**\n * Database driver used by this connection.\n */\n driver: Driver\n\n /**\n * EntityManager of this connection.\n */\n readonly manager: EntityManager\n\n /**\n * Naming strategy used in the connection.\n */\n namingStrategy: NamingStrategyInterface\n\n /**\n * Name for the metadata table\n */\n readonly metadataTableName: string\n\n /**\n * Logger used to log orm events.\n */\n logger: Logger\n\n /**\n * Migration instances that are registered for this connection.\n */\n readonly migrations: MigrationInterface[] = []\n\n /**\n * Entity subscriber instances that are registered for this connection.\n */\n readonly subscribers: EntitySubscriberInterface<any>[] = []\n\n /**\n * All entity metadatas that are registered for this connection.\n */\n readonly entityMetadatas: EntityMetadata[] = []\n\n /**\n * Used to work with query result cache.\n */\n queryResultCache?: QueryResultCache\n\n /**\n * Used to load relations and work with lazy relations.\n */\n readonly relationLoader: RelationLoader\n\n readonly relationIdLoader: RelationIdLoader\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(options: DataSourceOptions) {\n this.name = options.name || \"default\"\n this.options = options\n this.logger = new LoggerFactory().create(\n this.options.logger,\n this.options.logging,\n )\n this.driver = new DriverFactory().create(this)\n this.manager = this.createEntityManager()\n this.namingStrategy =\n options.namingStrategy || new DefaultNamingStrategy()\n this.metadataTableName = options.metadataTableName || \"typeorm_metadata\"\n this.queryResultCache = options.cache\n ? new QueryResultCacheFactory(this).create()\n : undefined\n this.relationLoader = new RelationLoader(this)\n this.relationIdLoader = new RelationIdLoader(this)\n this.isInitialized = false\n }\n\n // -------------------------------------------------------------------------\n // Public Accessors\n // -------------------------------------------------------------------------\n\n /**\n Indicates if DataSource is initialized or not.\n *\n * @deprecated use .isInitialized instead\n */\n get isConnected() {\n return this.isInitialized\n }\n\n /**\n * Gets the mongodb entity manager that allows to perform mongodb-specific repository operations\n * with any entity in this connection.\n *\n * Available only in mongodb connections.\n */\n get mongoManager(): MongoEntityManager {\n if (!InstanceChecker.isMongoEntityManager(this.manager))\n throw new TypeORMError(\n `MongoEntityManager is only available for MongoDB databases.`,\n )\n\n return this.manager as MongoEntityManager\n }\n\n /**\n * Gets a sql.js specific Entity Manager that allows to perform special load and save operations\n *\n * Available only in connection with the sqljs driver.\n */\n get sqljsManager(): SqljsEntityManager {\n if (!InstanceChecker.isSqljsEntityManager(this.manager))\n throw new TypeORMError(\n `SqljsEntityManager is only available for Sqljs databases.`,\n )\n\n return this.manager\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n /**\n * Updates current connection options with provided options.\n */\n setOptions(options: Partial<DataSourceOptions>): this {\n Object.assign(this.options, options)\n\n if (options.logger || options.logging) {\n this.logger = new LoggerFactory().create(\n options.logger || this.options.logger,\n options.logging || this.options.logging,\n )\n }\n\n if (options.namingStrategy) {\n this.namingStrategy = options.namingStrategy\n }\n\n if (options.cache) {\n this.queryResultCache = new QueryResultCacheFactory(this).create()\n }\n\n return this\n }\n\n /**\n * Performs connection to the database.\n * This method should be called once on application bootstrap.\n * This method not necessarily creates database connection (depend on database type),\n * but it also can setup a connection pool with database to use.\n */\n async initialize(): Promise<this> {\n if (this.isInitialized)\n throw new CannotConnectAlreadyConnectedError(this.name)\n\n // connect to the database via its driver\n await this.driver.connect()\n\n // connect to the cache-specific database if cache is enabled\n if (this.queryResultCache) await this.queryResultCache.connect()\n\n try {\n // build all metadatas registered in the current connection\n await this.buildMetadatas()\n\n await this.driver.afterConnect()\n\n // if option is set - drop schema once connection is done\n if (this.options.dropSchema) await this.dropDatabase()\n\n // if option is set - automatically synchronize a schema\n if (this.options.migrationsRun)\n await this.runMigrations({\n transaction: this.options.migrationsTransactionMode,\n })\n\n // if option is set - automatically synchronize a schema\n if (this.options.synchronize) await this.synchronize()\n } catch (error) {\n // if for some reason build metadata fail (for example validation error during entity metadata check)\n // connection needs to be closed\n await this.close()\n throw error\n }\n\n // set connected status for the current connection\n ObjectUtils.assign(this, { isInitialized: true })\n\n return this\n }\n\n /**\n * Performs connection to the database.\n * This method should be called once on application bootstrap.\n * This method not necessarily creates database connection (depend on database type),\n * but it also can setup a connection pool with database to use.\n *\n * @deprecated use .initialize method instead\n */\n async connect(): Promise<this> {\n return this.initialize()\n }\n\n /**\n * Closes connection with the database.\n * Once connection is closed, you cannot use repositories or perform any operations except opening connection again.\n */\n async destroy(): Promise<void> {\n if (!this.isInitialized)\n throw new CannotExecuteNotConnectedError(this.name)\n\n await this.driver.disconnect()\n\n // disconnect from the cache-specific database if cache was enabled\n if (this.queryResultCache) await this.queryResultCache.disconnect()\n\n ObjectUtils.assign(this, { isInitialized: false })\n }\n\n /**\n * Closes connection with the database.\n * Once connection is closed, you cannot use repositories or perform any operations except opening connection again.\n *\n * @deprecated use .destroy method instead\n */\n async close(): Promise<void> {\n return this.destroy()\n }\n\n /**\n * Creates database schema for all entities registered in this connection.\n * Can be used only after connection to the database is established.\n *\n * @param dropBeforeSync If set to true then it drops the database with all its tables and data\n */\n async synchronize(dropBeforeSync: boolean = false): Promise<void> {\n if (!this.isInitialized)\n throw new CannotExecuteNotConnectedError(this.name)\n\n if (dropBeforeSync) await this.dropDatabase()\n\n const schemaBuilder = this.driver.createSchemaBuilder()\n await schemaBuilder.build()\n }\n\n /**\n * Drops the database and all its data.\n * Be careful with this method on production since this method will erase all your database tables and their data.\n * Can be used only after connection to the database is established.\n */\n // TODO rename\n async dropDatabase(): Promise<void> {\n const queryRunner = this.createQueryRunner()\n try {\n if (\n this.driver.options.type === \"mssql\" ||\n DriverUtils.isMySQLFamily(this.driver) ||\n this.driver.options.type === \"aurora-mysql\" ||\n DriverUtils.isSQLiteFamily(this.driver)\n ) {\n const databases: string[] = []\n this.entityMetadatas.forEach((metadata) => {\n if (\n metadata.database &&\n databases.indexOf(metadata.database) === -1\n )\n databases.push(metadata.database)\n })\n if (databases.length === 0 && this.driver.database) {\n databases.push(this.driver.database)\n }\n\n if (databases.length === 0) {\n await queryRunner.clearDatabase()\n } else {\n for (const database of databases) {\n await queryRunner.clearDatabase(database)\n }\n }\n } else {\n await queryRunner.clearDatabase()\n }\n } finally {\n await queryRunner.release()\n }\n }\n\n /**\n * Runs all pending migrations.\n * Can be used only after connection to the database is established.\n */\n async runMigrations(options?: {\n transaction?: \"all\" | \"none\" | \"each\"\n fake?: boolean\n }): Promise<Migration[]> {\n if (!this.isInitialized)\n throw new CannotExecuteNotConnectedError(this.name)\n\n const migrationExecutor = new MigrationExecutor(this)\n migrationExecutor.transaction =\n (options && options.transaction) || \"all\"\n migrationExecutor.fake = (options && options.fake) || false\n\n const successMigrations =\n await migrationExecutor.executePendingMigrations()\n return successMigrations\n }\n\n /**\n * Reverts last executed migration.\n * Can be used only after connection to the database is established.\n */\n async undoLastMigration(options?: {\n transaction?: \"all\" | \"none\" | \"each\"\n fake?: boolean\n }): Promise<void> {\n if (!this.isInitialized)\n throw new CannotExecuteNotConnectedError(this.name)\n\n const migrationExecutor = new MigrationExecutor(this)\n migrationExecutor.transaction =\n (options && options.transaction) || \"all\"\n migrationExecutor.fake = (options && options.fake) || false\n\n await migrationExecutor.undoLastMigration()\n }\n\n /**\n * Lists all migrations and whether they have been run.\n * Returns true if there are pending migrations\n */\n async showMigrations(): Promise<boolean> {\n if (!this.isInitialized) {\n throw new CannotExecuteNotConnectedError(this.name)\n }\n const migrationExecutor = new MigrationExecutor(this)\n return await migrationExecutor.showMigrations()\n }\n\n /**\n * Checks if entity metadata exist for the given entity class, target name or table name.\n */\n hasMetadata(target: EntityTarget<any>): boolean {\n return !!this.findMetadata(target)\n }\n\n /**\n * Gets entity metadata for the given entity class or schema name.\n */\n getMetadata(target: EntityTarget<any>): EntityMetadata {\n const metadata = this.findMetadata(target)\n if (!metadata) throw new EntityMetadataNotFoundError(target)\n\n return metadata\n }\n\n /**\n * Gets repository for the given entity.\n */\n getRepository<Entity extends ObjectLiteral>(\n target: EntityTarget<Entity>,\n ): Repository<Entity> {\n return this.manager.getRepository(target)\n }\n\n /**\n * Gets tree repository for the given entity class or name.\n * Only tree-type entities can have a TreeRepository, like ones decorated with @Tree decorator.\n */\n getTreeRepository<Entity extends ObjectLiteral>(\n target: EntityTarget<Entity>,\n ): TreeRepository<Entity> {\n return this.manager.getTreeRepository(target)\n }\n\n /**\n * Gets mongodb-specific repository for the given entity class or name.\n * Works only if connection is mongodb-specific.\n */\n getMongoRepository<Entity extends ObjectLiteral>(\n target: EntityTarget<Entity>,\n ): MongoRepository<Entity> {\n if (!(this.driver.options.type === \"mongodb\"))\n throw new TypeORMError(\n `You can use getMongoRepository only for MongoDB connections.`,\n )\n\n return this.manager.getRepository(target) as any\n }\n\n /**\n * Gets custom entity repository marked with @EntityRepository decorator.\n *\n * @deprecated use Repository.extend function to create a custom repository\n */\n getCustomRepository<T>(customRepository: ObjectType<T>): T {\n return this.manager.getCustomRepository(customRepository)\n }\n\n /**\n * Wraps given function execution (and all operations made there) into a transaction.\n * All database operations must be executed using provided entity manager.\n */\n async transaction<T>(\n runInTransaction: (entityManager: EntityManager) => Promise<T>,\n ): Promise<T>\n async transaction<T>(\n isolationLevel: IsolationLevel,\n runInTransaction: (entityManager: EntityManager) => Promise<T>,\n ): Promise<T>\n async transaction<T>(\n isolationOrRunInTransaction:\n | IsolationLevel\n | ((entityManager: EntityManager) => Promise<T>),\n runInTransactionParam?: (entityManager: EntityManager) => Promise<T>,\n ): Promise<any> {\n return this.manager.transaction(\n isolationOrRunInTransaction as any,\n runInTransactionParam as any,\n )\n }\n\n /**\n * Executes raw SQL query and returns raw database results.\n */\n async query(\n query: string,\n parameters?: any[],\n queryRunner?: QueryRunner,\n ): Promise<any> {\n if (InstanceChecker.isMongoEntityManager(this.manager))\n throw new TypeORMError(`Queries aren't supported by MongoDB.`)\n\n if (queryRunner && queryRunner.isReleased)\n throw new QueryRunnerProviderAlreadyReleasedError()\n\n const usedQueryRunner = queryRunner || this.createQueryRunner()\n\n try {\n return await usedQueryRunner.query(query, parameters) // await is needed here because we are using finally\n } finally {\n if (!queryRunner) await usedQueryRunner.release()\n }\n }\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n createQueryBuilder<Entity extends ObjectLiteral>(\n entityClass: EntityTarget<Entity>,\n alias: string,\n queryRunner?: QueryRunner,\n ): SelectQueryBuilder<Entity>\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n createQueryBuilder(queryRunner?: QueryRunner): SelectQueryBuilder<any>\n\n /**\n * Creates a new query builder that can be used to build a SQL query.\n */\n createQueryBuilder<Entity extends ObjectLiteral>(\n entityOrRunner?: EntityTarget<Entity> | QueryRunner,\n alias?: string,\n queryRunner?: QueryRunner,\n ): SelectQueryBuilder<Entity> {\n if (InstanceChecker.isMongoEntityManager(this.manager))\n throw new TypeORMError(`Query Builder is not supported by MongoDB.`)\n\n if (alias) {\n alias = DriverUtils.buildAlias(this.driver, alias)\n const metadata = this.getMetadata(\n entityOrRunner as EntityTarget<Entity>,\n )\n return new SelectQueryBuilder(this, queryRunner)\n .select(alias)\n .from(metadata.target, alias)\n } else {\n return new SelectQueryBuilder(\n this,\n entityOrRunner as QueryRunner | undefined,\n )\n }\n }\n\n /**\n * Creates a query runner used for perform queries on a single database connection.\n * Using query runners you can control your queries to execute using single database connection and\n * manually control your database transaction.\n *\n * Mode is used in replication mode and indicates whatever you want to connect\n * to master database or any of slave databases.\n * If you perform writes you must use master database,\n * if you perform reads you can use slave databases.\n */\n createQueryRunner(mode: ReplicationMode = \"master\"): QueryRunner {\n const queryRunner = this.driver.createQueryRunner(mode)\n const manager = this.createEntityManager(queryRunner)\n Object.assign(queryRunner, { manager: manager })\n return queryRunner\n }\n\n /**\n * Gets entity metadata of the junction table (many-to-many table).\n */\n getManyToManyMetadata(\n entityTarget: EntityTarget<any>,\n relationPropertyPath: string,\n ) {\n const relationMetadata =\n this.getMetadata(entityTarget).findRelationWithPropertyPath(\n relationPropertyPath,\n )\n if (!relationMetadata)\n throw new TypeORMError(\n `Relation \"${relationPropertyPath}\" was not found in ${entityTarget} entity.`,\n )\n if (!relationMetadata.isManyToMany)\n throw new TypeORMError(\n `Relation \"${entityTarget}#${relationPropertyPath}\" does not have a many-to-many relationship.` +\n `You can use this method only on many-to-many relations.`,\n )\n\n return relationMetadata.junctionEntityMetadata\n }\n\n /**\n * Creates an Entity Manager for the current connection with the help of the EntityManagerFactory.\n */\n createEntityManager(queryRunner?: QueryRunner): EntityManager {\n return new EntityManagerFactory().create(this, queryRunner)\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Finds exist entity metadata by the given entity class, target name or table name.\n */\n protected findMetadata(\n target: EntityTarget<any>,\n ): EntityMetadata | undefined {\n return this.entityMetadatas.find((metadata) => {\n if (metadata.target === target) return true\n if (InstanceChecker.isEntitySchema(target)) {\n return metadata.name === target.options.name\n }\n if (typeof target === \"string\") {\n if (target.indexOf(\".\") !== -1) {\n return metadata.tablePath === target\n } else {\n return (\n metadata.name === target ||\n metadata.tableName === target\n )\n }\n }\n if (\n ObjectUtils.isObject(target) &&\n typeof target.name === \"string\"\n ) {\n if (target.name.indexOf(\".\") !== -1) {\n return metadata.tablePath === target.name\n } else {\n return (\n metadata.name === target.name ||\n metadata.tableName === target.name\n )\n }\n }\n\n return false\n })\n }\n\n /**\n * Builds metadatas for all registered classes inside this connection.\n */\n protected async buildMetadatas(): Promise<void> {\n const connectionMetadataBuilder = new ConnectionMetadataBuilder(this)\n const entityMetadataValidator = new EntityMetadataValidator()\n\n // create subscribers instances if they are not disallowed from high-level (for example they can disallowed from migrations run process)\n const flattenedSubscribers = ObjectUtils.mixedListToArray(\n this.options.subscribers || [],\n )\n const subscribers = await connectionMetadataBuilder.buildSubscribers(\n flattenedSubscribers,\n )\n ObjectUtils.assign(this, { subscribers: subscribers })\n\n // build entity metadatas\n const flattenedEntities = ObjectUtils.mixedListToArray(\n this.options.entities || [],\n )\n const entityMetadatas =\n await connectionMetadataBuilder.buildEntityMetadatas(\n flattenedEntities,\n )\n ObjectUtils.assign(this, { entityMetadatas: entityMetadatas })\n\n // create migration instances\n const flattenedMigrations = ObjectUtils.mixedListToArray(\n this.options.migrations || [],\n )\n const migrations = await connectionMetadataBuilder.buildMigrations(\n flattenedMigrations,\n )\n ObjectUtils.assign(this, { migrations: migrations })\n\n // validate all created entity metadatas to make sure user created entities are valid and correct\n entityMetadataValidator.validateMany(\n this.entityMetadatas.filter(\n (metadata) => metadata.tableType !== \"view\",\n ),\n this.driver,\n )\n\n // set current data source to the entities\n for (let entityMetadata of entityMetadatas) {\n if (\n InstanceChecker.isBaseEntityConstructor(entityMetadata.target)\n ) {\n entityMetadata.target.useDataSource(this)\n }\n }\n }\n}\n"],"sourceRoot":".."}
@@ -69,12 +69,6 @@ class BetterSqlite3QueryRunner extends AbstractSqliteQueryRunner_1.AbstractSqlit
69
69
  if (this.isReleased)
70
70
  throw new QueryRunnerAlreadyReleasedError_1.QueryRunnerAlreadyReleasedError();
71
71
  const connection = this.driver.connection;
72
- parameters = parameters || [];
73
- for (let i = 0; i < parameters.length; i++) {
74
- // in "where" clauses the parameters are not escaped by the driver
75
- if (typeof parameters[i] === "boolean")
76
- parameters[i] = +parameters[i];
77
- }
78
72
  this.driver.connection.logger.logQuery(query, parameters, this);
79
73
  const queryStartTime = +new Date();
80
74
  const stmt = await this.getStmt(query);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/driver/better-sqlite3/BetterSqlite3QueryRunner.ts"],"names":[],"mappings":";;;AAAA,iGAA6F;AAC7F,mEAA+D;AAC/D,4FAAwF;AACxF,8DAA0D;AAE1D,gEAA4D;AAE5D;;;;;GAKG;AACH,MAAa,wBAAyB,SAAQ,qDAAyB;IAMnE,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YAAY,MAA2B;QACnC,KAAK,EAAE,CAAA;QAYH,cAAS,GAAG,IAAI,GAAG,EAAe,CAAA;QAXtC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAA;QACnC,IAAI,CAAC,WAAW,GAAG,IAAI,yBAAW,CAAC,IAAI,CAAC,CAAA;QACxC,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,kBAAkB,KAAK,QAAQ,EAAE;YAC5D,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAA;SAC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BAAiB,CAAC,SAAiB,EAAE,MAAc;QAC/D,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,CAAA;QAC5D,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CACxB,UACI,QAAQ,CAAC,CAAC,CAAC,IAAI,QAAQ,IAAI,CAAC,CAAC,CAAC,EAClC,GAAG,MAAM,KAAK,SAAS,IAAI,CAC9B,CAAA;QACD,OAAO,GAAG,CAAA;IACd,CAAC;CACJ;AA7JD,4DA6JC","file":"BetterSqlite3QueryRunner.js","sourcesContent":["import { QueryRunnerAlreadyReleasedError } from \"../../error/QueryRunnerAlreadyReleasedError\"\nimport { QueryFailedError } from \"../../error/QueryFailedError\"\nimport { AbstractSqliteQueryRunner } from \"../sqlite-abstract/AbstractSqliteQueryRunner\"\nimport { Broadcaster } from \"../../subscriber/Broadcaster\"\nimport { BetterSqlite3Driver } from \"./BetterSqlite3Driver\"\nimport { QueryResult } from \"../../query-runner/QueryResult\"\n\n/**\n * Runs queries on a single sqlite database connection.\n *\n * Does not support compose primary keys with autoincrement field.\n * todo: need to throw exception for this case.\n */\nexport class BetterSqlite3QueryRunner extends AbstractSqliteQueryRunner {\n /**\n * Database driver used by connection.\n */\n driver: BetterSqlite3Driver\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(driver: BetterSqlite3Driver) {\n super()\n this.driver = driver\n this.connection = driver.connection\n this.broadcaster = new Broadcaster(this)\n if (typeof this.driver.options.statementCacheSize === \"number\") {\n this.cacheSize = this.driver.options.statementCacheSize\n } else {\n this.cacheSize = 100\n }\n }\n\n private cacheSize: number\n private stmtCache = new Map<string, any>()\n\n private async getStmt(query: string) {\n if (this.cacheSize > 0) {\n let stmt = this.stmtCache.get(query)\n if (!stmt) {\n const databaseConnection = await this.connect()\n stmt = databaseConnection.prepare(query)\n this.stmtCache.set(query, stmt)\n while (this.stmtCache.size > this.cacheSize) {\n // since es6 map keeps the insertion order,\n // it comes to be FIFO cache\n const key = this.stmtCache.keys().next().value\n this.stmtCache.delete(key)\n }\n }\n return stmt\n } else {\n const databaseConnection = await this.connect()\n return databaseConnection.prepare(query)\n }\n }\n\n /**\n * Called before migrations are run.\n */\n async beforeMigration(): Promise<void> {\n await this.query(`PRAGMA foreign_keys = OFF`)\n }\n\n /**\n * Called after migrations are run.\n */\n async afterMigration(): Promise<void> {\n await this.query(`PRAGMA foreign_keys = ON`)\n }\n\n /**\n * Executes a given SQL query.\n */\n async query(\n query: string,\n parameters?: any[],\n useStructuredResult = false,\n ): Promise<any> {\n if (this.isReleased) throw new QueryRunnerAlreadyReleasedError()\n\n const connection = this.driver.connection\n\n parameters = parameters || []\n for (let i = 0; i < parameters.length; i++) {\n // in \"where\" clauses the parameters are not escaped by the driver\n if (typeof parameters[i] === \"boolean\")\n parameters[i] = +parameters[i]\n }\n\n this.driver.connection.logger.logQuery(query, parameters, this)\n const queryStartTime = +new Date()\n\n const stmt = await this.getStmt(query)\n\n try {\n const result = new QueryResult()\n\n if (stmt.reader) {\n const raw = stmt.all.apply(stmt, parameters)\n\n result.raw = raw\n\n if (Array.isArray(raw)) {\n result.records = raw\n }\n } else {\n const raw = stmt.run.apply(stmt, parameters)\n result.affected = raw.changes\n result.raw = raw.lastInsertRowid\n }\n\n // log slow queries if maxQueryExecution time is set\n const maxQueryExecutionTime =\n this.driver.options.maxQueryExecutionTime\n const queryEndTime = +new Date()\n const queryExecutionTime = queryEndTime - queryStartTime\n if (\n maxQueryExecutionTime &&\n queryExecutionTime > maxQueryExecutionTime\n )\n connection.logger.logQuerySlow(\n queryExecutionTime,\n query,\n parameters,\n this,\n )\n\n if (!useStructuredResult) {\n return result.raw\n }\n\n return result\n } catch (err) {\n connection.logger.logQueryError(err, query, parameters, this)\n throw new QueryFailedError(query, parameters, err)\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n protected async loadTableRecords(\n tablePath: string,\n tableOrIndex: \"table\" | \"index\",\n ) {\n const [database, tableName] = this.splitTablePath(tablePath)\n const res = await this.query(\n `SELECT ${\n database ? `'${database}'` : null\n } as database, * FROM ${this.escapePath(\n `${database ? `${database}.` : \"\"}sqlite_master`,\n )} WHERE \"type\" = '${tableOrIndex}' AND \"${\n tableOrIndex === \"table\" ? \"name\" : \"tbl_name\"\n }\" IN ('${tableName}')`,\n )\n return res\n }\n protected async loadPragmaRecords(tablePath: string, pragma: string) {\n const [database, tableName] = this.splitTablePath(tablePath)\n const res = await this.query(\n `PRAGMA ${\n database ? `\"${database}\".` : \"\"\n }${pragma}(\"${tableName}\")`,\n )\n return res\n }\n}\n"],"sourceRoot":"../.."}
1
+ {"version":3,"sources":["../../src/driver/better-sqlite3/BetterSqlite3QueryRunner.ts"],"names":[],"mappings":";;;AAAA,iGAA6F;AAC7F,mEAA+D;AAC/D,4FAAwF;AACxF,8DAA0D;AAE1D,gEAA4D;AAE5D;;;;;GAKG;AACH,MAAa,wBAAyB,SAAQ,qDAAyB;IAMnE,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YAAY,MAA2B;QACnC,KAAK,EAAE,CAAA;QAYH,cAAS,GAAG,IAAI,GAAG,EAAe,CAAA;QAXtC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAA;QACnC,IAAI,CAAC,WAAW,GAAG,IAAI,yBAAW,CAAC,IAAI,CAAC,CAAA;QACxC,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,kBAAkB,KAAK,QAAQ,EAAE;YAC5D,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAA;SAC1D;aAAM;YACH,IAAI,CAAC,SAAS,GAAG,GAAG,CAAA;SACvB;IACL,CAAC;IAKO,KAAK,CAAC,OAAO,CAAC,KAAa;QAC/B,IAAI,IA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asedError } from \"../../error/QueryRunnerAlreadyReleasedError\"\nimport { QueryFailedError } from \"../../error/QueryFailedError\"\nimport { AbstractSqliteQueryRunner } from \"../sqlite-abstract/AbstractSqliteQueryRunner\"\nimport { Broadcaster } from \"../../subscriber/Broadcaster\"\nimport { BetterSqlite3Driver } from \"./BetterSqlite3Driver\"\nimport { QueryResult } from \"../../query-runner/QueryResult\"\n\n/**\n * Runs queries on a single sqlite database connection.\n *\n * Does not support compose primary keys with autoincrement field.\n * todo: need to throw exception for this case.\n */\nexport class BetterSqlite3QueryRunner extends AbstractSqliteQueryRunner {\n /**\n * Database driver used by connection.\n */\n driver: BetterSqlite3Driver\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(driver: BetterSqlite3Driver) {\n super()\n this.driver = driver\n this.connection = driver.connection\n this.broadcaster = new Broadcaster(this)\n if (typeof this.driver.options.statementCacheSize === \"number\") {\n this.cacheSize = this.driver.options.statementCacheSize\n } else {\n this.cacheSize = 100\n }\n }\n\n private cacheSize: number\n private stmtCache = new Map<string, any>()\n\n private async getStmt(query: string) {\n if (this.cacheSize > 0) {\n let stmt = this.stmtCache.get(query)\n if (!stmt) {\n const databaseConnection = await this.connect()\n stmt = databaseConnection.prepare(query)\n this.stmtCache.set(query, stmt)\n while (this.stmtCache.size > this.cacheSize) {\n // since es6 map keeps the insertion order,\n // it comes to be FIFO cache\n const key = this.stmtCache.keys().next().value\n this.stmtCache.delete(key)\n }\n }\n return stmt\n } else {\n const databaseConnection = await this.connect()\n return databaseConnection.prepare(query)\n }\n }\n\n /**\n * Called before migrations are run.\n */\n async beforeMigration(): Promise<void> {\n await this.query(`PRAGMA foreign_keys = OFF`)\n }\n\n /**\n * Called after migrations are run.\n */\n async afterMigration(): Promise<void> {\n await this.query(`PRAGMA foreign_keys = ON`)\n }\n\n /**\n * Executes a given SQL query.\n */\n async query(\n query: string,\n parameters?: any[],\n useStructuredResult = false,\n ): Promise<any> {\n if (this.isReleased) throw new QueryRunnerAlreadyReleasedError()\n\n const connection = this.driver.connection\n\n this.driver.connection.logger.logQuery(query, parameters, this)\n const queryStartTime = +new Date()\n\n const stmt = await this.getStmt(query)\n\n try {\n const result = new QueryResult()\n\n if (stmt.reader) {\n const raw = stmt.all.apply(stmt, parameters)\n\n result.raw = raw\n\n if (Array.isArray(raw)) {\n result.records = raw\n }\n } else {\n const raw = stmt.run.apply(stmt, parameters)\n result.affected = raw.changes\n result.raw = raw.lastInsertRowid\n }\n\n // log slow queries if maxQueryExecution time is set\n const maxQueryExecutionTime =\n this.driver.options.maxQueryExecutionTime\n const queryEndTime = +new Date()\n const queryExecutionTime = queryEndTime - queryStartTime\n if (\n maxQueryExecutionTime &&\n queryExecutionTime > maxQueryExecutionTime\n )\n connection.logger.logQuerySlow(\n queryExecutionTime,\n query,\n parameters,\n this,\n )\n\n if (!useStructuredResult) {\n return result.raw\n }\n\n return result\n } catch (err) {\n connection.logger.logQueryError(err, query, parameters, this)\n throw new QueryFailedError(query, parameters, err)\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n protected async loadTableRecords(\n tablePath: string,\n tableOrIndex: \"table\" | \"index\",\n ) {\n const [database, tableName] = this.splitTablePath(tablePath)\n const res = await this.query(\n `SELECT ${\n database ? `'${database}'` : null\n } as database, * FROM ${this.escapePath(\n `${database ? `${database}.` : \"\"}sqlite_master`,\n )} WHERE \"type\" = '${tableOrIndex}' AND \"${\n tableOrIndex === \"table\" ? \"name\" : \"tbl_name\"\n }\" IN ('${tableName}')`,\n )\n return res\n }\n protected async loadPragmaRecords(tablePath: string, pragma: string) {\n const [database, tableName] = this.splitTablePath(tablePath)\n const res = await this.query(\n `PRAGMA ${\n database ? `\"${database}\".` : \"\"\n }${pragma}(\"${tableName}\")`,\n )\n return res\n }\n}\n"],"sourceRoot":"../.."}
@@ -250,14 +250,26 @@ export declare class PostgresQueryRunner extends BaseQueryRunner implements Quer
250
250
  * Creates a new index.
251
251
  */
252
252
  createIndex(tableOrName: Table | string, index: TableIndex): Promise<void>;
253
+ /**
254
+ * Create a new view index.
255
+ */
256
+ createViewIndex(viewOrName: View | string, index: TableIndex): Promise<void>;
253
257
  /**
254
258
  * Creates a new indices
255
259
  */
256
260
  createIndices(tableOrName: Table | string, indices: TableIndex[]): Promise<void>;
261
+ /**
262
+ * Creates new view indices
263
+ */
264
+ createViewIndices(viewOrName: View | string, indices: TableIndex[]): Promise<void>;
257
265
  /**
258
266
  * Drops an index from the table.
259
267
  */
260
268
  dropIndex(tableOrName: Table | string, indexOrName: TableIndex | string): Promise<void>;
269
+ /**
270
+ * Drops an index from a view.
271
+ */
272
+ dropViewIndex(viewOrName: View | string, indexOrName: TableIndex | string): Promise<void>;
261
273
  /**
262
274
  * Drops an indices from the table.
263
275
  */
@@ -318,10 +330,14 @@ export declare class PostgresQueryRunner extends BaseQueryRunner implements Quer
318
330
  * Builds create index sql.
319
331
  */
320
332
  protected createIndexSql(table: Table, index: TableIndex): Query;
333
+ /**
334
+ * Builds create view index sql.
335
+ */
336
+ protected createViewIndexSql(view: View, index: TableIndex): Query;
321
337
  /**
322
338
  * Builds drop index sql.
323
339
  */
324
- protected dropIndexSql(table: Table, indexOrName: TableIndex | string): Query;
340
+ protected dropIndexSql(table: Table | View, indexOrName: TableIndex | string): Query;
325
341
  /**
326
342
  * Builds create primary key sql.
327
343
  */
@@ -1482,6 +1482,21 @@ class PostgresQueryRunner extends BaseQueryRunner_1.BaseQueryRunner {
1482
1482
  await this.executeQueries(up, down);
1483
1483
  table.addIndex(index);
1484
1484
  }
1485
+ /**
1486
+ * Create a new view index.
1487
+ */
1488
+ async createViewIndex(viewOrName, index) {
1489
+ const view = InstanceChecker_1.InstanceChecker.isView(viewOrName)
1490
+ ? viewOrName
1491
+ : await this.getCachedView(viewOrName);
1492
+ // new index may be passed without name. In this case we generate index name manually.
1493
+ if (!index.name)
1494
+ index.name = this.generateIndexName(view, index);
1495
+ const up = this.createViewIndexSql(view, index);
1496
+ const down = this.dropIndexSql(view, index);
1497
+ await this.executeQueries(up, down);
1498
+ view.addIndex(index);
1499
+ }
1485
1500
  /**
1486
1501
  * Creates a new indices
1487
1502
  */
@@ -1490,6 +1505,14 @@ class PostgresQueryRunner extends BaseQueryRunner_1.BaseQueryRunner {
1490
1505
  await this.createIndex(tableOrName, index);
1491
1506
  }
1492
1507
  }
1508
+ /**
1509
+ * Creates new view indices
1510
+ */
1511
+ async createViewIndices(viewOrName, indices) {
1512
+ for (const index of indices) {
1513
+ await this.createViewIndex(viewOrName, index);
1514
+ }
1515
+ }
1493
1516
  /**
1494
1517
  * Drops an index from the table.
1495
1518
  */
@@ -1510,6 +1533,26 @@ class PostgresQueryRunner extends BaseQueryRunner_1.BaseQueryRunner {
1510
1533
  await this.executeQueries(up, down);
1511
1534
  table.removeIndex(index);
1512
1535
  }
1536
+ /**
1537
+ * Drops an index from a view.
1538
+ */
1539
+ async dropViewIndex(viewOrName, indexOrName) {
1540
+ const view = InstanceChecker_1.InstanceChecker.isView(viewOrName)
1541
+ ? viewOrName
1542
+ : await this.getCachedView(viewOrName);
1543
+ const index = InstanceChecker_1.InstanceChecker.isTableIndex(indexOrName)
1544
+ ? indexOrName
1545
+ : view.indices.find((i) => i.name === indexOrName);
1546
+ if (!index)
1547
+ throw new error_1.TypeORMError(`Supplied index ${indexOrName} was not found in view ${view.name}`);
1548
+ // old index may be passed without name. In this case we generate index name manually.
1549
+ if (!index.name)
1550
+ index.name = this.generateIndexName(view, index);
1551
+ const up = this.dropIndexSql(view, index);
1552
+ const down = this.createViewIndexSql(view, index);
1553
+ await this.executeQueries(up, down);
1554
+ view.removeIndex(index);
1555
+ }
1513
1556
  /**
1514
1557
  * Drops an indices from the table.
1515
1558
  */
@@ -1608,12 +1651,41 @@ class PostgresQueryRunner extends BaseQueryRunner_1.BaseQueryRunner {
1608
1651
  return `("t"."schema" = '${schema}' AND "t"."name" = '${tableName}')`;
1609
1652
  })
1610
1653
  .join(" OR ");
1654
+ const constraintsCondition = viewNames.length === 0
1655
+ ? "1=1"
1656
+ : viewNames
1657
+ .map((tableName) => this.driver.parseTableName(tableName))
1658
+ .map(({ schema, tableName }) => {
1659
+ if (!schema) {
1660
+ schema =
1661
+ this.driver.options.schema || currentSchema;
1662
+ }
1663
+ return `("ns"."nspname" = '${schema}' AND "t"."relname" = '${tableName}')`;
1664
+ })
1665
+ .join(" OR ");
1666
+ const indicesSql = `SELECT "ns"."nspname" AS "table_schema", "t"."relname" AS "table_name", "i"."relname" AS "constraint_name", "a"."attname" AS "column_name", ` +
1667
+ `CASE "ix"."indisunique" WHEN 't' THEN 'TRUE' ELSE'FALSE' END AS "is_unique", pg_get_expr("ix"."indpred", "ix"."indrelid") AS "condition", ` +
1668
+ `"types"."typname" AS "type_name" ` +
1669
+ `FROM "pg_class" "t" ` +
1670
+ `INNER JOIN "pg_index" "ix" ON "ix"."indrelid" = "t"."oid" ` +
1671
+ `INNER JOIN "pg_attribute" "a" ON "a"."attrelid" = "t"."oid" AND "a"."attnum" = ANY ("ix"."indkey") ` +
1672
+ `INNER JOIN "pg_namespace" "ns" ON "ns"."oid" = "t"."relnamespace" ` +
1673
+ `INNER JOIN "pg_class" "i" ON "i"."oid" = "ix"."indexrelid" ` +
1674
+ `INNER JOIN "pg_type" "types" ON "types"."oid" = "a"."atttypid" ` +
1675
+ `LEFT JOIN "pg_constraint" "cnst" ON "cnst"."conname" = "i"."relname" ` +
1676
+ `WHERE "t"."relkind" IN ('m') AND "cnst"."contype" IS NULL AND (${constraintsCondition})`;
1611
1677
  const query = `SELECT "t".* FROM ${this.escapePath(this.getTypeormMetadataTableName())} "t" ` +
1612
1678
  `INNER JOIN "pg_catalog"."pg_class" "c" ON "c"."relname" = "t"."name" ` +
1613
1679
  `INNER JOIN "pg_namespace" "n" ON "n"."oid" = "c"."relnamespace" AND "n"."nspname" = "t"."schema" ` +
1614
1680
  `WHERE "t"."type" IN ('${MetadataTableType_1.MetadataTableType.VIEW}', '${MetadataTableType_1.MetadataTableType.MATERIALIZED_VIEW}') ${viewsCondition ? `AND (${viewsCondition})` : ""}`;
1615
1681
  const dbViews = await this.query(query);
1682
+ const dbIndices = await this.query(indicesSql);
1616
1683
  return dbViews.map((dbView) => {
1684
+ // find index constraints of table, group them by constraint name and build TableIndex.
1685
+ const tableIndexConstraints = OrmUtils_1.OrmUtils.uniq(dbIndices.filter((dbIndex) => {
1686
+ return (dbIndex["table_name"] === dbView["name"] &&
1687
+ dbIndex["table_schema"] === dbView["schema"]);
1688
+ }), (dbIndex) => dbIndex["constraint_name"]);
1617
1689
  const view = new View_1.View();
1618
1690
  const schema = dbView["schema"] === currentSchema &&
1619
1691
  !this.driver.options.schema
@@ -1625,6 +1697,22 @@ class PostgresQueryRunner extends BaseQueryRunner_1.BaseQueryRunner {
1625
1697
  view.expression = dbView["value"];
1626
1698
  view.materialized =
1627
1699
  dbView["type"] === MetadataTableType_1.MetadataTableType.MATERIALIZED_VIEW;
1700
+ view.indices = tableIndexConstraints.map((constraint) => {
1701
+ const indices = dbIndices.filter((index) => {
1702
+ return (index["table_schema"] === constraint["table_schema"] &&
1703
+ index["table_name"] === constraint["table_name"] &&
1704
+ index["constraint_name"] ===
1705
+ constraint["constraint_name"]);
1706
+ });
1707
+ return new TableIndex_1.TableIndex({
1708
+ view: view,
1709
+ name: constraint["constraint_name"],
1710
+ columnNames: indices.map((i) => i["column_name"]),
1711
+ isUnique: constraint["is_unique"] === "TRUE",
1712
+ where: constraint["condition"],
1713
+ isFulltext: false,
1714
+ });
1715
+ });
1628
1716
  return view;
1629
1717
  });
1630
1718
  }
@@ -2321,6 +2409,15 @@ class PostgresQueryRunner extends BaseQueryRunner_1.BaseQueryRunner {
2321
2409
  .join(", ");
2322
2410
  return new Query_1.Query(`CREATE ${index.isUnique ? "UNIQUE " : ""}INDEX "${index.name}" ON ${this.escapePath(table)} ${index.isSpatial ? "USING GiST " : ""}(${columns}) ${index.where ? "WHERE " + index.where : ""}`);
2323
2411
  }
2412
+ /**
2413
+ * Builds create view index sql.
2414
+ */
2415
+ createViewIndexSql(view, index) {
2416
+ const columns = index.columnNames
2417
+ .map((columnName) => `"${columnName}"`)
2418
+ .join(", ");
2419
+ return new Query_1.Query(`CREATE ${index.isUnique ? "UNIQUE " : ""}INDEX "${index.name}" ON ${this.escapePath(view)} (${columns}) ${index.where ? "WHERE " + index.where : ""}`);
2420
+ }
2324
2421
  /**
2325
2422
  * Builds drop index sql.
2326
2423
  */