@depup/typeorm 1.1.0-depup.3 → 1.1.2-depup.0

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 (131) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +5 -4
  3. package/browser/cache/DbQueryResultCache.d.ts +1 -1
  4. package/browser/cache/DbQueryResultCache.js +47 -32
  5. package/browser/cache/DbQueryResultCache.js.map +1 -1
  6. package/browser/data-source/DataSource.d.ts +1 -0
  7. package/browser/data-source/DataSource.js +56 -29
  8. package/browser/data-source/DataSource.js.map +1 -1
  9. package/browser/decorator/options/SpatialColumnOptions.d.ts +3 -2
  10. package/browser/decorator/options/SpatialColumnOptions.js.map +1 -1
  11. package/browser/driver/aurora-mysql/AuroraMysqlDriver.js +3 -3
  12. package/browser/driver/aurora-mysql/AuroraMysqlDriver.js.map +1 -1
  13. package/browser/driver/better-sqlite3/BetterSqlite3QueryRunner.js +6 -2
  14. package/browser/driver/better-sqlite3/BetterSqlite3QueryRunner.js.map +1 -1
  15. package/browser/driver/cockroachdb/CockroachDriver.js +19 -14
  16. package/browser/driver/cockroachdb/CockroachDriver.js.map +1 -1
  17. package/browser/driver/cockroachdb/CockroachQueryRunner.js +96 -33
  18. package/browser/driver/cockroachdb/CockroachQueryRunner.js.map +1 -1
  19. package/browser/driver/mysql/MysqlDriver.js +4 -4
  20. package/browser/driver/mysql/MysqlDriver.js.map +1 -1
  21. package/browser/driver/mysql/MysqlQueryRunner.js +132 -84
  22. package/browser/driver/mysql/MysqlQueryRunner.js.map +1 -1
  23. package/browser/driver/oracle/OracleQueryRunner.js +84 -40
  24. package/browser/driver/oracle/OracleQueryRunner.js.map +1 -1
  25. package/browser/driver/postgres/PostgresDriver.js +10 -7
  26. package/browser/driver/postgres/PostgresDriver.js.map +1 -1
  27. package/browser/driver/postgres/PostgresQueryRunner.js +136 -74
  28. package/browser/driver/postgres/PostgresQueryRunner.js.map +1 -1
  29. package/browser/driver/sap/SapQueryRunner.js +24 -20
  30. package/browser/driver/sap/SapQueryRunner.js.map +1 -1
  31. package/browser/driver/spanner/SpannerQueryRunner.js +20 -16
  32. package/browser/driver/spanner/SpannerQueryRunner.js.map +1 -1
  33. package/browser/driver/sqlite-abstract/AbstractSqliteQueryRunner.js +52 -31
  34. package/browser/driver/sqlite-abstract/AbstractSqliteQueryRunner.js.map +1 -1
  35. package/browser/driver/sqljs/SqljsQueryRunner.js +4 -4
  36. package/browser/driver/sqljs/SqljsQueryRunner.js.map +1 -1
  37. package/browser/driver/sqlserver/SqlServerQueryRunner.js +95 -49
  38. package/browser/driver/sqlserver/SqlServerQueryRunner.js.map +1 -1
  39. package/browser/entity-manager/EntityManager.d.ts +6 -0
  40. package/browser/entity-manager/EntityManager.js +6 -0
  41. package/browser/entity-manager/EntityManager.js.map +1 -1
  42. package/browser/index.d.ts +2 -0
  43. package/browser/index.js +4 -1
  44. package/browser/index.js.map +1 -1
  45. package/browser/metadata/ColumnMetadata.js +1 -1
  46. package/browser/metadata/ColumnMetadata.js.map +1 -1
  47. package/browser/metadata-builder/EntityMetadataBuilder.js +5 -2
  48. package/browser/metadata-builder/EntityMetadataBuilder.js.map +1 -1
  49. package/browser/metadata-builder/JunctionEntityMetadataBuilder.js +4 -6
  50. package/browser/metadata-builder/JunctionEntityMetadataBuilder.js.map +1 -1
  51. package/browser/persistence/subject-builder/ManyToManySubjectBuilder.js +3 -0
  52. package/browser/persistence/subject-builder/ManyToManySubjectBuilder.js.map +1 -1
  53. package/browser/persistence/tree/ClosureSubjectExecutor.js +2 -3
  54. package/browser/persistence/tree/ClosureSubjectExecutor.js.map +1 -1
  55. package/browser/query-builder/InsertQueryBuilder.js +15 -13
  56. package/browser/query-builder/InsertQueryBuilder.js.map +1 -1
  57. package/browser/query-builder/SelectQueryBuilder.js +15 -14
  58. package/browser/query-builder/SelectQueryBuilder.js.map +1 -1
  59. package/browser/query-builder/transformer/RawSqlResultsToEntityTransformer.js +17 -7
  60. package/browser/query-builder/transformer/RawSqlResultsToEntityTransformer.js.map +1 -1
  61. package/browser/util/OrmUtils.d.ts +1 -0
  62. package/browser/util/OrmUtils.js +8 -4
  63. package/browser/util/OrmUtils.js.map +1 -1
  64. package/browser/util/VersionUtils.js +6 -3
  65. package/browser/util/VersionUtils.js.map +1 -1
  66. package/cache/DbQueryResultCache.d.ts +1 -1
  67. package/cache/DbQueryResultCache.js +47 -32
  68. package/cache/DbQueryResultCache.js.map +1 -1
  69. package/changes.json +8 -4
  70. package/data-source/DataSource.d.ts +1 -0
  71. package/data-source/DataSource.js +56 -29
  72. package/data-source/DataSource.js.map +1 -1
  73. package/decorator/options/SpatialColumnOptions.d.ts +3 -2
  74. package/decorator/options/SpatialColumnOptions.js.map +1 -1
  75. package/driver/aurora-mysql/AuroraMysqlDriver.js +3 -3
  76. package/driver/aurora-mysql/AuroraMysqlDriver.js.map +1 -1
  77. package/driver/better-sqlite3/BetterSqlite3QueryRunner.js +6 -2
  78. package/driver/better-sqlite3/BetterSqlite3QueryRunner.js.map +1 -1
  79. package/driver/cockroachdb/CockroachDriver.js +19 -14
  80. package/driver/cockroachdb/CockroachDriver.js.map +1 -1
  81. package/driver/cockroachdb/CockroachQueryRunner.js +96 -33
  82. package/driver/cockroachdb/CockroachQueryRunner.js.map +1 -1
  83. package/driver/mysql/MysqlDriver.js +4 -4
  84. package/driver/mysql/MysqlDriver.js.map +1 -1
  85. package/driver/mysql/MysqlQueryRunner.js +132 -84
  86. package/driver/mysql/MysqlQueryRunner.js.map +1 -1
  87. package/driver/oracle/OracleQueryRunner.js +84 -40
  88. package/driver/oracle/OracleQueryRunner.js.map +1 -1
  89. package/driver/postgres/PostgresDriver.js +10 -7
  90. package/driver/postgres/PostgresDriver.js.map +1 -1
  91. package/driver/postgres/PostgresQueryRunner.js +136 -74
  92. package/driver/postgres/PostgresQueryRunner.js.map +1 -1
  93. package/driver/sap/SapQueryRunner.js +24 -20
  94. package/driver/sap/SapQueryRunner.js.map +1 -1
  95. package/driver/spanner/SpannerQueryRunner.js +20 -16
  96. package/driver/spanner/SpannerQueryRunner.js.map +1 -1
  97. package/driver/sqlite-abstract/AbstractSqliteQueryRunner.js +52 -31
  98. package/driver/sqlite-abstract/AbstractSqliteQueryRunner.js.map +1 -1
  99. package/driver/sqljs/SqljsQueryRunner.js +4 -4
  100. package/driver/sqljs/SqljsQueryRunner.js.map +1 -1
  101. package/driver/sqlserver/SqlServerQueryRunner.js +95 -49
  102. package/driver/sqlserver/SqlServerQueryRunner.js.map +1 -1
  103. package/entity-manager/EntityManager.d.ts +6 -0
  104. package/entity-manager/EntityManager.js +6 -0
  105. package/entity-manager/EntityManager.js.map +1 -1
  106. package/index.d.ts +2 -0
  107. package/index.js +4 -1
  108. package/index.js.map +1 -1
  109. package/index.mjs +4 -0
  110. package/metadata/ColumnMetadata.js +1 -1
  111. package/metadata/ColumnMetadata.js.map +1 -1
  112. package/metadata-builder/EntityMetadataBuilder.js +5 -2
  113. package/metadata-builder/EntityMetadataBuilder.js.map +1 -1
  114. package/metadata-builder/JunctionEntityMetadataBuilder.js +4 -6
  115. package/metadata-builder/JunctionEntityMetadataBuilder.js.map +1 -1
  116. package/package.json +13 -9
  117. package/persistence/subject-builder/ManyToManySubjectBuilder.js +3 -0
  118. package/persistence/subject-builder/ManyToManySubjectBuilder.js.map +1 -1
  119. package/persistence/tree/ClosureSubjectExecutor.js +2 -3
  120. package/persistence/tree/ClosureSubjectExecutor.js.map +1 -1
  121. package/query-builder/InsertQueryBuilder.js +15 -13
  122. package/query-builder/InsertQueryBuilder.js.map +1 -1
  123. package/query-builder/SelectQueryBuilder.js +15 -14
  124. package/query-builder/SelectQueryBuilder.js.map +1 -1
  125. package/query-builder/transformer/RawSqlResultsToEntityTransformer.js +17 -7
  126. package/query-builder/transformer/RawSqlResultsToEntityTransformer.js.map +1 -1
  127. package/util/OrmUtils.d.ts +1 -0
  128. package/util/OrmUtils.js +8 -4
  129. package/util/OrmUtils.js.map +1 -1
  130. package/util/VersionUtils.js +6 -3
  131. package/util/VersionUtils.js.map +1 -1
