Skip to content

Commit

Permalink
Allow filter to be optional to adapter methods (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterOdin authored Feb 2, 2022
1 parent a3263a9 commit 94678c9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
8 changes: 4 additions & 4 deletions src/adapters/abstract_adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,19 @@ export abstract class AbstractAdapter {
abstract listDatabases(filter?: DatabaseFilter): Promise<string[]>;

// eslint-disable-next-line @typescript-eslint/no-unused-vars
listSchemas(filter: SchemaFilter): Promise<string[]> {
listSchemas(filter?: SchemaFilter): Promise<string[]> {
return Promise.resolve([]);
}

abstract listTables(filter: SchemaFilter): Promise<ListTableResult[]>;
abstract listTables(filter?: SchemaFilter): Promise<ListTableResult[]>;

// eslint-disable-next-line @typescript-eslint/no-unused-vars
listViews(filter: SchemaFilter): Promise<ListViewResult[]> {
listViews(filter?: SchemaFilter): Promise<ListViewResult[]> {
return Promise.resolve([]);
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
listRoutines(filter: SchemaFilter): Promise<ListRoutineResult[]> {
listRoutines(filter?: SchemaFilter): Promise<ListRoutineResult[]> {
return Promise.resolve([]);
}

Expand Down
8 changes: 4 additions & 4 deletions src/adapters/postgresql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export default class PostgresqlAdapter extends AbstractAdapter {
return data.rows.map((row) => row.datname);
}

async listTables(filter: SchemaFilter): Promise<ListTableResult[]> {
async listTables(filter?: SchemaFilter): Promise<ListTableResult[]> {
const schemaFilter = buildSchemaFilter(filter, 'table_schema');
const sql = `
SELECT
Expand All @@ -164,7 +164,7 @@ export default class PostgresqlAdapter extends AbstractAdapter {
return data.rows;
}

async listViews(filter: SchemaFilter): Promise<ListViewResult[]> {
async listViews(filter?: SchemaFilter): Promise<ListViewResult[]> {
const schemaFilter = buildSchemaFilter(filter, 'table_schema');
const sql = `
SELECT
Expand All @@ -180,7 +180,7 @@ export default class PostgresqlAdapter extends AbstractAdapter {
return data.rows;
}

async listRoutines(filter: SchemaFilter): Promise<ListRoutineResult[]> {
async listRoutines(filter?: SchemaFilter): Promise<ListRoutineResult[]> {
const schemaFilter = buildSchemaFilter(filter, 'routine_schema');
const sql = `
SELECT
Expand Down Expand Up @@ -256,7 +256,7 @@ export default class PostgresqlAdapter extends AbstractAdapter {
return data.rows.map((row) => row.index_name);
}

async listSchemas(filter: SchemaFilter): Promise<string[]> {
async listSchemas(filter?: SchemaFilter): Promise<string[]> {
const schemaFilter = buildSchemaFilter(filter);
const sql = `
SELECT schema_name
Expand Down
8 changes: 6 additions & 2 deletions src/adapters/sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -116,7 +117,10 @@ export default class SqliteAdapter extends AbstractAdapter {
});
}

async listTables(filter: unknown, connection?: sqlite3.Database): Promise<ListTableResult[]> {
async listTables(
filter?: SchemaFilter,
connection?: sqlite3.Database,
): Promise<ListTableResult[]> {
const sql = `
SELECT name
FROM sqlite_master
Expand Down Expand Up @@ -207,7 +211,7 @@ export default class SqliteAdapter extends AbstractAdapter {

async truncateAllTables(): Promise<void> {
await this.runWithConnection(async (connection) => {
const tables = await this.listTables(null, connection);
const tables = await this.listTables(undefined, connection);

const truncateAll = tables
.map(
Expand Down
8 changes: 4 additions & 4 deletions src/adapters/sqlserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export default class SqlServerAdapter extends AbstractAdapter {
return data.map((row) => row.name);
}

async listSchemas(filter: SchemaFilter): Promise<string[]> {
async listSchemas(filter?: SchemaFilter): Promise<string[]> {
const schemaFilter = buildSchemaFilter(filter);
const sql = `
SELECT schema_name
Expand All @@ -145,7 +145,7 @@ export default class SqlServerAdapter extends AbstractAdapter {
return data.map((row) => row.schema_name);
}

async listTables(filter: SchemaFilter): Promise<ListTableResult[]> {
async listTables(filter?: SchemaFilter): Promise<ListTableResult[]> {
const schemaFilter = buildSchemaFilter(filter, 'table_schema');
const sql = `
SELECT
Expand All @@ -165,7 +165,7 @@ export default class SqlServerAdapter extends AbstractAdapter {
}));
}

async listViews(filter: SchemaFilter): Promise<ListViewResult[]> {
async listViews(filter?: SchemaFilter): Promise<ListViewResult[]> {
const schemaFilter = buildSchemaFilter(filter, 'table_schema');
const sql = `
SELECT
Expand All @@ -184,7 +184,7 @@ export default class SqlServerAdapter extends AbstractAdapter {
}));
}

async listRoutines(filter: SchemaFilter): Promise<ListRoutineResult[]> {
async listRoutines(filter?: SchemaFilter): Promise<ListRoutineResult[]> {
const schemaFilter = buildSchemaFilter(filter, 'routine_schema');
const sql = `
SELECT
Expand Down
8 changes: 4 additions & 4 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,23 @@ export class Database {
return (<AbstractAdapter>this.connection).listDatabases(filter);
}

listSchemas(filter: SchemaFilter): Promise<string[]> {
listSchemas(filter?: SchemaFilter): Promise<string[]> {
this.checkIsConnected();
return (<AbstractAdapter>this.connection).listSchemas(filter);
}

listTables(filter: SchemaFilter): Promise<{ name: string }[]> {
listTables(filter?: SchemaFilter): Promise<{ name: string }[]> {
this.checkIsConnected();
return (<AbstractAdapter>this.connection).listTables(filter);
}

listViews(filter: SchemaFilter): Promise<{ name: string }[]> {
listViews(filter?: SchemaFilter): Promise<{ name: string }[]> {
this.checkIsConnected();
return (<AbstractAdapter>this.connection).listViews(filter);
}

listRoutines(
filter: SchemaFilter,
filter?: SchemaFilter,
): Promise<
{
schema?: string;
Expand Down

0 comments on commit 94678c9

Please sign in to comment.