Adding API for retrieving table names.
This commit is contained in:
parent
732ebb4f87
commit
2223027d28
|
@ -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)
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -23,6 +23,10 @@ export interface VerifyDatasourceResponse {
|
|||
error?: string
|
||||
}
|
||||
|
||||
export interface FetchTablesDatasourceResponse {
|
||||
tables: string[]
|
||||
}
|
||||
|
||||
export interface UpdateDatasourceRequest extends Datasource {
|
||||
datasource: Datasource
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue