typeorm 0.2.38-dev.e9366b3 → 0.2.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -16,7 +16,7 @@
16
16
  <a href="https://codecov.io/gh/typeorm/typeorm">
17
17
  <img alt="Codecov" src="https://img.shields.io/codecov/c/github/typeorm/typeorm.svg">
18
18
  </a>
19
- <a href="https://join.slack.com/t/typeorm/shared_invite/zt-gej3gc00-hR~L~DqGUJ7qOpGy4SSq3g">
19
+ <a href="https://join.slack.com/t/typeorm/shared_invite/zt-uu12ljeb-OH_0086I379fUDApYJHNuw">
20
20
  <img src="https://img.shields.io/badge/chat-on%20slack-blue.svg">
21
21
  </a>
22
22
  <br>
@@ -62,6 +62,7 @@ export declare abstract class BaseQueryRunner {
62
62
  * If replication is not setup its value is ignored.
63
63
  */
64
64
  protected mode: ReplicationMode;
65
+ private cachedTablePaths;
65
66
  /**
66
67
  * Executes a given SQL query.
67
68
  */
@@ -125,7 +126,7 @@ export declare abstract class BaseQueryRunner {
125
126
  * Replaces loaded table with given changed table.
126
127
  */
127
128
  protected replaceCachedTable(table: Table, changedTable: Table): void;
128
- protected getTablePath(target: EntityMetadata | Table | TableForeignKey | string): string;
129
+ protected getTablePath(target: EntityMetadata | Table | View | TableForeignKey | string): string;
129
130
  protected getTypeormMetadataTableName(): string;
130
131
  /**
131
132
  * Checks if at least one of column properties was changed.
@@ -1,10 +1,7 @@
1
1
  import { __awaiter, __generator, __read, __spreadArray, __values } from "tslib";
2
2
  import { Query } from "../driver/Query";
3
3
  import { SqlInMemory } from "../driver/SqlInMemory";
4
- import { Table } from "../schema-builder/table/Table";
5
4
  import { TypeORMError } from "../error/TypeORMError";
6
- import { EntityMetadata } from "../metadata/EntityMetadata";
7
- import { TableForeignKey } from "../schema-builder/table/TableForeignKey";
8
5
  var BaseQueryRunner = /** @class */ (function () {
9
6
  function BaseQueryRunner() {
10
7
  // -------------------------------------------------------------------------
@@ -40,6 +37,7 @@ var BaseQueryRunner = /** @class */ (function () {
40
37
  * Sql-s stored if "sql in memory" mode is enabled.
41
38
  */
42
39
  this.sqlInMemory = new SqlInMemory();
40
+ this.cachedTablePaths = {};
43
41
  }
44
42
  // -------------------------------------------------------------------------
45
43
  // Public Methods
@@ -267,19 +265,32 @@ var BaseQueryRunner = /** @class */ (function () {
267
265
  */
268
266
  BaseQueryRunner.prototype.getCachedTable = function (tableName) {
269
267
  return __awaiter(this, void 0, void 0, function () {
270
- var table, foundTables;
268
+ var tablePath_1, table, foundTables, foundTablePath_1, cachedTable;
269
+ var _this = this;
271
270
  return __generator(this, function (_a) {
272
271
  switch (_a.label) {
273
272
  case 0:
274
- table = this.loadedTables.find(function (table) { return table.name === tableName; });
275
- if (table)
276
- return [2 /*return*/, table];
273
+ if (tableName in this.cachedTablePaths) {
274
+ tablePath_1 = this.cachedTablePaths[tableName];
275
+ table = this.loadedTables.find(function (table) { return _this.getTablePath(table) === tablePath_1; });
276
+ if (table) {
277
+ return [2 /*return*/, table];
278
+ }
279
+ }
277
280
  return [4 /*yield*/, this.loadTables([tableName])];
278
281
  case 1:
279
282
  foundTables = _a.sent();
280
283
  if (foundTables.length > 0) {
281
- this.loadedTables.push(foundTables[0]);
282
- return [2 /*return*/, foundTables[0]];
284
+ foundTablePath_1 = this.getTablePath(foundTables[0]);
285
+ cachedTable = this.loadedTables.find(function (table) { return _this.getTablePath(table) === foundTablePath_1; });
286
+ if (!cachedTable) {
287
+ this.cachedTablePaths[tableName] = this.getTablePath(foundTables[0]);
288
+ this.loadedTables.push(foundTables[0]);
289
+ return [2 /*return*/, foundTables[0]];
290
+ }
291
+ else {
292
+ return [2 /*return*/, cachedTable];
293
+ }
283
294
  }
284
295
  else {
285
296
  throw new TypeORMError("Table \"" + tableName + "\" does not exist.");
@@ -293,7 +304,26 @@ var BaseQueryRunner = /** @class */ (function () {
293
304
  * Replaces loaded table with given changed table.
294
305
  */
295
306
  BaseQueryRunner.prototype.replaceCachedTable = function (table, changedTable) {
296
- var foundTable = this.loadedTables.find(function (loadedTable) { return loadedTable.name === table.name; });
307
+ var e_3, _a;
308
+ var _this = this;
309
+ var oldTablePath = this.getTablePath(table);
310
+ var foundTable = this.loadedTables.find(function (loadedTable) { return _this.getTablePath(loadedTable) === oldTablePath; });
311
+ try {
312
+ // Clean up the lookup cache..
313
+ for (var _b = __values(Object.entries(this.cachedTablePaths)), _c = _b.next(); !_c.done; _c = _b.next()) {
314
+ var _d = __read(_c.value, 2), key = _d[0], cachedPath = _d[1];
315
+ if (cachedPath === oldTablePath) {
316
+ this.cachedTablePaths[key] = this.getTablePath(changedTable);
317
+ }
318
+ }
319
+ }
320
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
321
+ finally {
322
+ try {
323
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
324
+ }
325
+ finally { if (e_3) throw e_3.error; }
326
+ }
297
327
  if (foundTable) {
298
328
  foundTable.database = changedTable.database;
299
329
  foundTable.schema = changedTable.schema;
@@ -308,16 +338,8 @@ var BaseQueryRunner = /** @class */ (function () {
308
338
  }
309
339
  };
310
340
  BaseQueryRunner.prototype.getTablePath = function (target) {
311
- if (target instanceof Table) {
312
- return target.name;
313
- }
314
- if (target instanceof TableForeignKey) {
315
- return target.referencedTableName;
316
- }
317
- if (target instanceof EntityMetadata) {
318
- return target.tablePath;
319
- }
320
- return target;
341
+ var parsed = this.connection.driver.parseTableName(target);
342
+ return this.connection.driver.buildTableName(parsed.tableName, parsed.schema, parsed.database);
321
343
  };
322
344
  BaseQueryRunner.prototype.getTypeormMetadataTableName = function () {
323
345
  var options = this.connection.driver.options;
@@ -429,8 +451,8 @@ var BaseQueryRunner = /** @class */ (function () {
429
451
  */
430
452
  BaseQueryRunner.prototype.executeQueries = function (upQueries, downQueries) {
431
453
  return __awaiter(this, void 0, void 0, function () {
432
- var upQueries_1, upQueries_1_1, _a, query, parameters, e_3_1;
433
- var _b, _c, e_3, _d;
454
+ var upQueries_1, upQueries_1_1, _a, query, parameters, e_4_1;
455
+ var _b, _c, e_4, _d;
434
456
  return __generator(this, function (_e) {
435
457
  switch (_e.label) {
436
458
  case 0:
@@ -460,14 +482,14 @@ var BaseQueryRunner = /** @class */ (function () {
460
482
  return [3 /*break*/, 2];
461
483
  case 5: return [3 /*break*/, 8];
462
484
  case 6:
463
- e_3_1 = _e.sent();
464
- e_3 = { error: e_3_1 };
485
+ e_4_1 = _e.sent();
486
+ e_4 = { error: e_4_1 };
465
487
  return [3 /*break*/, 8];
466
488
  case 7:
467
489
  try {
468
490
  if (upQueries_1_1 && !upQueries_1_1.done && (_d = upQueries_1.return)) _d.call(upQueries_1);
469
491
  }
470
- finally { if (e_3) throw e_3.error; }
492
+ finally { if (e_4) throw e_4.error; }
471
493
  return [7 /*endfinally*/];
472
494
  case 8: return [2 /*return*/];
473
495
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../browser/src/query-runner/BaseQueryRunner.ts"],"names":[],"mappings":";AACA,OAAO,EAAC,KAAK,EAAC,MAAM,iBAAiB,CAAC;AACtC,OAAO,EAAC,WAAW,EAAC,MAAM,uBAAuB,CAAC;AAIlD,OAAO,EAAC,KAAK,EAAC,MAAM,+BAA+B,CAAC;AAKpD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAE1E;IAAA;QAEI,4EAA4E;QAC5E,oBAAoB;QACpB,4EAA4E;QAY5E;;;WAGG;QACH,eAAU,GAAG,KAAK,CAAC;QAEnB;;WAEG;QACH,wBAAmB,GAAG,KAAK,CAAC;QAE5B;;;WAGG;QACH,SAAI,GAAG,EAAE,CAAC;QAEV;;WAEG;QACH,iBAAY,GAAY,EAAE,CAAC;QAE3B;;WAEG;QACH,gBAAW,GAAW,EAAE,CAAC;QAgBzB;;WAEG;QACO,kBAAa,GAAY,KA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AEL,sBAAC;AAAD,CA7YA,AA6YC,IAAA","file":"BaseQueryRunner.js","sourcesContent":["import {PostgresConnectionOptions} from \"../driver/postgres/PostgresConnectionOptions\";\nimport {Query} from \"../driver/Query\";\nimport {SqlInMemory} from \"../driver/SqlInMemory\";\nimport {SqlServerConnectionOptions} from \"../driver/sqlserver/SqlServerConnectionOptions\";\nimport {View} from \"../schema-builder/view/View\";\nimport {Connection} from \"../connection/Connection\";\nimport {Table} from \"../schema-builder/table/Table\";\nimport {EntityManager} from \"../entity-manager/EntityManager\";\nimport {TableColumn} from \"../schema-builder/table/TableColumn\";\nimport {Broadcaster} from \"../subscriber/Broadcaster\";\nimport {ReplicationMode} from \"../driver/types/ReplicationMode\";\nimport { TypeORMError } from \"../error/TypeORMError\";\nimport { EntityMetadata } from \"../metadata/EntityMetadata\";\nimport { TableForeignKey } from \"../schema-builder/table/TableForeignKey\";\n\nexport abstract class BaseQueryRunner {\n\n // -------------------------------------------------------------------------\n // Public Properties\n // -------------------------------------------------------------------------\n\n /**\n * Connection used by this query runner.\n */\n connection: Connection;\n\n /**\n * Entity manager working only with current query runner.\n */\n manager: EntityManager;\n\n /**\n * Indicates if connection for this query runner is released.\n * Once its released, query runner cannot run queries anymore.\n */\n isReleased = false;\n\n /**\n * Indicates if transaction is in progress.\n */\n isTransactionActive = false;\n\n /**\n * Stores temporarily user data.\n * Useful for sharing data with subscribers.\n */\n data = {};\n\n /**\n * All synchronized tables in the database.\n */\n loadedTables: Table[] = [];\n\n /**\n * All synchronized views in the database.\n */\n loadedViews: View[] = [];\n\n /**\n * Broadcaster used on this query runner to broadcast entity events.\n */\n broadcaster: Broadcaster;\n\n // -------------------------------------------------------------------------\n // Protected Properties\n // -------------------------------------------------------------------------\n\n /**\n * Real database connection from a connection pool used to perform queries.\n */\n protected databaseConnection: any;\n\n /**\n * Indicates if special query runner mode in which sql queries won't be executed is enabled.\n */\n protected sqlMemoryMode: boolean = false;\n\n /**\n * Sql-s stored if \"sql in memory\" mode is enabled.\n */\n protected sqlInMemory: SqlInMemory = new SqlInMemory();\n\n /**\n * Mode in which query runner executes.\n * Used for replication.\n * If replication is not setup its value is ignored.\n */\n protected mode: ReplicationMode;\n\n // -------------------------------------------------------------------------\n // Public Abstract Methods\n // -------------------------------------------------------------------------\n\n /**\n * Executes a given SQL query.\n */\n abstract query(query: string, parameters?: any[], useStructuredResult?: boolean): Promise<any>;\n\n // -------------------------------------------------------------------------\n // Protected Abstract Methods\n // -------------------------------------------------------------------------\n\n protected abstract loadTables(tablePaths?: string[]): Promise<Table[]>;\n\n protected abstract loadViews(tablePaths?: string[]): Promise<View[]>;\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Loads given table's data from the database.\n */\n async getTable(tablePath: string): Promise<Table|undefined> {\n this.loadedTables = await this.loadTables([tablePath]);\n return this.loadedTables.length > 0 ? this.loadedTables[0] : undefined;\n }\n\n /**\n * Loads all tables (with given names) from the database.\n */\n async getTables(tableNames?: string[]): Promise<Table[]> {\n if (!tableNames) {\n // Don't cache in this case.\n // This is the new case & isn't used anywhere else anyway.\n return await this.loadTables(tableNames);\n }\n\n this.loadedTables = await this.loadTables(tableNames);\n return this.loadedTables;\n }\n\n /**\n * Loads given view's data from the database.\n */\n async getView(viewPath: string): Promise<View|undefined> {\n this.loadedViews = await this.loadViews([viewPath]);\n return this.loadedViews.length > 0 ? this.loadedViews[0] : undefined;\n }\n\n /**\n * Loads given view's data from the database.\n */\n async getViews(viewPaths?: string[]): Promise<View[]> {\n this.loadedViews = await this.loadViews(viewPaths);\n return this.loadedViews;\n }\n\n /**\n * Enables special query runner mode in which sql queries won't be executed,\n * instead they will be memorized into a special variable inside query runner.\n * You can get memorized sql using getMemorySql() method.\n */\n enableSqlMemory(): void {\n this.sqlInMemory = new SqlInMemory();\n this.sqlMemoryMode = true;\n }\n\n /**\n * Disables special query runner mode in which sql queries won't be executed\n * started by calling enableSqlMemory() method.\n *\n * Previously memorized sql will be flushed.\n */\n disableSqlMemory(): void {\n this.sqlInMemory = new SqlInMemory();\n this.sqlMemoryMode = false;\n }\n\n /**\n * Flushes all memorized sqls.\n */\n clearSqlMemory(): void {\n this.sqlInMemory = new SqlInMemory();\n }\n\n /**\n * Gets sql stored in the memory. Parameters in the sql are already replaced.\n */\n getMemorySql(): SqlInMemory {\n return this.sqlInMemory;\n }\n\n /**\n * Executes up sql queries.\n */\n async executeMemoryUpSql(): Promise<void> {\n for (const {query, parameters} of this.sqlInMemory.upQueries) {\n await this.query(query, parameters);\n }\n }\n\n /**\n * Executes down sql queries.\n */\n async executeMemoryDownSql(): Promise<void> {\n for (const {query, parameters} of this.sqlInMemory.downQueries.reverse()) {\n await this.query(query, parameters);\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Gets view from previously loaded views, otherwise loads it from database.\n */\n protected async getCachedView(viewName: string): Promise<View> {\n const view = this.loadedViews.find(view => view.name === viewName);\n if (view) return view;\n\n const foundViews = await this.loadViews([viewName]);\n if (foundViews.length > 0) {\n this.loadedViews.push(foundViews[0]);\n return foundViews[0];\n } else {\n throw new TypeORMError(`View \"${viewName}\" does not exist.`);\n }\n }\n\n /**\n * Gets table from previously loaded tables, otherwise loads it from database.\n */\n protected async getCachedTable(tableName: string): Promise<Table> {\n const table = this.loadedTables.find(table => table.name === tableName);\n if (table) return table;\n\n const foundTables = await this.loadTables([tableName]);\n if (foundTables.length > 0) {\n this.loadedTables.push(foundTables[0]);\n return foundTables[0];\n } else {\n throw new TypeORMError(`Table \"${tableName}\" does not exist.`);\n }\n }\n\n /**\n * Replaces loaded table with given changed table.\n */\n protected replaceCachedTable(table: Table, changedTable: Table): void {\n const foundTable = this.loadedTables.find(loadedTable => loadedTable.name === table.name);\n if (foundTable) {\n foundTable.database = changedTable.database;\n foundTable.schema = changedTable.schema;\n foundTable.name = changedTable.name;\n foundTable.columns = changedTable.columns;\n foundTable.indices = changedTable.indices;\n foundTable.foreignKeys = changedTable.foreignKeys;\n foundTable.uniques = changedTable.uniques;\n foundTable.checks = changedTable.checks;\n foundTable.justCreated = changedTable.justCreated;\n foundTable.engine = changedTable.engine;\n }\n }\n\n protected getTablePath(target: EntityMetadata | Table | TableForeignKey | string): string {\n if (target instanceof Table) {\n return target.name;\n }\n\n if (target instanceof TableForeignKey) {\n return target.referencedTableName;\n }\n\n if (target instanceof EntityMetadata) {\n return target.tablePath;\n }\n\n return target;\n }\n\n protected getTypeormMetadataTableName(): string {\n const options = <SqlServerConnectionOptions|PostgresConnectionOptions>this.connection.driver.options;\n return this.connection.driver.buildTableName(\"typeorm_metadata\", options.schema, options.database);\n }\n\n /**\n * Checks if at least one of column properties was changed.\n * Does not checks column type, length and autoincrement, because these properties changes separately.\n */\n protected isColumnChanged(oldColumn: TableColumn, newColumn: TableColumn, checkDefault?: boolean, checkComment?: boolean): boolean {\n // this logs need to debug issues in column change detection. Do not delete it!\n\n // console.log(\"charset ---------------\");\n // console.log(oldColumn.charset !== newColumn.charset);\n // console.log(oldColumn.charset, newColumn.charset);\n // console.log(\"collation ---------------\");\n // console.log(oldColumn.collation !== newColumn.collation);\n // console.log(oldColumn.collation, newColumn.collation);\n // console.log(\"precision ---------------\");\n // console.log(oldColumn.precision !== newColumn.precision);\n // console.log(oldColumn.precision, newColumn.precision);\n // console.log(\"scale ---------------\");\n // console.log(oldColumn.scale !== newColumn.scale);\n // console.log(oldColumn.scale, newColumn.scale);\n // console.log(\"default ---------------\");\n // console.log((checkDefault && oldColumn.default !== newColumn.default));\n // console.log(oldColumn.default, newColumn.default);\n // console.log(\"isNullable ---------------\");\n // console.log(oldColumn.isNullable !== newColumn.isNullable);\n // console.log(oldColumn.isNullable, newColumn.isNullable);\n // console.log(\"comment ---------------\");\n // console.log((checkComment && oldColumn.comment !== newColumn.comment));\n // console.log(oldColumn.comment, newColumn.comment);\n // console.log(\"enum ---------------\");\n // console.log(oldColumn.enum !== newColumn.enum);\n // console.log(oldColumn.enum, newColumn.enum);\n\n return oldColumn.charset !== newColumn.charset\n || oldColumn.collation !== newColumn.collation\n || oldColumn.precision !== newColumn.precision\n || oldColumn.scale !== newColumn.scale\n || oldColumn.width !== newColumn.width // MySQL only\n || oldColumn.zerofill !== newColumn.zerofill // MySQL only\n || oldColumn.unsigned !== newColumn.unsigned // MySQL only\n || oldColumn.asExpression !== newColumn.asExpression // MySQL only\n || (checkDefault && oldColumn.default !== newColumn.default)\n || oldColumn.onUpdate !== newColumn.onUpdate // MySQL only\n || oldColumn.isNullable !== newColumn.isNullable\n || (checkComment && oldColumn.comment !== newColumn.comment)\n || oldColumn.enum !== newColumn.enum;\n }\n\n /**\n * Checks if column length is by default.\n */\n protected isDefaultColumnLength(table: Table, column: TableColumn, length: string): boolean {\n // if table have metadata, we check if length is specified in column metadata\n if (this.connection.hasMetadata(table.name)) {\n const metadata = this.connection.getMetadata(table.name);\n const columnMetadata = metadata.findColumnWithDatabaseName(column.name);\n\n if (columnMetadata) {\n const columnMetadataLength = this.connection.driver.getColumnLength(columnMetadata);\n if (columnMetadataLength)\n return false;\n }\n }\n\n if (this.connection.driver.dataTypeDefaults\n && this.connection.driver.dataTypeDefaults[column.type]\n && this.connection.driver.dataTypeDefaults[column.type].length) {\n return this.connection.driver.dataTypeDefaults[column.type].length!.toString() === length.toString();\n }\n\n return false;\n }\n\n /**\n * Checks if column precision is by default.\n */\n protected isDefaultColumnPrecision(table: Table, column: TableColumn, precision: number): boolean {\n // if table have metadata, we check if length is specified in column metadata\n if (this.connection.hasMetadata(table.name)) {\n const metadata = this.connection.getMetadata(table.name);\n const columnMetadata = metadata.findColumnWithDatabaseName(column.name);\n if (columnMetadata && columnMetadata.precision !== null && columnMetadata.precision !== undefined)\n return false;\n }\n\n if (this.connection.driver.dataTypeDefaults\n && this.connection.driver.dataTypeDefaults[column.type]\n && this.connection.driver.dataTypeDefaults[column.type].precision !== null\n && this.connection.driver.dataTypeDefaults[column.type].precision !== undefined)\n return this.connection.driver.dataTypeDefaults[column.type].precision === precision;\n\n return false;\n }\n\n /**\n * Checks if column scale is by default.\n */\n protected isDefaultColumnScale(table: Table, column: TableColumn, scale: number): boolean {\n // if table have metadata, we check if length is specified in column metadata\n if (this.connection.hasMetadata(table.name)) {\n const metadata = this.connection.getMetadata(table.name);\n const columnMetadata = metadata.findColumnWithDatabaseName(column.name);\n if (columnMetadata && columnMetadata.scale !== null && columnMetadata.scale !== undefined)\n return false;\n }\n\n if (this.connection.driver.dataTypeDefaults\n && this.connection.driver.dataTypeDefaults[column.type]\n && this.connection.driver.dataTypeDefaults[column.type].scale !== null\n && this.connection.driver.dataTypeDefaults[column.type].scale !== undefined)\n return this.connection.driver.dataTypeDefaults[column.type].scale === scale;\n\n return false;\n }\n\n /**\n * Executes sql used special for schema build.\n */\n protected async executeQueries(upQueries: Query|Query[], downQueries: Query|Query[]): Promise<void> {\n if (upQueries instanceof Query)\n upQueries = [upQueries];\n if (downQueries instanceof Query)\n downQueries = [downQueries];\n\n this.sqlInMemory.upQueries.push(...upQueries);\n this.sqlInMemory.downQueries.push(...downQueries);\n\n // if sql-in-memory mode is enabled then simply store sql in memory and return\n if (this.sqlMemoryMode === true)\n return Promise.resolve() as Promise<any>;\n\n for (const {query, parameters} of upQueries) {\n await this.query(query, parameters);\n }\n }\n\n}\n"],"sourceRoot":".."}
1
+ {"version":3,"sources":["../browser/src/query-runner/BaseQueryRunner.ts"],"names":[],"mappings":";AACA,OAAO,EAAC,KAAK,EAAC,MAAM,iBAAiB,CAAC;AACtC,OAAO,EAAC,WAAW,EAAC,MAAM,uBAAuB,CAAC;AASlD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAIrD;IAAA;QAEI,4EAA4E;QAC5E,oBAAoB;QACpB,4EAA4E;QAY5E;;;WAGG;QACH,eAAU,GAAG,KAAK,CAAC;QAEnB;;WAEG;QACH,wBAAmB,GAAG,KAAK,CAAC;QAE5B;;;WAGG;QACH,SAAI,GAAG,EAAE,CAAC;QAEV;;WAEG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\nimport {Query} from \"../driver/Query\";\nimport {SqlInMemory} from \"../driver/SqlInMemory\";\nimport {SqlServerConnectionOptions} from \"../driver/sqlserver/SqlServerConnectionOptions\";\nimport {View} from \"../schema-builder/view/View\";\nimport {Connection} from \"../connection/Connection\";\nimport {Table} from \"../schema-builder/table/Table\";\nimport {EntityManager} from \"../entity-manager/EntityManager\";\nimport {TableColumn} from \"../schema-builder/table/TableColumn\";\nimport {Broadcaster} from \"../subscriber/Broadcaster\";\nimport {ReplicationMode} from \"../driver/types/ReplicationMode\";\nimport { TypeORMError } from \"../error/TypeORMError\";\nimport { EntityMetadata } from \"../metadata/EntityMetadata\";\nimport { TableForeignKey } from \"../schema-builder/table/TableForeignKey\";\n\nexport abstract class BaseQueryRunner {\n\n // -------------------------------------------------------------------------\n // Public Properties\n // -------------------------------------------------------------------------\n\n /**\n * Connection used by this query runner.\n */\n connection: Connection;\n\n /**\n * Entity manager working only with current query runner.\n */\n manager: EntityManager;\n\n /**\n * Indicates if connection for this query runner is released.\n * Once its released, query runner cannot run queries anymore.\n */\n isReleased = false;\n\n /**\n * Indicates if transaction is in progress.\n */\n isTransactionActive = false;\n\n /**\n * Stores temporarily user data.\n * Useful for sharing data with subscribers.\n */\n data = {};\n\n /**\n * All synchronized tables in the database.\n */\n loadedTables: Table[] = [];\n\n /**\n * All synchronized views in the database.\n */\n loadedViews: View[] = [];\n\n /**\n * Broadcaster used on this query runner to broadcast entity events.\n */\n broadcaster: Broadcaster;\n\n // -------------------------------------------------------------------------\n // Protected Properties\n // -------------------------------------------------------------------------\n\n /**\n * Real database connection from a connection pool used to perform queries.\n */\n protected databaseConnection: any;\n\n /**\n * Indicates if special query runner mode in which sql queries won't be executed is enabled.\n */\n protected sqlMemoryMode: boolean = false;\n\n /**\n * Sql-s stored if \"sql in memory\" mode is enabled.\n */\n protected sqlInMemory: SqlInMemory = new SqlInMemory();\n\n /**\n * Mode in which query runner executes.\n * Used for replication.\n * If replication is not setup its value is ignored.\n */\n protected mode: ReplicationMode;\n\n private cachedTablePaths: Record<string, string> = {};\n\n // -------------------------------------------------------------------------\n // Public Abstract Methods\n // -------------------------------------------------------------------------\n\n /**\n * Executes a given SQL query.\n */\n abstract query(query: string, parameters?: any[], useStructuredResult?: boolean): Promise<any>;\n\n // -------------------------------------------------------------------------\n // Protected Abstract Methods\n // -------------------------------------------------------------------------\n\n protected abstract loadTables(tablePaths?: string[]): Promise<Table[]>;\n\n protected abstract loadViews(tablePaths?: string[]): Promise<View[]>;\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Loads given table's data from the database.\n */\n async getTable(tablePath: string): Promise<Table|undefined> {\n this.loadedTables = await this.loadTables([tablePath]);\n return this.loadedTables.length > 0 ? this.loadedTables[0] : undefined;\n }\n\n /**\n * Loads all tables (with given names) from the database.\n */\n async getTables(tableNames?: string[]): Promise<Table[]> {\n if (!tableNames) {\n // Don't cache in this case.\n // This is the new case & isn't used anywhere else anyway.\n return await this.loadTables(tableNames);\n }\n\n this.loadedTables = await this.loadTables(tableNames);\n return this.loadedTables;\n }\n\n /**\n * Loads given view's data from the database.\n */\n async getView(viewPath: string): Promise<View|undefined> {\n this.loadedViews = await this.loadViews([viewPath]);\n return this.loadedViews.length > 0 ? this.loadedViews[0] : undefined;\n }\n\n /**\n * Loads given view's data from the database.\n */\n async getViews(viewPaths?: string[]): Promise<View[]> {\n this.loadedViews = await this.loadViews(viewPaths);\n return this.loadedViews;\n }\n\n /**\n * Enables special query runner mode in which sql queries won't be executed,\n * instead they will be memorized into a special variable inside query runner.\n * You can get memorized sql using getMemorySql() method.\n */\n enableSqlMemory(): void {\n this.sqlInMemory = new SqlInMemory();\n this.sqlMemoryMode = true;\n }\n\n /**\n * Disables special query runner mode in which sql queries won't be executed\n * started by calling enableSqlMemory() method.\n *\n * Previously memorized sql will be flushed.\n */\n disableSqlMemory(): void {\n this.sqlInMemory = new SqlInMemory();\n this.sqlMemoryMode = false;\n }\n\n /**\n * Flushes all memorized sqls.\n */\n clearSqlMemory(): void {\n this.sqlInMemory = new SqlInMemory();\n }\n\n /**\n * Gets sql stored in the memory. Parameters in the sql are already replaced.\n */\n getMemorySql(): SqlInMemory {\n return this.sqlInMemory;\n }\n\n /**\n * Executes up sql queries.\n */\n async executeMemoryUpSql(): Promise<void> {\n for (const {query, parameters} of this.sqlInMemory.upQueries) {\n await this.query(query, parameters);\n }\n }\n\n /**\n * Executes down sql queries.\n */\n async executeMemoryDownSql(): Promise<void> {\n for (const {query, parameters} of this.sqlInMemory.downQueries.reverse()) {\n await this.query(query, parameters);\n }\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Gets view from previously loaded views, otherwise loads it from database.\n */\n protected async getCachedView(viewName: string): Promise<View> {\n const view = this.loadedViews.find(view => view.name === viewName);\n if (view) return view;\n\n const foundViews = await this.loadViews([viewName]);\n if (foundViews.length > 0) {\n this.loadedViews.push(foundViews[0]);\n return foundViews[0];\n } else {\n throw new TypeORMError(`View \"${viewName}\" does not exist.`);\n }\n }\n\n /**\n * Gets table from previously loaded tables, otherwise loads it from database.\n */\n protected async getCachedTable(tableName: string): Promise<Table> {\n if (tableName in this.cachedTablePaths) {\n const tablePath = this.cachedTablePaths[tableName];\n const table = this.loadedTables.find(table => this.getTablePath(table) === tablePath);\n\n if (table) {\n return table;\n }\n }\n\n const foundTables = await this.loadTables([tableName]);\n\n if (foundTables.length > 0) {\n const foundTablePath = this.getTablePath(foundTables[0]);\n\n const cachedTable = this.loadedTables.find((table) => this.getTablePath(table) === foundTablePath);\n\n if (!cachedTable) {\n this.cachedTablePaths[tableName] = this.getTablePath(foundTables[0]);\n this.loadedTables.push(foundTables[0]);\n return foundTables[0];\n } else {\n return cachedTable;\n }\n } else {\n throw new TypeORMError(`Table \"${tableName}\" does not exist.`);\n }\n }\n\n /**\n * Replaces loaded table with given changed table.\n */\n protected replaceCachedTable(table: Table, changedTable: Table): void {\n const oldTablePath = this.getTablePath(table);\n const foundTable = this.loadedTables.find(loadedTable => this.getTablePath(loadedTable) === oldTablePath);\n\n // Clean up the lookup cache..\n for (const [key, cachedPath] of Object.entries(this.cachedTablePaths)) {\n if (cachedPath === oldTablePath) {\n this.cachedTablePaths[key] = this.getTablePath(changedTable);\n }\n }\n\n if (foundTable) {\n foundTable.database = changedTable.database;\n foundTable.schema = changedTable.schema;\n foundTable.name = changedTable.name;\n foundTable.columns = changedTable.columns;\n foundTable.indices = changedTable.indices;\n foundTable.foreignKeys = changedTable.foreignKeys;\n foundTable.uniques = changedTable.uniques;\n foundTable.checks = changedTable.checks;\n foundTable.justCreated = changedTable.justCreated;\n foundTable.engine = changedTable.engine;\n }\n }\n\n protected getTablePath(target: EntityMetadata | Table | View | TableForeignKey | string): string {\n const parsed = this.connection.driver.parseTableName(target);\n\n return this.connection.driver.buildTableName(\n parsed.tableName,\n parsed.schema,\n parsed.database\n );\n }\n\n protected getTypeormMetadataTableName(): string {\n const options = <SqlServerConnectionOptions|PostgresConnectionOptions>this.connection.driver.options;\n return this.connection.driver.buildTableName(\"typeorm_metadata\", options.schema, options.database);\n }\n\n /**\n * Checks if at least one of column properties was changed.\n * Does not checks column type, length and autoincrement, because these properties changes separately.\n */\n protected isColumnChanged(oldColumn: TableColumn, newColumn: TableColumn, checkDefault?: boolean, checkComment?: boolean): boolean {\n // this logs need to debug issues in column change detection. Do not delete it!\n\n // console.log(\"charset ---------------\");\n // console.log(oldColumn.charset !== newColumn.charset);\n // console.log(oldColumn.charset, newColumn.charset);\n // console.log(\"collation ---------------\");\n // console.log(oldColumn.collation !== newColumn.collation);\n // console.log(oldColumn.collation, newColumn.collation);\n // console.log(\"precision ---------------\");\n // console.log(oldColumn.precision !== newColumn.precision);\n // console.log(oldColumn.precision, newColumn.precision);\n // console.log(\"scale ---------------\");\n // console.log(oldColumn.scale !== newColumn.scale);\n // console.log(oldColumn.scale, newColumn.scale);\n // console.log(\"default ---------------\");\n // console.log((checkDefault && oldColumn.default !== newColumn.default));\n // console.log(oldColumn.default, newColumn.default);\n // console.log(\"isNullable ---------------\");\n // console.log(oldColumn.isNullable !== newColumn.isNullable);\n // console.log(oldColumn.isNullable, newColumn.isNullable);\n // console.log(\"comment ---------------\");\n // console.log((checkComment && oldColumn.comment !== newColumn.comment));\n // console.log(oldColumn.comment, newColumn.comment);\n // console.log(\"enum ---------------\");\n // console.log(oldColumn.enum !== newColumn.enum);\n // console.log(oldColumn.enum, newColumn.enum);\n\n return oldColumn.charset !== newColumn.charset\n || oldColumn.collation !== newColumn.collation\n || oldColumn.precision !== newColumn.precision\n || oldColumn.scale !== newColumn.scale\n || oldColumn.width !== newColumn.width // MySQL only\n || oldColumn.zerofill !== newColumn.zerofill // MySQL only\n || oldColumn.unsigned !== newColumn.unsigned // MySQL only\n || oldColumn.asExpression !== newColumn.asExpression // MySQL only\n || (checkDefault && oldColumn.default !== newColumn.default)\n || oldColumn.onUpdate !== newColumn.onUpdate // MySQL only\n || oldColumn.isNullable !== newColumn.isNullable\n || (checkComment && oldColumn.comment !== newColumn.comment)\n || oldColumn.enum !== newColumn.enum;\n }\n\n /**\n * Checks if column length is by default.\n */\n protected isDefaultColumnLength(table: Table, column: TableColumn, length: string): boolean {\n // if table have metadata, we check if length is specified in column metadata\n if (this.connection.hasMetadata(table.name)) {\n const metadata = this.connection.getMetadata(table.name);\n const columnMetadata = metadata.findColumnWithDatabaseName(column.name);\n\n if (columnMetadata) {\n const columnMetadataLength = this.connection.driver.getColumnLength(columnMetadata);\n if (columnMetadataLength)\n return false;\n }\n }\n\n if (this.connection.driver.dataTypeDefaults\n && this.connection.driver.dataTypeDefaults[column.type]\n && this.connection.driver.dataTypeDefaults[column.type].length) {\n return this.connection.driver.dataTypeDefaults[column.type].length!.toString() === length.toString();\n }\n\n return false;\n }\n\n /**\n * Checks if column precision is by default.\n */\n protected isDefaultColumnPrecision(table: Table, column: TableColumn, precision: number): boolean {\n // if table have metadata, we check if length is specified in column metadata\n if (this.connection.hasMetadata(table.name)) {\n const metadata = this.connection.getMetadata(table.name);\n const columnMetadata = metadata.findColumnWithDatabaseName(column.name);\n if (columnMetadata && columnMetadata.precision !== null && columnMetadata.precision !== undefined)\n return false;\n }\n\n if (this.connection.driver.dataTypeDefaults\n && this.connection.driver.dataTypeDefaults[column.type]\n && this.connection.driver.dataTypeDefaults[column.type].precision !== null\n && this.connection.driver.dataTypeDefaults[column.type].precision !== undefined)\n return this.connection.driver.dataTypeDefaults[column.type].precision === precision;\n\n return false;\n }\n\n /**\n * Checks if column scale is by default.\n */\n protected isDefaultColumnScale(table: Table, column: TableColumn, scale: number): boolean {\n // if table have metadata, we check if length is specified in column metadata\n if (this.connection.hasMetadata(table.name)) {\n const metadata = this.connection.getMetadata(table.name);\n const columnMetadata = metadata.findColumnWithDatabaseName(column.name);\n if (columnMetadata && columnMetadata.scale !== null && columnMetadata.scale !== undefined)\n return false;\n }\n\n if (this.connection.driver.dataTypeDefaults\n && this.connection.driver.dataTypeDefaults[column.type]\n && this.connection.driver.dataTypeDefaults[column.type].scale !== null\n && this.connection.driver.dataTypeDefaults[column.type].scale !== undefined)\n return this.connection.driver.dataTypeDefaults[column.type].scale === scale;\n\n return false;\n }\n\n /**\n * Executes sql used special for schema build.\n */\n protected async executeQueries(upQueries: Query|Query[], downQueries: Query|Query[]): Promise<void> {\n if (upQueries instanceof Query)\n upQueries = [upQueries];\n if (downQueries instanceof Query)\n downQueries = [downQueries];\n\n this.sqlInMemory.upQueries.push(...upQueries);\n this.sqlInMemory.downQueries.push(...downQueries);\n\n // if sql-in-memory mode is enabled then simply store sql in memory and return\n if (this.sqlMemoryMode === true)\n return Promise.resolve() as Promise<any>;\n\n for (const {query, parameters} of upQueries) {\n await this.query(query, parameters);\n }\n }\n\n}\n"],"sourceRoot":".."}
@@ -25,6 +25,8 @@ export declare class RdbmsSchemaBuilder implements SchemaBuilder {
25
25
  * Used to execute schema creation queries in a single connection.
26
26
  */
27
27
  protected queryRunner: QueryRunner;
28
+ private currentDatabase?;
29
+ private currentSchema?;
28
30
  constructor(connection: Connection);
29
31
  /**
30
32
  * Creates complete schemas for the given entity metadatas.
@@ -47,6 +47,9 @@ var RdbmsSchemaBuilder = /** @class */ (function () {
47
47
  switch (_a.label) {
48
48
  case 0:
49
49
  this.queryRunner = this.connection.createQueryRunner();
50
+ // this.connection.driver.database || this.currentDatabase;
51
+ this.currentDatabase = this.connection.driver.database;
52
+ this.currentSchema = this.connection.driver.schema;
50
53
  isUsingTransactions = (!(this.connection.driver instanceof CockroachDriver) &&
51
54
  this.connection.options.migrationsTransactionMode !== "none");
52
55
  if (!isUsingTransactions) return [3 /*break*/, 2];
@@ -252,13 +255,8 @@ var RdbmsSchemaBuilder = /** @class */ (function () {
252
255
  });
253
256
  };
254
257
  RdbmsSchemaBuilder.prototype.getTablePath = function (target) {
255
- if (target instanceof Table) {
256
- return target.name;
257
- }
258
- if (target instanceof TableForeignKey) {
259
- return target.referencedTableName;
260
- }
261
- return target.tablePath;
258
+ var parsed = this.connection.driver.parseTableName(target);
259
+ return this.connection.driver.buildTableName(parsed.tableName, parsed.schema || this.currentSchema, parsed.database || this.currentDatabase);
262
260
  };
263
261
  /**
264
262
  * Drops all (old) foreign keys that exist in the tables, but do not exist in the entity metadata.
@@ -706,27 +704,18 @@ var RdbmsSchemaBuilder = /** @class */ (function () {
706
704
  */
707
705
  RdbmsSchemaBuilder.prototype.createNewTables = function () {
708
706
  return __awaiter(this, void 0, void 0, function () {
709
- var currentSchema, _loop_7, this_7, _a, _b, metadata, e_7_1;
707
+ var _loop_7, this_7, _a, _b, metadata, e_7_1;
710
708
  var e_7, _c;
711
709
  var _this = this;
712
710
  return __generator(this, function (_d) {
713
711
  switch (_d.label) {
714
- case 0: return [4 /*yield*/, this.queryRunner.getCurrentSchema()];
715
- case 1:
716
- currentSchema = _d.sent();
712
+ case 0:
717
713
  _loop_7 = function (metadata) {
718
714
  var existTable, table;
719
715
  return __generator(this, function (_e) {
720
716
  switch (_e.label) {
721
717
  case 0:
722
- existTable = this_7.queryRunner.loadedTables.find(function (table) {
723
- var database = metadata.database && metadata.database !== _this.connection.driver.database ? metadata.database : undefined;
724
- var schema = metadata.schema || _this.connection.driver.options.schema;
725
- // if schema is default db schema (e.g. "public" in PostgreSQL), skip it.
726
- schema = schema === currentSchema ? undefined : schema;
727
- var fullTableName = _this.connection.driver.buildTableName(metadata.tableName, schema, database);
728
- return table.name === fullTableName;
729
- });
718
+ existTable = this_7.queryRunner.loadedTables.find(function (table) { return _this.getTablePath(table) === _this.getTablePath(metadata); });
730
719
  if (existTable)
731
720
  return [2 /*return*/, "continue"];
732
721
  this_7.connection.logger.logSchemaBuild("creating a new table: " + this_7.getTablePath(metadata));
@@ -740,33 +729,33 @@ var RdbmsSchemaBuilder = /** @class */ (function () {
740
729
  });
741
730
  };
742
731
  this_7 = this;
732
+ _d.label = 1;
733
+ case 1:
734
+ _d.trys.push([1, 6, 7, 8]);
735
+ _a = __values(this.entityToSyncMetadatas), _b = _a.next();
743
736
  _d.label = 2;
744
737
  case 2:
745
- _d.trys.push([2, 7, 8, 9]);
746
- _a = __values(this.entityToSyncMetadatas), _b = _a.next();
747
- _d.label = 3;
748
- case 3:
749
- if (!!_b.done) return [3 /*break*/, 6];
738
+ if (!!_b.done) return [3 /*break*/, 5];
750
739
  metadata = _b.value;
751
740
  return [5 /*yield**/, _loop_7(metadata)];
752
- case 4:
741
+ case 3:
753
742
  _d.sent();
754
- _d.label = 5;
755
- case 5:
743
+ _d.label = 4;
744
+ case 4:
756
745
  _b = _a.next();
757
- return [3 /*break*/, 3];
758
- case 6: return [3 /*break*/, 9];
759
- case 7:
746
+ return [3 /*break*/, 2];
747
+ case 5: return [3 /*break*/, 8];
748
+ case 6:
760
749
  e_7_1 = _d.sent();
761
750
  e_7 = { error: e_7_1 };
762
- return [3 /*break*/, 9];
763
- case 8:
751
+ return [3 /*break*/, 8];
752
+ case 7:
764
753
  try {
765
754
  if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
766
755
  }
767
756
  finally { if (e_7) throw e_7.error; }
768
757
  return [7 /*endfinally*/];
769
- case 9: return [2 /*return*/];
758
+ case 8: return [2 /*return*/];
770
759
  }
771
760
  });
772
761
  });
@@ -785,12 +774,9 @@ var RdbmsSchemaBuilder = /** @class */ (function () {
785
774
  switch (_e.label) {
786
775
  case 0:
787
776
  existView = this_8.queryRunner.loadedViews.find(function (view) {
788
- var database = metadata.database && metadata.database !== _this.connection.driver.database ? metadata.database : undefined;
789
- var schema = metadata.schema || _this.connection.driver.options.schema;
790
- var fullViewName = _this.connection.driver.buildTableName(metadata.tableName, schema, database);
791
777
  var viewExpression = typeof view.expression === "string" ? view.expression.trim() : view.expression(_this.connection).getQuery();
792
778
  var metadataExpression = typeof metadata.expression === "string" ? metadata.expression.trim() : metadata.expression(_this.connection).getQuery();
793
- return view.name === fullViewName && viewExpression === metadataExpression;
779
+ return _this.getTablePath(view) === _this.getTablePath(metadata) && viewExpression === metadataExpression;
794
780
  });
795
781
  if (existView)
796
782
  return [2 /*return*/, "continue"];
@@ -851,12 +837,9 @@ var RdbmsSchemaBuilder = /** @class */ (function () {
851
837
  switch (_e.label) {
852
838
  case 0:
853
839
  existViewMetadata = this_9.viewEntityToSyncMetadatas.find(function (metadata) {
854
- var database = metadata.database && metadata.database !== _this.connection.driver.database ? metadata.database : undefined;
855
- var schema = metadata.schema || _this.connection.driver.options.schema;
856
- var fullViewName = _this.connection.driver.buildTableName(metadata.tableName, schema, database);
857
840
  var viewExpression = typeof view.expression === "string" ? view.expression.trim() : view.expression(_this.connection).getQuery();
858
841
  var metadataExpression = typeof metadata.expression === "string" ? metadata.expression.trim() : metadata.expression(_this.connection).getQuery();
859
- return view.name === fullViewName && viewExpression === metadataExpression;
842
+ return _this.getTablePath(view) === _this.getTablePath(metadata) && viewExpression === metadataExpression;
860
843
  });
861
844
  if (existViewMetadata)
862
845
  return [2 /*return*/, "continue"];
@@ -1732,8 +1715,8 @@ var RdbmsSchemaBuilder = /** @class */ (function () {
1732
1715
  return __generator(this, function (_a) {
1733
1716
  switch (_a.label) {
1734
1717
  case 0:
1735
- schema = this.connection.driver.options.schema;
1736
- database = this.connection.driver.database;
1718
+ schema = this.currentSchema;
1719
+ database = this.currentDatabase;
1737
1720
  typeormMetadataTable = this.connection.driver.buildTableName("typeorm_metadata", schema, database);
1738
1721
  return [4 /*yield*/, this.queryRunner.createTable(new Table({
1739
1722
  database: database,