8000 fix: support schemas query param for listing tables · joeally/postgres-meta@95992c9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 95992c9

Browse files
committed
fix: support schemas query param for listing tables
1 parent f14c40f commit 95992c9

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/lib/PostgresMetaTables.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,19 @@ export default class PostgresMetaTables {
1313

1414
async list({
1515
includeSystemSchemas = false,
16+
schemas,
1617
limit,
1718
offset,
1819
}: {
1920
includeSystemSchemas?: boolean
21+
schemas?: string[]
2022
limit?: number
2123
offset?: number
2224
} = {}): Promise<PostgresMetaResult<PostgresTable[]>> {
2325
let sql = enrichedTablesSql
24-
if (!includeSystemSchemas) {
26+
if (schemas) {
27+
sql = `${sql} WHERE (schema IN (${schemas.map(literal).join(',')}))`
28+
} else if (!includeSystemSchemas) {
2529
sql = `${sql} WHERE NOT (schema IN (${DEFAULT_SYSTEM_SCHEMAS.map(literal).join(',')}))`
2630
}
2731
if (limit) {

src/server/routes/tables.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ export default async (fastify: FastifyInstance) => {
88
Headers: { pg: string }
99
Querystring: {
1010
include_system_schemas?: string
11+
schemas?: string[]
1112
limit?: number
1213
offset?: number
1314
}
1415
}>('/', async (request, reply) => {
1516
const connectionString = request.headers.pg
1617
const includeSystemSchemas = request.query.include_system_schemas === 'true'
17-
const limit = request.query.limit
18-
const offset = request.query.offset
18+
const { schemas, limit, offset } = request.query
1919

2020
const pgMeta = new PostgresMeta({ ...DEFAULT_POOL_CONFIG, connectionString })
21-
const { data, error } = await pgMeta.tables.list({ includeSystemSchemas, limit, offset })
21+
const { data, error } = await pgMeta.tables.list({ includeSystemSchemas, schemas, limit, offset })
2222
await pgMeta.end()
2323
if (error) {
2424
request.log.error({ error, request: extractRequestForLogging(request) })

0 commit comments

Comments
 (0)
0