From b1335eed7f1166f913d6cb12f718bbab7a420ef8 Mon Sep 17 00:00:00 2001 From: pc3b3r Date: Thu, 20 Aug 2020 16:03:00 +0200 Subject: [PATCH] drivers query IN --- src/drivers/MssqlDriver.ts | 13 +++++++++---- src/drivers/MysqlDriver.ts | 13 +++++++++---- src/drivers/OracleDriver.ts | 13 +++++++++---- src/drivers/PostgresDriver.ts | 13 +++++++++---- src/drivers/SqliteDriver.ts | 13 +++++++++---- 5 files changed, 45 insertions(+), 20 deletions(-) diff --git a/src/drivers/MssqlDriver.ts b/src/drivers/MssqlDriver.ts index ccc846f3..054eead2 100644 --- a/src/drivers/MssqlDriver.ts +++ b/src/drivers/MssqlDriver.ts @@ -40,12 +40,17 @@ export default class MssqlDriver extends AbstractDriver { public GetAllTablesQuery = async ( schema: string, dbNames: string, - tableNames: string[] + notInTables: string[], + inTables: string[] ) => { const request = new this.MSSQL.Request(this.Connection); const tableCondition = - tableNames.length > 0 - ? ` AND NOT TABLE_NAME IN ('${tableNames.join("','")}')` + notInTables.length > 0 + ? ` AND NOT TABLE_NAME IN ('${notInTables.join("','")}')` + : ""; + const inTableCondition = + inTables.length > 0 + ? ` AND TABLE_NAME IN ('${inTables.join("','")}')` : ""; const response: { TABLE_SCHEMA: string; @@ -56,7 +61,7 @@ export default class MssqlDriver extends AbstractDriver { `SELECT TABLE_SCHEMA,TABLE_NAME, table_catalog as "DB_NAME" FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE' and TABLE_SCHEMA in (${schema}) AND TABLE_CATALOG in (${MssqlDriver.escapeCommaSeparatedList( dbNames - )}) ${tableCondition}` + )}) ${tableCondition} ${inTableCondition}` ) ).recordset; return response; diff --git a/src/drivers/MysqlDriver.ts b/src/drivers/MysqlDriver.ts index 95d7f171..fbb259d4 100644 --- a/src/drivers/MysqlDriver.ts +++ b/src/drivers/MysqlDriver.ts @@ -42,11 +42,16 @@ export default class MysqlDriver extends AbstractDriver { public GetAllTablesQuery = async ( schema: string, dbNames: string, - tableNames: string[] + notInTables: string[], + inTables: string[] ) => { const tableCondition = - tableNames.length > 0 - ? ` AND NOT TABLE_NAME IN ('${tableNames.join("','")}')` + notInTables.length > 0 + ? ` AND NOT TABLE_NAME IN ('${notInTables.join("','")}')` + : ""; + const inTableCondition = + inTables.length > 0 + ? ` AND TABLE_NAME IN ('${inTables.join("','")}')` : ""; const response = this.ExecQuery<{ TABLE_SCHEMA: string; @@ -57,7 +62,7 @@ export default class MysqlDriver extends AbstractDriver { WHERE table_type='BASE TABLE' AND table_schema IN (${MysqlDriver.escapeCommaSeparatedList( dbNames - )}) ${tableCondition}`); + )}) ${tableCondition} ${inTableCondition}`); return response; }; diff --git a/src/drivers/OracleDriver.ts b/src/drivers/OracleDriver.ts index 2282887e..b283c138 100644 --- a/src/drivers/OracleDriver.ts +++ b/src/drivers/OracleDriver.ts @@ -41,11 +41,16 @@ export default class OracleDriver extends AbstractDriver { public GetAllTablesQuery = async ( schema: string, dbNames: string, - tableNames: string[] + notInTables: string[], + inTables: string[] ) => { const tableCondition = - tableNames.length > 0 - ? ` AND NOT TABLE_NAME IN ('${tableNames.join("','")}')` + notInTables.length > 0 + ? ` AND NOT TABLE_NAME IN ('${notInTables.join("','")}')` + : ""; + const inTableCondition = + inTables.length > 0 + ? ` AND TABLE_NAME IN ('${inTables.join("','")}')` : ""; const response = ( await this.Connection.execute<{ @@ -53,7 +58,7 @@ export default class OracleDriver extends AbstractDriver { TABLE_NAME: string; DB_NAME: string; }>( - `SELECT NULL AS TABLE_SCHEMA, TABLE_NAME, NULL AS DB_NAME FROM all_tables WHERE owner = (select user from dual) ${tableCondition}` + `SELECT NULL AS TABLE_SCHEMA, TABLE_NAME, NULL AS DB_NAME FROM all_tables WHERE owner = (select user from dual) ${tableCondition} ${inTableCondition}` ) ).rows!; return response; diff --git a/src/drivers/PostgresDriver.ts b/src/drivers/PostgresDriver.ts index 6ac3d1b9..a5884ccf 100644 --- a/src/drivers/PostgresDriver.ts +++ b/src/drivers/PostgresDriver.ts @@ -40,11 +40,16 @@ export default class PostgresDriver extends AbstractDriver { public GetAllTablesQuery = async ( schema: string, dbNames: string, - tableNames: string[] + notInTables: string[], + inTables: string[] ) => { const tableCondition = - tableNames.length > 0 - ? ` AND NOT table_name IN ('${tableNames.join("','")}')` + notInTables.length > 0 + ? ` AND NOT table_name IN ('${notInTables.join("','")}')` + : ""; + const inTableCondition = + inTables.length > 0 + ? ` AND table_name IN ('${inTables.join("','")}')` : ""; const response: { TABLE_SCHEMA: string; @@ -52,7 +57,7 @@ export default class PostgresDriver extends AbstractDriver { DB_NAME: string; }[] = ( await this.Connection.query( - `SELECT table_schema as "TABLE_SCHEMA",table_name as "TABLE_NAME", table_catalog as "DB_NAME" FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE' AND table_schema in (${schema}) ${tableCondition}` + `SELECT table_schema as "TABLE_SCHEMA",table_name as "TABLE_NAME", table_catalog as "DB_NAME" FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE' AND table_schema in (${schema}) ${tableCondition} ${inTableCondition}` ) ).rows; return response; diff --git a/src/drivers/SqliteDriver.ts b/src/drivers/SqliteDriver.ts index 1883a97d..1c8ed190 100644 --- a/src/drivers/SqliteDriver.ts +++ b/src/drivers/SqliteDriver.ts @@ -47,16 +47,21 @@ export default class SqliteDriver extends AbstractDriver { public async GetAllTables( schema: string, dbNames: string, - tableNames: string[] + notInTables: string[], + inTables: string[] ): Promise { const ret: Entity[] = [] as Entity[]; const tableCondition = - tableNames.length > 0 - ? ` AND NOT tbl_name IN ('${tableNames.join("','")}')` + notInTables.length > 0 + ? ` AND NOT tbl_name IN ('${notInTables.join("','")}')` + : ""; + const inTableCondition = + inTables.length > 0 + ? ` AND tbl_name IN ('${inTables.join("','")}')` : ""; // eslint-disable-next-line camelcase const rows = await this.ExecQuery<{ tbl_name: string; sql: string }>( - `SELECT tbl_name, sql FROM "sqlite_master" WHERE "type" = 'table' AND name NOT LIKE 'sqlite_%' ${tableCondition}` + `SELECT tbl_name, sql FROM "sqlite_master" WHERE "type" = 'table' AND name NOT LIKE 'sqlite_%' ${tableCondition} ${inTableCondition}` ); rows.forEach((val) => { if (val.sql.includes("AUTOINCREMENT")) {