@@ -112,41 +112,48 @@ class DbQueryResultCache {
112
112
  * @param options
113
113
  * @param queryRunner
114
114
  */
115
- getFromCache(options, queryRunner) {
116
- queryRunner = this.getQueryRunner(queryRunner);
117
- const qb = this.dataSource
118
- .createQueryBuilder(queryRunner)
119
- .select()
120
- .from(this.queryResultCacheTable, "cache");
121
- if (options.identifier) {
122
- return qb
123
- .where(`${qb.escape("cache")}.${qb.escape("identifier")} = :identifier`)
124
- .setParameters({
125
- identifier: this.dataSource.driver.options.type === "mssql"
126
- ? new MssqlParameter_1.MssqlParameter(options.identifier, "nvarchar")
127
- : options.identifier,
128
- })
129
- .cache(false) // disable cache to avoid infinite loops when cache is alwaysEnable
130
- .getRawOne();
131
- }
132
- else if (options.query) {
133
- if (this.dataSource.driver.options.type === "oracle") {
134
- return qb
135
- .where(`dbms_lob.compare(${qb.escape("cache")}.${qb.escape("query")}, :query) = 0`, { query: options.query })
115
+ async getFromCache(options, queryRunner) {
116
+ const _queryRunner = queryRunner ?? this.getQueryRunner();
117
+ try {
118
+ const qb = this.dataSource
119
+ .createQueryBuilder(_queryRunner)
120
+ .select()
121
+ .from(this.queryResultCacheTable, "cache");
122
+ if (options.identifier) {
123
+ return await qb
124
+ .where(`${qb.escape("cache")}.${qb.escape("identifier")} = :identifier`)
125
+ .setParameters({
126
+ identifier: this.dataSource.driver.options.type === "mssql"
127
+ ? new MssqlParameter_1.MssqlParameter(options.identifier, "nvarchar")
128
+ : options.identifier,
129
+ })
136
130
  .cache(false) // disable cache to avoid infinite loops when cache is alwaysEnable
137
131
  .getRawOne();
138
132
  }
139
- return qb
140
- .where(`${qb.escape("cache")}.${qb.escape("query")} = :query`)
141
- .setParameters({
142
- query: this.dataSource.driver.options.type === "mssql"
143
- ? new MssqlParameter_1.MssqlParameter(options.query, "nvarchar")
144
- : options.query,
145
- })
146
- .cache(false) // disable cache to avoid infinite loops when cache is alwaysEnable
147
- .getRawOne();
133
+ else if (options.query) {
134
+ if (this.dataSource.driver.options.type === "oracle") {
135
+ return await qb
136
+ .where(`dbms_lob.compare(${qb.escape("cache")}.${qb.escape("query")}, :query) = 0`, { query: options.query })
137
+ .cache(false) // disable cache to avoid infinite loops when cache is alwaysEnable
138
+ .getRawOne();
139
+ }
140
+ return await qb
141
+ .where(`${qb.escape("cache")}.${qb.escape("query")} = :query`)
142
+ .setParameters({
143
+ query: this.dataSource.driver.options.type === "mssql"
144
+ ? new MssqlParameter_1.MssqlParameter(options.query, "nvarchar")
145
+ : options.query,
146
+ })
147
+ .cache(false) // disable cache to avoid infinite loops when cache is alwaysEnable
148
+ .getRawOne();
149
+ }
150
+ return undefined;
151
+ }
152
+ finally {
153
+ if (!queryRunner) {
154
+ await _queryRunner.release();
155
+ }
148
156
  }
149
- return Promise.resolve(undefined);
150
157
  }
151
158
  /**
152
159
  * Checks if cache is expired or not.
@@ -244,7 +251,15 @@ class DbQueryResultCache {
244
251
  * @param queryRunner
245
252
  */
246
253
  async clear(queryRunner) {
247
- return this.getQueryRunner(queryRunner).clearTable(this.queryResultCacheTable);
254
+ const _queryRunner = queryRunner ?? this.getQueryRunner();
255
+ try {
256
+ return await _queryRunner.clearTable(this.queryResultCacheTable);
257
+ }
258
+ finally {
259
+ if (!queryRunner) {
260
+ await _queryRunner.release();
261
+ }
262
+ }
248
263
  }
249
264
  /**
250
265
  * Removes all cached results by given identifiers from cache.
@@ -1 +1 @@
1
- {"version":3,"file":"DbQueryResultCache.js","sourceRoot":"","sources":["../../../src/cache/DbQueryResultCache.ts"],"names":[],"mappings":";;;AAEA,uEAAmE;AAEnE,yDAAqD;AACrD,6DAAyD;AAIzD;;GAEG;AACH,MAAa,kBAAkB;IAW3B,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YAAsB,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;QACxC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,OAAc,C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;QAEzB,MAAM,YAAY,GAAgB,WAAW,IAAI,IAAI,CAAC,cAAc,EAAE,CAAA;QACtE,MAAM,OAAO,CAAC,GAAG,CACb,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE;YAC3B,MAAM,EAAE,GAAG,YAAY,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAA;YACpD,OAAO,EAAE;iBACJ,MAAM,EAAE;iBACR,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAAC;iBAChC,KAAK,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,gBAAgB,EAAE;gBAC/C,UAAU;aACb,CAAC;iBACD,OAAO,EAAE,CAAA;QAClB,CAAC,CAAC,CACL,CAAA;QAED,IAAI,CAAC,WAAW,EAAE,CAAC;YACf,MAAM,YAAY,CAAC,OAAO,EAAE,CAAA;QAChC,CAAC;IACL,CAAC;IAED,4EAA4E;IAC5E,oBAAoB;IACpB,4EAA4E;IAE5E;;;;OAIG;IACO,cAAc,CAAC,WAAyB;QAC9C,IAAI,WAAW;YAAE,OAAO,WAAW,CAAA;QAEnC,OAAO,IAAI,CAAC,UAAU,CAAC,iBAAiB,EAAE,CAAA;IAC9C,CAAC;CACJ;AAxVD,gDAwVC","sourcesContent":["import type { ObjectLiteral } from \"../common/ObjectLiteral\"\nimport type { DataSource } from \"../data-source/DataSource\"\nimport { MssqlParameter } from \"../driver/sqlserver/MssqlParameter\"\nimport type { QueryRunner } from \"../query-runner/QueryRunner\"\nimport { Table } from \"../schema-builder/table/Table\"\nimport { RandomGenerator } from \"../util/RandomGenerator\"\nimport type { QueryResultCache } from \"./QueryResultCache\"\nimport type { QueryResultCacheOptions } from \"./QueryResultCacheOptions\"\n\n/**\n * Caches query result into current database, into separate table called \"query-result-cache\".\n */\nexport class DbQueryResultCache implements QueryResultCache {\n // -------------------------------------------------------------------------\n // Private properties\n // -------------------------------------------------------------------------\n\n private queryResultCacheTable: string\n\n private queryResultCacheDatabase?: string\n\n private queryResultCacheSchema?: string\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(protected dataSource: DataSource) {\n const { schema } = this.dataSource.driver.options as any\n const database = this.dataSource.driver.database\n const cacheOptions =\n typeof this.dataSource.options.cache === \"object\"\n ? this.dataSource.options.cache\n : {}\n const tableName =\n cacheOptions.tableName === \"\" ? undefined : cacheOptions.tableName\n const cacheTableName = tableName ?? \"query-result-cache\"\n\n this.queryResultCacheDatabase = database\n this.queryResultCacheSchema = schema\n this.queryResultCacheTable = this.dataSource.driver.buildTableName(\n cacheTableName,\n schema,\n database,\n )\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates a connection with given cache provider.\n */\n async connect(): Promise<void> {}\n\n /**\n * Disconnects with given cache provider.\n */\n async disconnect(): Promise<void> {}\n\n /**\n * Creates table for storing cache if it does not exist yet.\n *\n * @param queryRunner\n */\n async synchronize(queryRunner?: QueryRunner): Promise<void> {\n queryRunner = this.getQueryRunner(queryRunner)\n const driver = this.dataSource.driver\n const tableExist = await queryRunner.hasTable(\n this.queryResultCacheTable,\n ) // todo: table name should be configurable\n if (tableExist) return\n\n await queryRunner.createTable(\n new Table({\n database: this.queryResultCacheDatabase,\n schema: this.queryResultCacheSchema,\n name: this.queryResultCacheTable,\n columns: [\n {\n name: \"id\",\n isPrimary: true,\n isNullable: false,\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheId,\n }),\n generationStrategy:\n driver.options.type === \"spanner\"\n ? \"uuid\"\n : \"increment\",\n isGenerated: true,\n },\n {\n name: \"identifier\",\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheIdentifier,\n }),\n isNullable: true,\n },\n {\n name: \"time\",\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheTime,\n }),\n isPrimary: false,\n isNullable: false,\n },\n {\n name: \"duration\",\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheDuration,\n }),\n isPrimary: false,\n isNullable: false,\n },\n {\n name: \"query\",\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheQuery,\n }),\n isPrimary: false,\n isNullable: false,\n },\n {\n name: \"result\",\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheResult,\n }),\n isNullable: false,\n },\n ],\n }),\n )\n }\n\n /**\n * Get data from cache.\n * Returns cache result if found.\n * Returns undefined if result is not cached.\n *\n * @param options\n * @param queryRunner\n */\n getFromCache(\n options: QueryResultCacheOptions,\n queryRunner?: QueryRunner,\n ): Promise<QueryResultCacheOptions | undefined> {\n queryRunner = this.getQueryRunner(queryRunner)\n const qb = this.dataSource\n .createQueryBuilder(queryRunner)\n .select()\n .from(this.queryResultCacheTable, \"cache\")\n\n if (options.identifier) {\n return qb\n .where(\n `${qb.escape(\"cache\")}.${qb.escape(\n \"identifier\",\n )} = :identifier`,\n )\n .setParameters({\n identifier:\n this.dataSource.driver.options.type === \"mssql\"\n ? new MssqlParameter(options.identifier, \"nvarchar\")\n : options.identifier,\n })\n .cache(false) // disable cache to avoid infinite loops when cache is alwaysEnable\n .getRawOne()\n } else if (options.query) {\n if (this.dataSource.driver.options.type === \"oracle\") {\n return qb\n .where(\n `dbms_lob.compare(${qb.escape(\"cache\")}.${qb.escape(\n \"query\",\n )}, :query) = 0`,\n { query: options.query },\n )\n .cache(false) // disable cache to avoid infinite loops when cache is alwaysEnable\n .getRawOne()\n }\n\n return qb\n .where(`${qb.escape(\"cache\")}.${qb.escape(\"query\")} = :query`)\n .setParameters({\n query:\n this.dataSource.driver.options.type === \"mssql\"\n ? new MssqlParameter(options.query, \"nvarchar\")\n : options.query,\n })\n .cache(false) // disable cache to avoid infinite loops when cache is alwaysEnable\n .getRawOne()\n }\n\n return Promise.resolve(undefined)\n }\n\n /**\n * Checks if cache is expired or not.\n *\n * @param savedCache\n */\n isExpired(savedCache: QueryResultCacheOptions): boolean {\n const duration =\n typeof savedCache.duration === \"string\"\n ? parseInt(savedCache.duration)\n : savedCache.duration\n return (\n (typeof savedCache.time === \"string\"\n ? parseInt(savedCache.time as any)\n : savedCache.time)! +\n duration <\n Date.now()\n )\n }\n\n /**\n * Stores given query result in the cache.\n *\n * @param options\n * @param savedCache\n * @param queryRunner\n */\n async storeInCache(\n options: QueryResultCacheOptions,\n savedCache: QueryResultCacheOptions | undefined,\n queryRunner?: QueryRunner,\n ): Promise<void> {\n const shouldCreateQueryRunner =\n queryRunner === undefined ||\n queryRunner?.getReplicationMode() === \"slave\"\n\n if (queryRunner === undefined || shouldCreateQueryRunner) {\n queryRunner = this.dataSource.createQueryRunner(\"master\")\n }\n\n let insertedValues: ObjectLiteral = options\n if (this.dataSource.driver.options.type === \"mssql\") {\n // todo: bad abstraction, re-implement this part, probably better if we create an entity metadata for cache table\n insertedValues = {\n identifier: new MssqlParameter(options.identifier, \"nvarchar\"),\n time: new MssqlParameter(options.time, \"bigint\"),\n duration: new MssqlParameter(options.duration, \"int\"),\n query: new MssqlParameter(options.query, \"nvarchar\"),\n result: new MssqlParameter(options.result, \"nvarchar\"),\n }\n }\n\n try {\n if (savedCache?.identifier) {\n // if exist then update\n const qb = queryRunner.manager\n .createQueryBuilder()\n .update(this.queryResultCacheTable)\n .set(insertedValues)\n\n qb.where(`${qb.escape(\"identifier\")} = :condition`, {\n condition: insertedValues.identifier,\n })\n await qb.execute()\n } else if (savedCache?.query) {\n // if exist then update\n const qb = queryRunner.manager\n .createQueryBuilder()\n .update(this.queryResultCacheTable)\n .set(insertedValues)\n\n if (this.dataSource.driver.options.type === \"oracle\") {\n qb.where(`dbms_lob.compare(\"query\", :condition) = 0`, {\n condition: insertedValues.query,\n })\n } else {\n qb.where(`${qb.escape(\"query\")} = :condition`, {\n condition: insertedValues.query,\n })\n }\n\n await qb.execute()\n } else {\n // Spanner does not support auto-generated columns\n if (\n this.dataSource.driver.options.type === \"spanner\" &&\n !insertedValues.id\n ) {\n insertedValues.id = RandomGenerator.uuidv4()\n }\n\n // otherwise insert\n await queryRunner.manager\n .createQueryBuilder()\n .insert()\n .into(this.queryResultCacheTable)\n .values(insertedValues)\n .execute()\n }\n } finally {\n if (shouldCreateQueryRunner) {\n await queryRunner.release()\n }\n }\n }\n\n /**\n * Clears everything stored in the cache.\n *\n * @param queryRunner\n */\n async clear(queryRunner: QueryRunner): Promise<void> {\n return this.getQueryRunner(queryRunner).clearTable(\n this.queryResultCacheTable,\n )\n }\n\n /**\n * Removes all cached results by given identifiers from cache.\n *\n * @param identifiers\n * @param queryRunner\n */\n async remove(\n identifiers: string[],\n queryRunner?: QueryRunner,\n ): Promise<void> {\n const _queryRunner: QueryRunner = queryRunner ?? this.getQueryRunner()\n await Promise.all(\n identifiers.map((identifier) => {\n const qb = _queryRunner.manager.createQueryBuilder()\n return qb\n .delete()\n .from(this.queryResultCacheTable)\n .where(`${qb.escape(\"identifier\")} = :identifier`, {\n identifier,\n })\n .execute()\n }),\n )\n\n if (!queryRunner) {\n await _queryRunner.release()\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Gets a query runner to work with.\n *\n * @param queryRunner\n */\n protected getQueryRunner(queryRunner?: QueryRunner): QueryRunner {\n if (queryRunner) return queryRunner\n\n return this.dataSource.createQueryRunner()\n }\n}\n"]}
1
+ {"version":3,"file":"DbQueryResultCache.js","sourceRoot":"","sources":["../../../src/cache/DbQueryResultCache.ts"],"names":[],"mappings":";;;AAEA,uEAAmE;AAEnE,yDAAqD;AACrD,6DAAyD;AAIzD;;GAEG;AACH,MAAa,kBAAkB;IAW3B,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YAAsB,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;QACxC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,OAAc,CAAA;QACxD,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAA;QAChD,MAAM,YAAY,GACd,OAAO,IAAI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AAqB,CAAC,CAAA;QACpE,CAAC;gBAAS,CAAC;YACP,IAAI,CAAC,WAAW,EAAE,CAAC;gBACf,MAAM,YAAY,CAAC,OAAO,EAAE,CAAA;YAChC,CAAC;QACL,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,MAAM,CACR,WAAqB,EACrB,WAAyB;QAEzB,MAAM,YAAY,GAAgB,WAAW,IAAI,IAAI,CAAC,cAAc,EAAE,CAAA;QACtE,MAAM,OAAO,CAAC,GAAG,CACb,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE;YAC3B,MAAM,EAAE,GAAG,YAAY,CAAC,OAAO,CAAC,kBAAkB,EAAE,CAAA;YACpD,OAAO,EAAE;iBACJ,MAAM,EAAE;iBACR,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAAC;iBAChC,KAAK,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,gBAAgB,EAAE;gBAC/C,UAAU;aACb,CAAC;iBACD,OAAO,EAAE,CAAA;QAClB,CAAC,CAAC,CACL,CAAA;QAED,IAAI,CAAC,WAAW,EAAE,CAAC;YACf,MAAM,YAAY,CAAC,OAAO,EAAE,CAAA;QAChC,CAAC;IACL,CAAC;IAED,4EAA4E;IAC5E,oBAAoB;IACpB,4EAA4E;IAE5E;;;;OAIG;IACO,cAAc,CAAC,WAAyB;QAC9C,IAAI,WAAW;YAAE,OAAO,WAAW,CAAA;QAEnC,OAAO,IAAI,CAAC,UAAU,CAAC,iBAAiB,EAAE,CAAA;IAC9C,CAAC;CACJ;AAxWD,gDAwWC","sourcesContent":["import type { ObjectLiteral } from \"../common/ObjectLiteral\"\nimport type { DataSource } from \"../data-source/DataSource\"\nimport { MssqlParameter } from \"../driver/sqlserver/MssqlParameter\"\nimport type { QueryRunner } from \"../query-runner/QueryRunner\"\nimport { Table } from \"../schema-builder/table/Table\"\nimport { RandomGenerator } from \"../util/RandomGenerator\"\nimport type { QueryResultCache } from \"./QueryResultCache\"\nimport type { QueryResultCacheOptions } from \"./QueryResultCacheOptions\"\n\n/**\n * Caches query result into current database, into separate table called \"query-result-cache\".\n */\nexport class DbQueryResultCache implements QueryResultCache {\n // -------------------------------------------------------------------------\n // Private properties\n // -------------------------------------------------------------------------\n\n private queryResultCacheTable: string\n\n private queryResultCacheDatabase?: string\n\n private queryResultCacheSchema?: string\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(protected dataSource: DataSource) {\n const { schema } = this.dataSource.driver.options as any\n const database = this.dataSource.driver.database\n const cacheOptions =\n typeof this.dataSource.options.cache === \"object\"\n ? this.dataSource.options.cache\n : {}\n const tableName =\n cacheOptions.tableName === \"\" ? undefined : cacheOptions.tableName\n const cacheTableName = tableName ?? \"query-result-cache\"\n\n this.queryResultCacheDatabase = database\n this.queryResultCacheSchema = schema\n this.queryResultCacheTable = this.dataSource.driver.buildTableName(\n cacheTableName,\n schema,\n database,\n )\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Creates a connection with given cache provider.\n */\n async connect(): Promise<void> {}\n\n /**\n * Disconnects with given cache provider.\n */\n async disconnect(): Promise<void> {}\n\n /**\n * Creates table for storing cache if it does not exist yet.\n *\n * @param queryRunner\n */\n async synchronize(queryRunner?: QueryRunner): Promise<void> {\n queryRunner = this.getQueryRunner(queryRunner)\n const driver = this.dataSource.driver\n const tableExist = await queryRunner.hasTable(\n this.queryResultCacheTable,\n ) // todo: table name should be configurable\n if (tableExist) return\n\n await queryRunner.createTable(\n new Table({\n database: this.queryResultCacheDatabase,\n schema: this.queryResultCacheSchema,\n name: this.queryResultCacheTable,\n columns: [\n {\n name: \"id\",\n isPrimary: true,\n isNullable: false,\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheId,\n }),\n generationStrategy:\n driver.options.type === \"spanner\"\n ? \"uuid\"\n : \"increment\",\n isGenerated: true,\n },\n {\n name: \"identifier\",\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheIdentifier,\n }),\n isNullable: true,\n },\n {\n name: \"time\",\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheTime,\n }),\n isPrimary: false,\n isNullable: false,\n },\n {\n name: \"duration\",\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheDuration,\n }),\n isPrimary: false,\n isNullable: false,\n },\n {\n name: \"query\",\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheQuery,\n }),\n isPrimary: false,\n isNullable: false,\n },\n {\n name: \"result\",\n type: driver.normalizeType({\n type: driver.mappedDataTypes.cacheResult,\n }),\n isNullable: false,\n },\n ],\n }),\n )\n }\n\n /**\n * Get data from cache.\n * Returns cache result if found.\n * Returns undefined if result is not cached.\n *\n * @param options\n * @param queryRunner\n */\n async getFromCache(\n options: QueryResultCacheOptions,\n queryRunner?: QueryRunner,\n ): Promise<QueryResultCacheOptions | undefined> {\n const _queryRunner: QueryRunner = queryRunner ?? this.getQueryRunner()\n try {\n const qb = this.dataSource\n .createQueryBuilder(_queryRunner)\n .select()\n .from(this.queryResultCacheTable, \"cache\")\n\n if (options.identifier) {\n return await qb\n .where(\n `${qb.escape(\"cache\")}.${qb.escape(\n \"identifier\",\n )} = :identifier`,\n )\n .setParameters({\n identifier:\n this.dataSource.driver.options.type === \"mssql\"\n ? new MssqlParameter(\n options.identifier,\n \"nvarchar\",\n )\n : options.identifier,\n })\n .cache(false) // disable cache to avoid infinite loops when cache is alwaysEnable\n .getRawOne()\n } else if (options.query) {\n if (this.dataSource.driver.options.type === \"oracle\") {\n return await qb\n .where(\n `dbms_lob.compare(${qb.escape(\"cache\")}.${qb.escape(\n \"query\",\n )}, :query) = 0`,\n { query: options.query },\n )\n .cache(false) // disable cache to avoid infinite loops when cache is alwaysEnable\n .getRawOne()\n }\n\n return await qb\n .where(\n `${qb.escape(\"cache\")}.${qb.escape(\"query\")} = :query`,\n )\n .setParameters({\n query:\n this.dataSource.driver.options.type === \"mssql\"\n ? new MssqlParameter(options.query, \"nvarchar\")\n : options.query,\n })\n .cache(false) // disable cache to avoid infinite loops when cache is alwaysEnable\n .getRawOne()\n }\n\n return undefined\n } finally {\n if (!queryRunner) {\n await _queryRunner.release()\n }\n }\n }\n\n /**\n * Checks if cache is expired or not.\n *\n * @param savedCache\n */\n isExpired(savedCache: QueryResultCacheOptions): boolean {\n const duration =\n typeof savedCache.duration === \"string\"\n ? parseInt(savedCache.duration)\n : savedCache.duration\n return (\n (typeof savedCache.time === \"string\"\n ? parseInt(savedCache.time as any)\n : savedCache.time)! +\n duration <\n Date.now()\n )\n }\n\n /**\n * Stores given query result in the cache.\n *\n * @param options\n * @param savedCache\n * @param queryRunner\n */\n async storeInCache(\n options: QueryResultCacheOptions,\n savedCache: QueryResultCacheOptions | undefined,\n queryRunner?: QueryRunner,\n ): Promise<void> {\n const shouldCreateQueryRunner =\n queryRunner === undefined ||\n queryRunner?.getReplicationMode() === \"slave\"\n\n if (queryRunner === undefined || shouldCreateQueryRunner) {\n queryRunner = this.dataSource.createQueryRunner(\"master\")\n }\n\n let insertedValues: ObjectLiteral = options\n if (this.dataSource.driver.options.type === \"mssql\") {\n // todo: bad abstraction, re-implement this part, probably better if we create an entity metadata for cache table\n insertedValues = {\n identifier: new MssqlParameter(options.identifier, \"nvarchar\"),\n time: new MssqlParameter(options.time, \"bigint\"),\n duration: new MssqlParameter(options.duration, \"int\"),\n query: new MssqlParameter(options.query, \"nvarchar\"),\n result: new MssqlParameter(options.result, \"nvarchar\"),\n }\n }\n\n try {\n if (savedCache?.identifier) {\n // if exist then update\n const qb = queryRunner.manager\n .createQueryBuilder()\n .update(this.queryResultCacheTable)\n .set(insertedValues)\n\n qb.where(`${qb.escape(\"identifier\")} = :condition`, {\n condition: insertedValues.identifier,\n })\n await qb.execute()\n } else if (savedCache?.query) {\n // if exist then update\n const qb = queryRunner.manager\n .createQueryBuilder()\n .update(this.queryResultCacheTable)\n .set(insertedValues)\n\n if (this.dataSource.driver.options.type === \"oracle\") {\n qb.where(`dbms_lob.compare(\"query\", :condition) = 0`, {\n condition: insertedValues.query,\n })\n } else {\n qb.where(`${qb.escape(\"query\")} = :condition`, {\n condition: insertedValues.query,\n })\n }\n\n await qb.execute()\n } else {\n // Spanner does not support auto-generated columns\n if (\n this.dataSource.driver.options.type === \"spanner\" &&\n !insertedValues.id\n ) {\n insertedValues.id = RandomGenerator.uuidv4()\n }\n\n // otherwise insert\n await queryRunner.manager\n .createQueryBuilder()\n .insert()\n .into(this.queryResultCacheTable)\n .values(insertedValues)\n .execute()\n }\n } finally {\n if (shouldCreateQueryRunner) {\n await queryRunner.release()\n }\n }\n }\n\n /**\n * Clears everything stored in the cache.\n *\n * @param queryRunner\n */\n async clear(queryRunner?: QueryRunner): Promise<void> {\n const _queryRunner: QueryRunner = queryRunner ?? this.getQueryRunner()\n try {\n return await _queryRunner.clearTable(this.queryResultCacheTable)\n } finally {\n if (!queryRunner) {\n await _queryRunner.release()\n }\n }\n }\n\n /**\n * Removes all cached results by given identifiers from cache.\n *\n * @param identifiers\n * @param queryRunner\n */\n async remove(\n identifiers: string[],\n queryRunner?: QueryRunner,\n ): Promise<void> {\n const _queryRunner: QueryRunner = queryRunner ?? this.getQueryRunner()\n await Promise.all(\n identifiers.map((identifier) => {\n const qb = _queryRunner.manager.createQueryBuilder()\n return qb\n .delete()\n .from(this.queryResultCacheTable)\n .where(`${qb.escape(\"identifier\")} = :identifier`, {\n identifier,\n })\n .execute()\n }),\n )\n\n if (!queryRunner) {\n await _queryRunner.release()\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Gets a query runner to work with.\n *\n * @param queryRunner\n */\n protected getQueryRunner(queryRunner?: QueryRunner): QueryRunner {\n if (queryRunner) return queryRunner\n\n return this.dataSource.createQueryRunner()\n }\n}\n"]}
package/changes.json CHANGED
@@ -1,10 +1,14 @@
1
1
  {
2
2
  "bumped": {
3
+ "ansis": {
4
+ "from": "^4.3.1",
5
+ "to": "^4.4.0"
6
+ },
3
7
  "yargs": {
4
- "from": "^18.0.0",
5
- "to": "^18.1.0"
8
+ "from": "^18.1.0",
9
+ "to": "^18.2.0"
6
10
  }
7
11
  },
8
- "timestamp": "2026-08-02T01:00:50.462Z",
9
- "totalUpdated": 1
12
+ "timestamp": "2026-10-09T15:09:34.601Z",
13
+ "totalUpdated": 2
10
14
  }
@@ -85,6 +85,7 @@ export declare class DataSource {
85
85
  */
86
86
  readonly relationLoader: RelationLoader;
87
87
  readonly relationIdLoader: RelationIdLoader;
88
+ private isInitializing;
88
89
  constructor(options: DataSourceOptions);
89
90
  /**
90
91
  * Gets the mongodb entity manager that allows to perform mongodb-specific repository operations
@@ -51,6 +51,7 @@ class DataSource {
51
51
  * This is a copy of #.entityMetadatas property -> used for more performant searches.
52
52
  */
53
53
  this.entityMetadatasMap = new Map();
54
+ this.isInitializing = false;
54
55
  (0, query_builder_1.registerQueryBuilders)();
55
56
  this.options = options;
56
57
  this.logger = new LoggerFactory_1.LoggerFactory().create(this.options.logger, this.options.logging);
@@ -129,38 +130,64 @@ class DataSource {
129
130
  * but it also can setup a connection pool with database to use.
130
131
  */
131
132
  async initialize() {
132
- if (this.isInitialized)
133
+ if (this.isInitialized || this.isInitializing)
133
134
  throw new error_1.CannotConnectAlreadyConnectedError();
134
- // validate isolationLevel before connecting
135
- (0, validate_isolation_level_1.validateIsolationLevel)(this.driver.supportedIsolationLevels, this.options.isolationLevel);
136
- // connect to the database via its driver
137
- await this.driver.connect();
138
- // connect to the cache-specific database if cache is enabled
139
- if (this.queryResultCache)
140
- await this.queryResultCache.connect();
141
- // set connected status for the current connection
142
- ObjectUtils_1.ObjectUtils.assign(this, { isInitialized: true });
135
+ this.isInitializing = true;
143
136
  try {
144
- // build all metadatas registered in the current connection
145
- await this.buildMetadatas();
146
- await this.driver.afterConnect();
147
- // if option is set - drop schema once connection is done
148
- if (this.options.dropSchema)
149
- await this.dropDatabase();
150
- // if option is set - automatically synchronize a schema
151
- if (this.options.migrationsRun)
152
- await this.runMigrations({
153
- transaction: this.options.migrationsTransactionMode,
154
- });
155
- // if option is set - automatically synchronize a schema
156
- if (this.options.synchronize)
157
- await this.synchronize();
137
+ // validate isolationLevel before connecting
138
+ (0, validate_isolation_level_1.validateIsolationLevel)(this.driver.supportedIsolationLevels, this.options.isolationLevel);
139
+ // connect to the database via its driver
140
+ await this.driver.connect();
141
+ try {
142
+ // connect to the cache-specific database if cache is enabled
143
+ if (this.queryResultCache)
144
+ await this.queryResultCache.connect();
145
+ // set connected status for the current connection
146
+ ObjectUtils_1.ObjectUtils.assign(this, { isInitialized: true });
147
+ // build all metadatas registered in the current connection
148
+ await this.buildMetadatas();
149
+ await this.driver.afterConnect();
150
+ // if option is set - drop schema once connection is done
151
+ if (this.options.dropSchema)
152
+ await this.dropDatabase();
153
+ // if option is set - automatically synchronize a schema
154
+ if (this.options.migrationsRun)
155
+ await this.runMigrations({
156
+ transaction: this.options.migrationsTransactionMode,
157
+ });
158
+ // if option is set - automatically synchronize a schema
159
+ if (this.options.synchronize)
160
+ await this.synchronize();
161
+ }
162
+ catch (error) {
163
+ // if for some reason build metadata fail (for example validation error during entity metadata check)
164
+ // connection needs to be closed
165
+ if (this.isInitialized) {
166
+ await this.destroy();
167
+ }
168
+ else {
169
+ // clean up whatever partially connected, without letting
170
+ // a cleanup failure mask the original error
171
+ if (this.queryResultCache) {
172
+ try {
173
+ await this.queryResultCache.disconnect();
174
+ }
175
+ catch {
176
+ // ignore
177
+ }
178
+ }
179
+ try {
180
+ await this.driver.disconnect();
181
+ }
182
+ catch {
183
+ // ignore
184
+ }
185
+ }
186
+ throw error;
187
+ }
158
188
  }
159
- catch (error) {
160
- // if for some reason build metadata fail (for example validation error during entity metadata check)
161
- // connection needs to be closed
162
- await this.destroy();
163
- throw error;
189
+ finally {
190
+ this.isInitializing = false;
164
191
  }
165
192
  return this;
166
193
  }
@@ -1 +1 @@
1
- {"version":3,"file":"DataSource.js","sourceRoot":"","sources":["../../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AC,uBAAuB,CAAC,cAAc,CAAC,MAAM,CAAC,EAChE,CAAC;gBACC,cAAc,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAA;YAC7C,CAAC;QACL,CAAC;IACL,CAAC;IAED;;OAEG;IACH,8BAA8B;QAC1B,IACI,aAAa,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO;YACpC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,EACjC,CAAC;YACC,MAAM,KAAK,GACP,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,WAGvB,CAAC,WAAW,CAAA;YACb,IAAI,KAAK,EAAE,CAAC;gBACR,OAAO,KAAK,CAAA;YAChB,CAAC;QACL,CAAC;QACD,OAAO,OAAO,CAAA;IAClB,CAAC;CACJ;AA3tBD,gCA2tBC","sourcesContent":["import type { Driver } from \"../driver/Driver\"\nimport { registerQueryBuilders } from \"../query-builder\"\nimport type { Repository } from \"../repository/Repository\"\nimport type { EntitySubscriberInterface } from \"../subscriber/EntitySubscriberInterface\"\nimport type { EntityTarget } from \"../common/EntityTarget\"\nimport type { EntityManager } from \"../entity-manager/EntityManager\"\nimport { DefaultNamingStrategy } from \"../naming-strategy/DefaultNamingStrategy\"\nimport {\n CannotConnectAlreadyConnectedError,\n CannotExecuteNotConnectedError,\n EntityMetadataNotFoundError,\n QueryRunnerProviderAlreadyReleasedError,\n TypeORMError,\n} from \"../error\"\nimport type { TreeRepository } from \"../repository/TreeRepository\"\nimport type { NamingStrategyInterface } from \"../naming-strategy/NamingStrategyInterface\"\nimport type { EntityMetadata } from \"../metadata/EntityMetadata\"\nimport type { Logger } from \"../logger/Logger\"\nimport type { MigrationInterface } from \"../migration/MigrationInterface\"\nimport { MigrationExecutor } from \"../migration/MigrationExecutor\"\nimport type { Migration } from \"../migration/Migration\"\nimport type { MongoRepository } from \"../repository/MongoRepository\"\nimport type { MongoEntityManager } from \"../entity-manager/MongoEntityManager\"\nimport { EntityMetadataValidator } from \"../metadata-builder/EntityMetadataValidator\"\nimport type { DataSourceOptions } from \"./DataSourceOptions\"\nimport { EntityManagerFactory } from \"../entity-manager/EntityManagerFactory\"\nimport { DriverFactory } from \"../driver/DriverFactory\"\nimport { ConnectionMetadataBuilder } from \"../connection/ConnectionMetadataBuilder\"\nimport type { QueryRunner } from \"../query-runner/QueryRunner\"\nimport { SelectQueryBuilder } from \"../query-builder/SelectQueryBuilder\"\nimport { LoggerFactory } from \"../logger/LoggerFactory\"\nimport { QueryResultCacheFactory } from \"../cache/QueryResultCacheFactory\"\nimport type { QueryResultCache } from \"../cache/QueryResultCache\"\nimport type { SqljsEntityManager } from \"../entity-manager/SqljsEntityManager\"\nimport { RelationLoader } from \"../query-builder/RelationLoader\"\nimport { ObjectUtils } from \"../util/ObjectUtils\"\nimport type { IsolationLevel } from \"../driver/types/IsolationLevel\"\nimport { validateIsolationLevel } from \"../driver/validate-isolation-level\"\nimport type { ReplicationMode } from \"../driver/types/ReplicationMode\"\nimport { RelationIdLoader } from \"../query-builder/RelationIdLoader\"\nimport { DriverUtils } from \"../driver/DriverUtils\"\nimport { InstanceChecker } from \"../util/InstanceChecker\"\nimport type { ObjectLiteral } from \"../common/ObjectLiteral\"\nimport { buildSqlTag } from \"../util/SqlTagUtils\"\n\nregisterQueryBuilders()\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 * DataSource options.\n */\n readonly options: DataSourceOptions\n\n /**\n * Indicates if the 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 * All entity metadatas that are registered for this connection.\n * This is a copy of #.entityMetadatas property -> used for more performant searches.\n */\n readonly entityMetadatasMap = new Map<EntityTarget<any>, 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 registerQueryBuilders()\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 * 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 * @returns the mongodb entity manager\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 * @returns an sqljs specific Entity Manager\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 * @param 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 // todo: we must update the database in the driver as well, if it was set by setOptions method\n // in the future we need to refactor the code and remove \"database\" from the driver, and instead\n // use database (and options) from a single place - data source.\n if (options.database) {\n this.driver.database = DriverUtils.buildDriverOptions(\n this.options,\n ).database\n }\n\n // todo: need to take a look if we need to update schema and other \"poor\" properties\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) throw new CannotConnectAlreadyConnectedError()\n\n // validate isolationLevel before connecting\n validateIsolationLevel(\n this.driver.supportedIsolationLevels,\n this.options.isolationLevel,\n )\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.destroy()\n throw error\n }\n\n return this\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) throw new CannotExecuteNotConnectedError()\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 * 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) throw new CannotExecuteNotConnectedError()\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 * @param options\n * @param options.transaction\n * @param options.fake\n */\n async runMigrations(options?: {\n transaction?: \"all\" | \"none\" | \"each\"\n fake?: boolean\n }): Promise<Migration[]> {\n if (!this.isInitialized) throw new CannotExecuteNotConnectedError()\n\n const migrationExecutor = new MigrationExecutor(this)\n migrationExecutor.transaction =\n options?.transaction ??\n this.options?.migrationsTransactionMode ??\n \"all\"\n migrationExecutor.fake = 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 * @param options\n * @param options.transaction\n * @param options.fake\n */\n async undoLastMigration(options?: {\n transaction?: \"all\" | \"none\" | \"each\"\n fake?: boolean\n }): Promise<void> {\n if (!this.isInitialized) throw new CannotExecuteNotConnectedError()\n\n const migrationExecutor = new MigrationExecutor(this)\n migrationExecutor.transaction = options?.transaction ?? \"all\"\n migrationExecutor.fake = 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()\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 * @param target\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 * @param target\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 * @param target\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 * @param target\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 * @param target\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 * 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 | ((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 * @param query\n * @param parameters\n * @param queryRunner\n * @returns a raw response from the database client\n * @see {@link https://typeorm.io/data-source-api | Official docs} for examples.\n */\n async query<T = any>(\n query: string,\n parameters?: any[] | ObjectLiteral,\n queryRunner?: QueryRunner,\n ): Promise<T> {\n if (InstanceChecker.isMongoEntityManager(this.manager))\n throw new TypeORMError(`Queries aren't supported by MongoDB.`)\n\n if (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 * Tagged template function that executes raw SQL query and returns raw database results.\n * Template expressions are automatically transformed into database parameters.\n * Raw query execution is supported only by relational databases (MongoDB is not supported).\n * Note: Don't call this as a regular function, it is meant to be used with backticks to tag a template literal.\n *\n * @example\n * dataSource.sql`SELECT * FROM table_name WHERE id = ${id}`\n *\n * @param strings\n * @param values\n * @returns a raw response from the database client\n */\n async sql<T = any>(\n strings: TemplateStringsArray,\n ...values: unknown[]\n ): Promise<T> {\n const { query, parameters } = buildSqlTag({\n driver: this.driver,\n strings: strings,\n expressions: values,\n })\n\n return await this.query(query, parameters)\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 * @param entityOrRunner\n * @param alias\n * @param queryRunner\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, undefined, 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 * @param mode\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 * @param entityTarget\n * @param relationPropertyPath\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 * @param queryRunner\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 * @param target\n */\n protected findMetadata(\n target: EntityTarget<any>,\n ): EntityMetadata | undefined {\n const metadataFromMap = this.entityMetadatasMap.get(target)\n if (metadataFromMap) return metadataFromMap\n\n for (const [_, metadata] of this.entityMetadatasMap) {\n if (\n InstanceChecker.isEntitySchema(target) &&\n metadata.name === target.options.name\n ) {\n return metadata\n }\n if (typeof target === \"string\") {\n if (target.indexOf(\".\") !== -1) {\n if (metadata.tablePath === target) {\n return metadata\n }\n } else {\n if (\n metadata.name === target ||\n metadata.tableName === target\n ) {\n return metadata\n }\n }\n }\n if (\n ObjectUtils.isObjectWithName(target) &&\n typeof target.name === \"string\"\n ) {\n if (target.name.indexOf(\".\") !== -1) {\n if (metadata.tablePath === target.name) {\n return metadata\n }\n } else {\n if (\n metadata.name === target.name ||\n metadata.tableName === target.name\n ) {\n return metadata\n }\n }\n }\n }\n\n return undefined\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 =\n 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, {\n entityMetadatas: entityMetadatas,\n entityMetadatasMap: new Map(\n entityMetadatas.map((metadata) => [metadata.target, metadata]),\n ),\n })\n\n // create migration instances\n const flattenedMigrations = ObjectUtils.mixedListToArray(\n this.options.migrations ?? [],\n )\n const migrations =\n await connectionMetadataBuilder.buildMigrations(flattenedMigrations)\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 (const entityMetadata of entityMetadatas) {\n if (\n InstanceChecker.isBaseEntityConstructor(entityMetadata.target)\n ) {\n entityMetadata.target.useDataSource(this)\n }\n }\n }\n\n /**\n * Get the replication mode SELECT queries should use for this datasource by default\n */\n defaultReplicationModeForReads(): ReplicationMode {\n if (\n \"replication\" in this.driver.options &&\n this.driver.options.replication\n ) {\n const value = (\n this.driver.options.replication as {\n defaultMode?: ReplicationMode\n }\n ).defaultMode\n if (value) {\n return value\n }\n }\n return \"slave\"\n }\n}\n"]}
1
+ {"version":3,"file":"DataSource.js","sourceRoot":"","sources":["../../../src/data-source/DataSource.ts"],"names":[],"mappings":";;;AACA,oDAAwD;AAKxD,oFAAgF;AAChF,oCAMiB;AAMjB,sEAAkE;AAIlE,yFAAqF;AAErF,iFAA6E;AAC7E,2DAAuD;AACvD,uFAAmF;AAEnF,4EAAwE;AACxE,2DAAuD;AACvD,8EAA0E;AAG1E,oEAAgE;AAChE,qDAAiD;AAEjD,iFAA2E;AAE3E,wEAAoE;AACpE,uDAAmD;AACnD,6DAAyD;AAEzD,qDAAiD;AAEjD,IAAA,qCAAqB,GAAE,CAAA;AAEvB;;;;;;;GAOG;AACH,MAAa,UAAU;IA6EnB,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,YAAY,OAA0B;QAhF7B,mBAAa,GAAG,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;QAyCjD;;WAEG;QACM,eAAU,GAAyB,EAAE,CAAA;QAE9C;;WAEG;QACM,gBAAW,GAAqC,EAAE,CAAA;QAE3D;;WAEG;QACM,oBAAe,GAAqB,EAAE,CAAA;QAE/C;;;WAGG;QACM,uBAAkB,GAAG,IAAI,GAAG,EAAqC,CAAA;QAclE,mBAAc,GAAG,KAAK,CAAA;QAO1B,IAAA,qCAAqB,GAAE,CAAA;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,MAAM,GAAG,IAAI,6BAAa,EAAE,CAAC,MAAM,CACpC,IAAI,CAAC,OAAO,CAAC,MAAM,EACnB,IAAI,CAAC,OAAO,CAAC,OAAO,CACvB,CAAA;QACD,IAAI,CAAC,MAAM,GAAG,IAAI,6BAAa,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QAC9C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,mBAAmB,EAAE,CAAA;QACzC,IAAI,CAAC,cAAc;YACf,OAAO,CAAC,c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CAovBC","sourcesContent":["import type { Driver } from \"../driver/Driver\"\nimport { registerQueryBuilders } from \"../query-builder\"\nimport type { Repository } from \"../repository/Repository\"\nimport type { EntitySubscriberInterface } from \"../subscriber/EntitySubscriberInterface\"\nimport type { EntityTarget } from \"../common/EntityTarget\"\nimport type { EntityManager } from \"../entity-manager/EntityManager\"\nimport { DefaultNamingStrategy } from \"../naming-strategy/DefaultNamingStrategy\"\nimport {\n CannotConnectAlreadyConnectedError,\n CannotExecuteNotConnectedError,\n EntityMetadataNotFoundError,\n QueryRunnerProviderAlreadyReleasedError,\n TypeORMError,\n} from \"../error\"\nimport type { TreeRepository } from \"../repository/TreeRepository\"\nimport type { NamingStrategyInterface } from \"../naming-strategy/NamingStrategyInterface\"\nimport type { EntityMetadata } from \"../metadata/EntityMetadata\"\nimport type { Logger } from \"../logger/Logger\"\nimport type { MigrationInterface } from \"../migration/MigrationInterface\"\nimport { MigrationExecutor } from \"../migration/MigrationExecutor\"\nimport type { Migration } from \"../migration/Migration\"\nimport type { MongoRepository } from \"../repository/MongoRepository\"\nimport type { MongoEntityManager } from \"../entity-manager/MongoEntityManager\"\nimport { EntityMetadataValidator } from \"../metadata-builder/EntityMetadataValidator\"\nimport type { DataSourceOptions } from \"./DataSourceOptions\"\nimport { EntityManagerFactory } from \"../entity-manager/EntityManagerFactory\"\nimport { DriverFactory } from \"../driver/DriverFactory\"\nimport { ConnectionMetadataBuilder } from \"../connection/ConnectionMetadataBuilder\"\nimport type { QueryRunner } from \"../query-runner/QueryRunner\"\nimport { SelectQueryBuilder } from \"../query-builder/SelectQueryBuilder\"\nimport { LoggerFactory } from \"../logger/LoggerFactory\"\nimport { QueryResultCacheFactory } from \"../cache/QueryResultCacheFactory\"\nimport type { QueryResultCache } from \"../cache/QueryResultCache\"\nimport type { SqljsEntityManager } from \"../entity-manager/SqljsEntityManager\"\nimport { RelationLoader } from \"../query-builder/RelationLoader\"\nimport { ObjectUtils } from \"../util/ObjectUtils\"\nimport type { IsolationLevel } from \"../driver/types/IsolationLevel\"\nimport { validateIsolationLevel } from \"../driver/validate-isolation-level\"\nimport type { ReplicationMode } from \"../driver/types/ReplicationMode\"\nimport { RelationIdLoader } from \"../query-builder/RelationIdLoader\"\nimport { DriverUtils } from \"../driver/DriverUtils\"\nimport { InstanceChecker } from \"../util/InstanceChecker\"\nimport type { ObjectLiteral } from \"../common/ObjectLiteral\"\nimport { buildSqlTag } from \"../util/SqlTagUtils\"\n\nregisterQueryBuilders()\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 * DataSource options.\n */\n readonly options: DataSourceOptions\n\n /**\n * Indicates if the 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 * All entity metadatas that are registered for this connection.\n * This is a copy of #.entityMetadatas property -> used for more performant searches.\n */\n readonly entityMetadatasMap = new Map<EntityTarget<any>, 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 private isInitializing = false\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(options: DataSourceOptions) {\n registerQueryBuilders()\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 * 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 * @returns the mongodb entity manager\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 * @returns an sqljs specific Entity Manager\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 * @param 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 // todo: we must update the database in the driver as well, if it was set by setOptions method\n // in the future we need to refactor the code and remove \"database\" from the driver, and instead\n // use database (and options) from a single place - data source.\n if (options.database) {\n this.driver.database = DriverUtils.buildDriverOptions(\n this.options,\n ).database\n }\n\n // todo: need to take a look if we need to update schema and other \"poor\" properties\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 || this.isInitializing)\n throw new CannotConnectAlreadyConnectedError()\n\n this.isInitializing = true\n try {\n // validate isolationLevel before connecting\n validateIsolationLevel(\n this.driver.supportedIsolationLevels,\n this.options.isolationLevel,\n )\n\n // connect to the database via its driver\n await this.driver.connect()\n\n try {\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 // 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 if (this.isInitialized) {\n await this.destroy()\n } else {\n // clean up whatever partially connected, without letting\n // a cleanup failure mask the original error\n if (this.queryResultCache) {\n try {\n await this.queryResultCache.disconnect()\n } catch {\n // ignore\n }\n }\n try {\n await this.driver.disconnect()\n } catch {\n // ignore\n }\n }\n throw error\n }\n } finally {\n this.isInitializing = false\n }\n\n return this\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) throw new CannotExecuteNotConnectedError()\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 * 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) throw new CannotExecuteNotConnectedError()\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 * @param options\n * @param options.transaction\n * @param options.fake\n */\n async runMigrations(options?: {\n transaction?: \"all\" | \"none\" | \"each\"\n fake?: boolean\n }): Promise<Migration[]> {\n if (!this.isInitialized) throw new CannotExecuteNotConnectedError()\n\n const migrationExecutor = new MigrationExecutor(this)\n migrationExecutor.transaction =\n options?.transaction ??\n this.options?.migrationsTransactionMode ??\n \"all\"\n migrationExecutor.fake = 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 * @param options\n * @param options.transaction\n * @param options.fake\n */\n async undoLastMigration(options?: {\n transaction?: \"all\" | \"none\" | \"each\"\n fake?: boolean\n }): Promise<void> {\n if (!this.isInitialized) throw new CannotExecuteNotConnectedError()\n\n const migrationExecutor = new MigrationExecutor(this)\n migrationExecutor.transaction = options?.transaction ?? \"all\"\n migrationExecutor.fake = 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()\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 * @param target\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 * @param target\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 * @param target\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 * @param target\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 * @param target\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 * 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 | ((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 * @param query\n * @param parameters\n * @param queryRunner\n * @returns a raw response from the database client\n * @see {@link https://typeorm.io/data-source-api | Official docs} for examples.\n */\n async query<T = any>(\n query: string,\n parameters?: any[] | ObjectLiteral,\n queryRunner?: QueryRunner,\n ): Promise<T> {\n if (InstanceChecker.isMongoEntityManager(this.manager))\n throw new TypeORMError(`Queries aren't supported by MongoDB.`)\n\n if (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 * Tagged template function that executes raw SQL query and returns raw database results.\n * Template expressions are automatically transformed into database parameters.\n * Raw query execution is supported only by relational databases (MongoDB is not supported).\n * Note: Don't call this as a regular function, it is meant to be used with backticks to tag a template literal.\n *\n * @example\n * dataSource.sql`SELECT * FROM table_name WHERE id = ${id}`\n *\n * @param strings\n * @param values\n * @returns a raw response from the database client\n */\n async sql<T = any>(\n strings: TemplateStringsArray,\n ...values: unknown[]\n ): Promise<T> {\n const { query, parameters } = buildSqlTag({\n driver: this.driver,\n strings: strings,\n expressions: values,\n })\n\n return await this.query(query, parameters)\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 * @param entityOrRunner\n * @param alias\n * @param queryRunner\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, undefined, 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 * @param mode\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 * @param entityTarget\n * @param relationPropertyPath\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 * @param queryRunner\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 * @param target\n */\n protected findMetadata(\n target: EntityTarget<any>,\n ): EntityMetadata | undefined {\n const metadataFromMap = this.entityMetadatasMap.get(target)\n if (metadataFromMap) return metadataFromMap\n\n for (const [_, metadata] of this.entityMetadatasMap) {\n if (\n InstanceChecker.isEntitySchema(target) &&\n metadata.name === target.options.name\n ) {\n return metadata\n }\n if (typeof target === \"string\") {\n if (target.indexOf(\".\") !== -1) {\n if (metadata.tablePath === target) {\n return metadata\n }\n } else {\n if (\n metadata.name === target ||\n metadata.tableName === target\n ) {\n return metadata\n }\n }\n }\n if (\n ObjectUtils.isObjectWithName(target) &&\n typeof target.name === \"string\"\n ) {\n if (target.name.indexOf(\".\") !== -1) {\n if (metadata.tablePath === target.name) {\n return metadata\n }\n } else {\n if (\n metadata.name === target.name ||\n metadata.tableName === target.name\n ) {\n return metadata\n }\n }\n }\n }\n\n return undefined\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 =\n 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, {\n entityMetadatas: entityMetadatas,\n entityMetadatasMap: new Map(\n entityMetadatas.map((metadata) => [metadata.target, metadata]),\n ),\n })\n\n // create migration instances\n const flattenedMigrations = ObjectUtils.mixedListToArray(\n this.options.migrations ?? [],\n )\n const migrations =\n await connectionMetadataBuilder.buildMigrations(flattenedMigrations)\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 (const entityMetadata of entityMetadatas) {\n if (\n InstanceChecker.isBaseEntityConstructor(entityMetadata.target)\n ) {\n entityMetadata.target.useDataSource(this)\n }\n }\n }\n\n /**\n * Get the replication mode SELECT queries should use for this datasource by default\n */\n defaultReplicationModeForReads(): ReplicationMode {\n if (\n \"replication\" in this.driver.options &&\n this.driver.options.replication\n ) {\n const value = (\n this.driver.options.replication as {\n defaultMode?: ReplicationMode\n }\n ).defaultMode\n if (value) {\n return value\n }\n }\n return \"slave\"\n }\n}\n"]}
@@ -5,9 +5,10 @@ import type { Geometry } from "../../driver/types/GeoJsonTypes";
5
5
  export interface SpatialColumnOptions {
6
6
  /**
7
7
  * Column type's feature type.
8
- * Geometry, Point, Polygon, etc.
8
+ * Geometry, Point, Polygon, etc., optionally with a Z, M or ZM
9
+ * dimensional suffix, such as PointZ or GeometryZM.
9
10
  */
10
- spatialFeatureType?: Geometry["type"];
11
+ spatialFeatureType?: Geometry["type"] | "Geometry" | `${Geometry["type"] | "Geometry"}${"Z" | "M" | "ZM"}`;
11
12
  /**
12
13
  * Column type's SRID.
13
14
  * Spatial Reference ID or EPSG code.
@@ -1 +1 @@
1
- {"version":3,"file":"SpatialColumnOptions.js","sourceRoot":"","sources":["../../../../src/decorator/options/SpatialColumnOptions.ts"],"names":[],"mappings":"","sourcesContent":["import type { Geometry } from \"../../driver/types/GeoJsonTypes\"\n\n/**\n * Options for spatial columns.\n */\nexport interface SpatialColumnOptions {\n /**\n * Column type's feature type.\n * Geometry, Point, Polygon, etc.\n */\n spatialFeatureType?: Geometry[\"type\"]\n\n /**\n * Column type's SRID.\n * Spatial Reference ID or EPSG code.\n */\n srid?: number\n}\n"]}
1
+ {"version":3,"file":"SpatialColumnOptions.js","sourceRoot":"","sources":["../../../../src/decorator/options/SpatialColumnOptions.ts"],"names":[],"mappings":"","sourcesContent":["import type { Geometry } from \"../../driver/types/GeoJsonTypes\"\n\n/**\n * Options for spatial columns.\n */\nexport interface SpatialColumnOptions {\n /**\n * Column type's feature type.\n * Geometry, Point, Polygon, etc., optionally with a Z, M or ZM\n * dimensional suffix, such as PointZ or GeometryZM.\n */\n spatialFeatureType?:\n | Geometry[\"type\"]\n | \"Geometry\"\n | `${Geometry[\"type\"] | \"Geometry\"}${\"Z\" | \"M\" | \"ZM\"}`\n\n /**\n * Column type's SRID.\n * Spatial Reference ID or EPSG code.\n */\n srid?: number\n}\n"]}
@@ -559,6 +559,9 @@ class AuroraMysqlDriver {
559
559
  if (defaultValue === null) {
560
560
  return undefined;
561
561
  }
562
+ if (typeof defaultValue === "function") {
563
+ return defaultValue();
564
+ }
562
565
  if ((columnMetadata.type === "enum" ||
563
566
  columnMetadata.type === "simple-enum") &&
564
567
  defaultValue !== undefined) {
@@ -573,9 +576,6 @@ class AuroraMysqlDriver {
573
576
  if (typeof defaultValue === "boolean") {
574
577
  return defaultValue ? "1" : "0";
575
578
  }
576
- if (typeof defaultValue === "function") {
577
- return defaultValue();
578
- }
579
579
  if (typeof defaultValue === "string") {
580
580
  return `'${defaultValue}'`;
581
581
  }