From 94678c925321d9ceb394d90a8fd13badfbf10417 Mon Sep 17 00:00:00 2001 From: Matthew Peveler Date: Wed, 2 Feb 2022 08:27:48 -0500 Subject: [PATCH] Allow filter to be optional to adapter methods (#37) --- src/adapters/abstract_adapter.ts | 8 ++++---- src/adapters/postgresql.ts | 8 ++++---- src/adapters/sqlite.ts | 8 ++++++-- src/adapters/sqlserver.ts | 8 ++++---- src/database.ts | 8 ++++---- 5 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/adapters/abstract_adapter.ts b/src/adapters/abstract_adapter.ts index a7d9c7f..0c2ca94 100644 --- a/src/adapters/abstract_adapter.ts +++ b/src/adapters/abstract_adapter.ts @@ -76,19 +76,19 @@ export abstract class AbstractAdapter { abstract listDatabases(filter?: DatabaseFilter): Promise; // eslint-disable-next-line @typescript-eslint/no-unused-vars - listSchemas(filter: SchemaFilter): Promise { + listSchemas(filter?: SchemaFilter): Promise { return Promise.resolve([]); } - abstract listTables(filter: SchemaFilter): Promise; + abstract listTables(filter?: SchemaFilter): Promise; // eslint-disable-next-line @typescript-eslint/no-unused-vars - listViews(filter: SchemaFilter): Promise { + listViews(filter?: SchemaFilter): Promise { return Promise.resolve([]); } // eslint-disable-next-line @typescript-eslint/no-unused-vars - listRoutines(filter: SchemaFilter): Promise { + listRoutines(filter?: SchemaFilter): Promise { return Promise.resolve([]); } diff --git a/src/adapters/postgresql.ts b/src/adapters/postgresql.ts index 2e1e6b7..adeabcb 100644 --- a/src/adapters/postgresql.ts +++ b/src/adapters/postgresql.ts @@ -147,7 +147,7 @@ export default class PostgresqlAdapter extends AbstractAdapter { return data.rows.map((row) => row.datname); } - async listTables(filter: SchemaFilter): Promise { + async listTables(filter?: SchemaFilter): Promise { const schemaFilter = buildSchemaFilter(filter, 'table_schema'); const sql = ` SELECT @@ -164,7 +164,7 @@ export default class PostgresqlAdapter extends AbstractAdapter { return data.rows; } - async listViews(filter: SchemaFilter): Promise { + async listViews(filter?: SchemaFilter): Promise { const schemaFilter = buildSchemaFilter(filter, 'table_schema'); const sql = ` SELECT @@ -180,7 +180,7 @@ export default class PostgresqlAdapter extends AbstractAdapter { return data.rows; } - async listRoutines(filter: SchemaFilter): Promise { + async listRoutines(filter?: SchemaFilter): Promise { const schemaFilter = buildSchemaFilter(filter, 'routine_schema'); const sql = ` SELECT @@ -256,7 +256,7 @@ export default class PostgresqlAdapter extends AbstractAdapter { return data.rows.map((row) => row.index_name); } - async listSchemas(filter: SchemaFilter): Promise { + async listSchemas(filter?: SchemaFilter): Promise { const schemaFilter = buildSchemaFilter(filter); const sql = ` SELECT schema_name diff --git a/src/adapters/sqlite.ts b/src/adapters/sqlite.ts index bd5eed2..c4bf86c 100644 --- a/src/adapters/sqlite.ts +++ b/src/adapters/sqlite.ts @@ -18,6 +18,7 @@ import type { } from './abstract_adapter'; import type { Server } from '../server'; import type { Database } from '../database'; +import { SchemaFilter } from '..'; const logger = createLogger('db:clients:sqlite'); @@ -116,7 +117,10 @@ export default class SqliteAdapter extends AbstractAdapter { }); } - async listTables(filter: unknown, connection?: sqlite3.Database): Promise { + async listTables( + filter?: SchemaFilter, + connection?: sqlite3.Database, + ): Promise { const sql = ` SELECT name FROM sqlite_master @@ -207,7 +211,7 @@ export default class SqliteAdapter extends AbstractAdapter { async truncateAllTables(): Promise { await this.runWithConnection(async (connection) => { - const tables = await this.listTables(null, connection); + const tables = await this.listTables(undefined, connection); const truncateAll = tables .map( diff --git a/src/adapters/sqlserver.ts b/src/adapters/sqlserver.ts index 671c86a..c6e90e2 100644 --- a/src/adapters/sqlserver.ts +++ b/src/adapters/sqlserver.ts @@ -131,7 +131,7 @@ export default class SqlServerAdapter extends AbstractAdapter { return data.map((row) => row.name); } - async listSchemas(filter: SchemaFilter): Promise { + async listSchemas(filter?: SchemaFilter): Promise { const schemaFilter = buildSchemaFilter(filter); const sql = ` SELECT schema_name @@ -145,7 +145,7 @@ export default class SqlServerAdapter extends AbstractAdapter { return data.map((row) => row.schema_name); } - async listTables(filter: SchemaFilter): Promise { + async listTables(filter?: SchemaFilter): Promise { const schemaFilter = buildSchemaFilter(filter, 'table_schema'); const sql = ` SELECT @@ -165,7 +165,7 @@ export default class SqlServerAdapter extends AbstractAdapter { })); } - async listViews(filter: SchemaFilter): Promise { + async listViews(filter?: SchemaFilter): Promise { const schemaFilter = buildSchemaFilter(filter, 'table_schema'); const sql = ` SELECT @@ -184,7 +184,7 @@ export default class SqlServerAdapter extends AbstractAdapter { })); } - async listRoutines(filter: SchemaFilter): Promise { + async listRoutines(filter?: SchemaFilter): Promise { const schemaFilter = buildSchemaFilter(filter, 'routine_schema'); const sql = ` SELECT diff --git a/src/database.ts b/src/database.ts index 8004aa1..c201053 100644 --- a/src/database.ts +++ b/src/database.ts @@ -106,23 +106,23 @@ export class Database { return (this.connection).listDatabases(filter); } - listSchemas(filter: SchemaFilter): Promise { + listSchemas(filter?: SchemaFilter): Promise { this.checkIsConnected(); return (this.connection).listSchemas(filter); } - listTables(filter: SchemaFilter): Promise<{ name: string }[]> { + listTables(filter?: SchemaFilter): Promise<{ name: string }[]> { this.checkIsConnected(); return (this.connection).listTables(filter); } - listViews(filter: SchemaFilter): Promise<{ name: string }[]> { + listViews(filter?: SchemaFilter): Promise<{ name: string }[]> { this.checkIsConnected(); return (this.connection).listViews(filter); } listRoutines( - filter: SchemaFilter, + filter?: SchemaFilter, ): Promise< { schema?: string;