Skip to content
This repository has been archived by the owner on Oct 10, 2022. It is now read-only.

Commit

Permalink
drivers query IN
Browse files Browse the repository at this point in the history
  • Loading branch information
pc3b3r committed Aug 20, 2020
1 parent defe6fd commit b1335ee
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 20 deletions.
13 changes: 9 additions & 4 deletions src/drivers/MssqlDriver.ts
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
13 changes: 9 additions & 4 deletions src/drivers/MysqlDriver.ts
Expand Up @@ -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;
Expand All @@ -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;
};

Expand Down
13 changes: 9 additions & 4 deletions src/drivers/OracleDriver.ts
Expand Up @@ -41,19 +41,24 @@ 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<{
TABLE_SCHEMA: string;
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;
Expand Down
13 changes: 9 additions & 4 deletions src/drivers/PostgresDriver.ts
Expand Up @@ -40,19 +40,24 @@ 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;
TABLE_NAME: string;
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;
Expand Down
13 changes: 9 additions & 4 deletions src/drivers/SqliteDriver.ts
Expand Up @@ -47,16 +47,21 @@ export default class SqliteDriver extends AbstractDriver {
public async GetAllTables(
schema: string,
dbNames: string,
tableNames: string[]
notInTables: string[],
inTables: string[]
): Promise<Entity[]> {
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")) {
Expand Down

0 comments on commit b1335ee

Please sign in to comment.