Adding API for retrieving table names.

This commit is contained in:
Michael Drury 2023-05-18 23:22:52 +01:00
parent 732ebb4f87
commit 2223027d28
3 changed files with 25 additions and 0 deletions

View File

@ -21,6 +21,7 @@ import {
CreateDatasourceRequest,
VerifyDatasourceRequest,
VerifyDatasourceResponse,
FetchTablesDatasourceResponse,
IntegrationBase,
DatasourcePlus,
} from "@budibase/types"
@ -153,6 +154,21 @@ export async function verify(
}
}
export async function tables(
ctx: UserCtx<void, FetchTablesDatasourceResponse>
) {
const datasourceId = ctx.params.datasourceId
const datasource = await sdk.datasources.get(datasourceId, { enriched: true })
const connector = (await getConnector(datasource)) as DatasourcePlus
if (!connector.getTableNames) {
ctx.throw(400, "Table name fetching not supported by datasource")
}
const tables = await connector.getTableNames()
ctx.body = {
tables,
}
}
export async function buildSchemaFromDb(ctx: UserCtx) {
const db = context.getAppDB()
const datasource = await sdk.datasources.get(ctx.params.datasourceId)

View File

@ -20,6 +20,11 @@ router
authorized(permissions.BUILDER),
datasourceController.verify
)
.get(
"/api/datasources/:datasourceId/tables",
authorized(permissions.BUILDER),
datasourceController.tables
)
.get(
"/api/datasources/:datasourceId",
authorized(

View File

@ -23,6 +23,10 @@ export interface VerifyDatasourceResponse {
error?: string
}
export interface FetchTablesDatasourceResponse {
tables: string[]
}
export interface UpdateDatasourceRequest extends Datasource {
datasource: Datasource
}