From 4e2c095ba54518afa953efb690788e9770a272ca Mon Sep 17 00:00:00 2001 From: Roman Lakhtadyr Date: Tue, 16 May 2017 20:57:52 +0300 Subject: [PATCH] add "drop table" to query runner --- src/driver/mongodb/MongoQueryRunner.ts | 7 +++++++ src/driver/mysql/MysqlQueryRunner.ts | 8 ++++++++ src/driver/oracle/OracleQueryRunner.ts | 8 ++++++++ src/driver/postgres/PostgresQueryRunner.ts | 8 ++++++++ src/driver/sqlite/SqliteQueryRunner.ts | 8 ++++++++ src/driver/sqlserver/SqlServerQueryRunner.ts | 8 ++++++++ src/driver/websql/WebsqlQueryRunner.ts | 8 ++++++++ src/query-runner/QueryRunner.ts | 5 +++++ 8 files changed, 60 insertions(+) diff --git a/src/driver/mongodb/MongoQueryRunner.ts b/src/driver/mongodb/MongoQueryRunner.ts index 27e40cc0c..fb5f208e0 100644 --- a/src/driver/mongodb/MongoQueryRunner.ts +++ b/src/driver/mongodb/MongoQueryRunner.ts @@ -435,6 +435,13 @@ export class MongoQueryRunner implements QueryRunner { throw new Error(`Schema update queries are not supported by MongoDB driver.`); } + /** + * Drops the table. + */ + async dropTable(tableName: string): Promise { + throw new Error(`Schema update queries are not supported by MongoDB driver.`); + } + /** * Checks if column with the given name exist in the given table. */ diff --git a/src/driver/mysql/MysqlQueryRunner.ts b/src/driver/mysql/MysqlQueryRunner.ts index 29c40bfa1..b8f9c3a2a 100644 --- a/src/driver/mysql/MysqlQueryRunner.ts +++ b/src/driver/mysql/MysqlQueryRunner.ts @@ -359,6 +359,14 @@ export class MysqlQueryRunner implements QueryRunner { await this.query(sql); } + /** + * Drop the table. + */ + async dropTable(tableName: String): Promise { + let sql = `DROP TABLE \`${tableName}\``; + await this.query(sql); + } + /** * Checks if column with the given name exist in the given table. */ diff --git a/src/driver/oracle/OracleQueryRunner.ts b/src/driver/oracle/OracleQueryRunner.ts index c4bea1abd..e9649ff14 100644 --- a/src/driver/oracle/OracleQueryRunner.ts +++ b/src/driver/oracle/OracleQueryRunner.ts @@ -388,6 +388,14 @@ AND cons.constraint_name = cols.constraint_name AND cons.owner = cols.owner ORDE await this.query(sql); } + /** + * Drops the table. + */ + async dropTable(tableName: string): Promise { + let sql = `DROP TABLE "${tableName}"`; + await this.query(sql); + } + /** * Checks if column with the given name exist in the given table. */ diff --git a/src/driver/postgres/PostgresQueryRunner.ts b/src/driver/postgres/PostgresQueryRunner.ts index b213c950b..24b557b01 100644 --- a/src/driver/postgres/PostgresQueryRunner.ts +++ b/src/driver/postgres/PostgresQueryRunner.ts @@ -373,6 +373,14 @@ where constraint_type = 'PRIMARY KEY' AND c.table_schema = '${this.schemaName}' await this.query(sql); } + /** + * Drops the table. + */ + async dropTable(tableName: string): Promise { + let sql = `DROP TABLE "${tableName}"`; + await this.query(sql); + } + /** * Checks if column with the given name exist in the given table. */ diff --git a/src/driver/sqlite/SqliteQueryRunner.ts b/src/driver/sqlite/SqliteQueryRunner.ts index c73e54f92..178cc111c 100644 --- a/src/driver/sqlite/SqliteQueryRunner.ts +++ b/src/driver/sqlite/SqliteQueryRunner.ts @@ -399,6 +399,14 @@ export class SqliteQueryRunner implements QueryRunner { await this.query(sql); } + /** + * Drops the table. + */ + async dropTable(tableName: string): Promise { + let sql = `DROP TABLE "${tableName}"`; + await this.query(sql); + } + /** * Checks if column with the given name exist in the given table. */ diff --git a/src/driver/sqlserver/SqlServerQueryRunner.ts b/src/driver/sqlserver/SqlServerQueryRunner.ts index f37168f0a..c40e4b167 100644 --- a/src/driver/sqlserver/SqlServerQueryRunner.ts +++ b/src/driver/sqlserver/SqlServerQueryRunner.ts @@ -445,6 +445,14 @@ export class SqlServerQueryRunner implements QueryRunner { await this.query(sql); } + /** + * Drops the table. + */ + async dropTable(tableName: string): Promise { + let sql = `DROP TABLE "${tableName}"`; + await this.query(sql); + } + /** * Checks if column with the given name exist in the given table. */ diff --git a/src/driver/websql/WebsqlQueryRunner.ts b/src/driver/websql/WebsqlQueryRunner.ts index 51d482e47..61ea36c76 100644 --- a/src/driver/websql/WebsqlQueryRunner.ts +++ b/src/driver/websql/WebsqlQueryRunner.ts @@ -409,6 +409,14 @@ export class WebsqlQueryRunner implements QueryRunner { await this.query(sql); } + /** + * Drops the table. + */ + async dropTable(tableName: string): Promise { + let sql = `DROP TABLE "${tableName}"`; + await this.query(sql); + } + /** * Checks if column with the given name exist in the given table. */ diff --git a/src/query-runner/QueryRunner.ts b/src/query-runner/QueryRunner.ts index 4a41ebdaf..1a2389603 100644 --- a/src/query-runner/QueryRunner.ts +++ b/src/query-runner/QueryRunner.ts @@ -106,6 +106,11 @@ export interface QueryRunner { */ createTable(table: TableSchema): Promise; + /** + * Drops the table. + */ + dropTable(tableName: string): Promise; + /** * Checks if column with the given name exist in the given table. */