Skip to content

Commit 7bf12a3

Browse files
committed
reverting back some instanceof checks to prevent compiler errors
1 parent 7588ac1 commit 7bf12a3

9 files changed

Lines changed: 33 additions & 16 deletions

File tree

src/query-builder/InsertQueryBuilder.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import {AbstractSqliteDriver} from "../driver/sqlite-abstract/AbstractSqliteDriv
1212
import {BroadcasterResult} from "../subscriber/BroadcasterResult";
1313
import {EntitySchema} from "../entity-schema/EntitySchema";
1414
import {TypeORMError} from "../error";
15+
import {SqlServerDriver} from "../driver/sqlserver/SqlServerDriver";
16+
import {MysqlDriver} from "../driver/mysql/MysqlDriver";
17+
import {AuroraDataApiDriver} from "../driver/aurora-data-api/AuroraDataApiDriver";
1518

1619
/**
1720
* Allows to build complex sql queries in a fashion way and execute those queries.
@@ -100,7 +103,7 @@ export class InsertQueryBuilder<Entity> extends QueryBuilder<Entity> {
100103
));
101104
}
102105

103-
if (returningColumns.length > 0 && this.connection.driver.options.type === "mssql") {
106+
if (returningColumns.length > 0 && this.connection.driver instanceof SqlServerDriver) {
104107
declareSql = this.connection.driver.buildTableVariableDeclaration("@OutputTable", returningColumns);
105108
selectOutputSql = `SELECT * FROM @OutputTable`;
106109
}
@@ -555,7 +558,7 @@ export class InsertQueryBuilder<Entity> extends QueryBuilder<Entity> {
555558

556559
// just any other regular value
557560
} else {
558-
if (this.connection.driver.options.type === "mssql")
561+
if (this.connection.driver instanceof SqlServerDriver)
559562
value = this.connection.driver.parametrizeValue(column, value);
560563

561564
// we need to store array values in a special class to make sure parameter replacement will work correctly
@@ -565,7 +568,7 @@ export class InsertQueryBuilder<Entity> extends QueryBuilder<Entity> {
565568

566569
const paramName = this.createParameter(value);
567570

568-
if ((this.connection.driver.options.type === "mysql" || this.connection.driver.options.type === "aurora-data-api") && this.connection.driver.spatialTypes.indexOf(column.type) !== -1) {
571+
if ((this.connection.driver instanceof MysqlDriver || this.connection.driver instanceof AuroraDataApiDriver) && this.connection.driver.spatialTypes.indexOf(column.type) !== -1) {
569572
const useLegacy = this.connection.driver.options.legacySpatialSupport;
570573
const geomFromText = useLegacy ? "GeomFromText" : "ST_GeomFromText";
571574
if (column.srid != null) {

src/query-builder/QueryBuilder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {TypeORMError} from "../error";
2121
import {WhereClause, WhereClauseCondition} from "./WhereClause";
2222
import {NotBrackets} from "./NotBrackets";
2323
import {EntityPropertyNotFoundError} from "../error/EntityPropertyNotFoundError";
24+
import {OracleDriver} from "../driver/oracle/OracleDriver";
2425

2526
// todo: completely cover query builder with tests
2627
// todo: entityOrProperty can be target name. implement proper behaviour if it is.
@@ -761,7 +762,7 @@ export abstract class QueryBuilder<Entity> {
761762
}
762763
}).join(", ");
763764

764-
if (driver.options.type === "oracle") {
765+
if (driver instanceof OracleDriver) {
765766
columnsExpression += " INTO " + columns.map(column => {
766767
return this.createParameter({ type: driver.columnTypeToNativeParameter(column.type), dir: driver.oracle.BIND_OUT });
767768
}).join(", ");

src/query-builder/SelectQueryBuilder.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ import {FindOperator} from "../find-options/FindOperator";
4545
import {OrmUtils} from "../util/OrmUtils";
4646
import {EntityPropertyNotFoundError} from "../error/EntityPropertyNotFoundError";
4747
import {EqualOperator} from "../find-options/EqualOperator";
48+
import {MysqlDriver} from "../driver/mysql/MysqlDriver";
49+
import {AuroraDataApiDriver} from "../driver/aurora-data-api/AuroraDataApiDriver";
4850

4951
/**
5052
* Allows to build complex sql queries in a fashion way and execute those queries.
@@ -1841,7 +1843,7 @@ export class SelectQueryBuilder<Entity> extends QueryBuilder<Entity> implements
18411843
allColumns.forEach(column => {
18421844
let selectionPath = this.escape(aliasName) + "." + this.escape(column.databaseName);
18431845
if (this.connection.driver.spatialTypes.indexOf(column.type) !== -1) {
1844-
if (this.connection.driver.options.type === "mysql" || this.connection.driver.options.type === "aurora-data-api") {
1846+
if (this.connection.driver instanceof MysqlDriver || this.connection.driver instanceof AuroraDataApiDriver) {
18451847
const useLegacy = this.connection.driver.options.legacySpatialSupport;
18461848
const asText = useLegacy ? "AsText" : "ST_AsText";
18471849
selectionPath = `${asText}(${selectionPath})`;

src/query-builder/UpdateQueryBuilder.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import {UpdateValuesMissingError} from "../error/UpdateValuesMissingError";
1414
import {QueryDeepPartialEntity} from "./QueryPartialEntity";
1515
import {TypeORMError} from "../error";
1616
import {EntityPropertyNotFoundError} from "../error/EntityPropertyNotFoundError";
17+
import {MysqlDriver} from "../driver/mysql/MysqlDriver";
18+
import {AuroraDataApiDriver} from "../driver/aurora-data-api/AuroraDataApiDriver";
19+
import {SqlServerDriver} from "../driver/sqlserver/SqlServerDriver";
1720

1821
/**
1922
* Allows to build complex sql queries in a fashion way and execute those queries.
@@ -90,7 +93,7 @@ export class UpdateQueryBuilder<Entity> extends QueryBuilder<Entity> implements
9093
));
9194
}
9295

93-
if (returningColumns.length > 0 && this.connection.driver.options.type === "mssql") {
96+
if (returningColumns.length > 0 && this.connection.driver instanceof SqlServerDriver) {
9497
declareSql = this.connection.driver.buildTableVariableDeclaration("@OutputTable", returningColumns);
9598
selectOutputSql = `SELECT * FROM @OutputTable`;
9699
}
@@ -405,14 +408,14 @@ export class UpdateQueryBuilder<Entity> extends QueryBuilder<Entity> implements
405408
} else if (this.connection.driver.options.type === "sap" && value === null) {
406409
updateColumnAndValues.push(this.escape(column.databaseName) + " = NULL");
407410
} else {
408-
if (this.connection.driver.options.type === "mssql") {
411+
if (this.connection.driver instanceof SqlServerDriver) {
409412
value = this.connection.driver.parametrizeValue(column, value);
410413
}
411414

412415
const paramName = this.createParameter(value);
413416

414417
let expression = null;
415-
if ((this.connection.driver.options.type === "mysql" || this.connection.driver.options.type === "aurora-data-api") && this.connection.driver.spatialTypes.indexOf(column.type) !== -1) {
418+
if ((this.connection.driver instanceof MysqlDriver || this.connection.driver instanceof AuroraDataApiDriver) && this.connection.driver.spatialTypes.indexOf(column.type) !== -1) {
416419
const useLegacy = this.connection.driver.options.legacySpatialSupport;
417420
const geomFromText = useLegacy ? "GeomFromText" : "ST_GeomFromText";
418421
if (column.srid != null) {

src/schema-builder/RdbmsSchemaBuilder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {TableCheck} from "./table/TableCheck";
1515
import {TableExclusion} from "./table/TableExclusion";
1616
import {View} from "./view/View";
1717
import {ViewUtils} from "./util/ViewUtils";
18+
import {PostgresDriver} from "../driver/postgres/PostgresDriver";
1819

1920
/**
2021
* Creates complete tables schemas in the database based on the entity metadatas.
@@ -108,7 +109,7 @@ export class RdbmsSchemaBuilder implements SchemaBuilder {
108109
* If the schema contains views, create the typeorm_metadata table if it doesn't exist yet
109110
*/
110111
async createMetadataTableIfNecessary(queryRunner: QueryRunner): Promise<void> {
111-
if (this.viewEntityToSyncMetadatas.length > 0 || (this.connection.driver.options.type === "postgres" && this.connection.driver.isGeneratedColumnsSupported)) {
112+
if (this.viewEntityToSyncMetadatas.length > 0 || (this.connection.driver instanceof PostgresDriver && this.connection.driver.isGeneratedColumnsSupported)) {
112113
await this.createTypeormMetadataTable(queryRunner);
113114
}
114115
}

test/functional/query-runner/add-column.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {Connection} from "../../../src/connection/Connection";
44
import {AbstractSqliteDriver} from "../../../src/driver/sqlite-abstract/AbstractSqliteDriver";
55
import {TableColumn} from "../../../src/schema-builder/table/TableColumn";
66
import {closeTestingConnections, createTestingConnections} from "../../utils/test-utils";
7+
import {PostgresDriver} from "../../../src/driver/postgres/PostgresDriver";
78

89
describe("query runner > add column", () => {
910

@@ -90,7 +91,7 @@ describe("query runner > add column", () => {
9091
const isMySQL = connection.driver.options.type === "mysql" && connection.options.type === "mysql";
9192
let postgresSupported = false;
9293

93-
if (connection.driver.options.type === "postgres") {
94+
if (connection.driver instanceof PostgresDriver) {
9495
postgresSupported = connection.driver.isGeneratedColumnsSupported;
9596
}
9697

test/functional/query-runner/change-column.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {Connection} from "../../../src/connection/Connection";
44
import {closeTestingConnections, createTestingConnections} from "../../utils/test-utils";
55
import {AbstractSqliteDriver} from "../../../src/driver/sqlite-abstract/AbstractSqliteDriver";
66
import {TableColumn} from "../../../src";
7+
import {PostgresDriver} from "../../../src/driver/postgres/PostgresDriver";
78

89
describe("query runner > change column", () => {
910

@@ -138,7 +139,7 @@ describe("query runner > change column", () => {
138139
it("should correctly change generated as expression", () => Promise.all(connections.map(async connection => {
139140

140141
// Only works on postgres
141-
if (!(connection.driver.options.type === "postgres")) return;
142+
if (!(connection.driver instanceof PostgresDriver)) return;
142143

143144
const queryRunner = connection.createQueryRunner();
144145

test/functional/schema-builder/change-column.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import {AbstractSqliteDriver} from "../../../src/driver/sqlite-abstract/Abstract
55
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../utils/test-utils";
66
import {Post} from "./entity/Post";
77
import {PostVersion} from "./entity/PostVersion";
8+
import {PostgresDriver} from "../../../src/driver/postgres/PostgresDriver";
9+
import {CockroachDriver} from "../../../src/driver/cockroachdb/CockroachDriver";
10+
import {SqlServerDriver} from "../../../src/driver/sqlserver/SqlServerDriver";
811

912
describe("schema builder > change column", () => {
1013

@@ -180,7 +183,7 @@ describe("schema builder > change column", () => {
180183
idColumn.generationStrategy = "uuid";
181184

182185
// depending on driver, we must change column and referenced column types
183-
if (connection.driver.options.type === "postgres" || connection.driver.options.type === "cockroachdb") {
186+
if (connection.driver instanceof PostgresDriver || connection.driver instanceof CockroachDriver) {
184187
idColumn.type = "uuid";
185188
} else if (connection.driver.options.type === "mssql") {
186189
idColumn.type = "uniqueidentifier";
@@ -193,7 +196,7 @@ describe("schema builder > change column", () => {
193196
const postTable = await queryRunner.getTable("post");
194197
await queryRunner.release();
195198

196-
if (connection.driver.options.type === "postgres" || connection.driver.options.type === "mssql" || connection.driver.options.type === "cockroachdb") {
199+
if (connection.driver instanceof PostgresDriver || connection.driver instanceof CockroachDriver || connection.driver instanceof SqlServerDriver) {
197200
postTable!.findColumnByName("id")!.isGenerated.should.be.true;
198201
postTable!.findColumnByName("id")!.generationStrategy!.should.be.equal("uuid");
199202

@@ -224,7 +227,7 @@ describe("schema builder > change column", () => {
224227
idColumn.generationStrategy = "uuid";
225228

226229
// depending on driver, we must change column and referenced column types
227-
if (connection.driver.options.type === "postgres" || connection.driver.options.type === "cockroachdb") {
230+
if (connection.driver instanceof PostgresDriver || connection.driver instanceof CockroachDriver) {
228231
idColumn.type = "uuid";
229232
teacherColumn.type = "uuid";
230233
} else if (connection.driver.options.type === "mssql") {

test/functional/transaction/transaction-with-load-many/transaction-load-many.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import {expect} from "chai";
33
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../utils/test-utils";
44
import {Connection} from "../../../../src";
55
import {Post} from "./entity/Post";
6+
import {MysqlDriver} from "../../../../src/driver/mysql/MysqlDriver";
7+
import {PostgresDriver} from "../../../../src/driver/postgres/PostgresDriver";
68

79
describe("transaction > transaction with load many", () => {
810

@@ -19,10 +21,10 @@ describe("transaction > transaction with load many", () => {
1921

2022
const driver = connection.driver;
2123

22-
if (driver.options.type === "mysql") {
24+
if (driver instanceof MysqlDriver) {
2325
const pool = driver.pool;
2426
pool.on("acquire", () => acquireCount++);
25-
} else if (driver.options.type === "postgres") {
27+
} else if (driver instanceof PostgresDriver) {
2628
const pool = driver.master;
2729
pool.on("acquire", () => acquireCount++);
2830
}

0 commit comments

Comments
 (0)