Adding API for retrieving table names.
This commit is contained in:
parent
732ebb4f87
commit
2223027d28
|
@ -21,6 +21,7 @@ import {
|
||||||
CreateDatasourceRequest,
|
CreateDatasourceRequest,
|
||||||
VerifyDatasourceRequest,
|
VerifyDatasourceRequest,
|
||||||
VerifyDatasourceResponse,
|
VerifyDatasourceResponse,
|
||||||
|
FetchTablesDatasourceResponse,
|
||||||
IntegrationBase,
|
IntegrationBase,
|
||||||
DatasourcePlus,
|
DatasourcePlus,
|
||||||
} from "@budibase/types"
|
} 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) {
|
export async function buildSchemaFromDb(ctx: UserCtx) {
|
||||||
const db = context.getAppDB()
|
const db = context.getAppDB()
|
||||||
const datasource = await sdk.datasources.get(ctx.params.datasourceId)
|
const datasource = await sdk.datasources.get(ctx.params.datasourceId)
|
||||||
|
|
|
@ -20,6 +20,11 @@ router
|
||||||
authorized(permissions.BUILDER),
|
authorized(permissions.BUILDER),
|
||||||
datasourceController.verify
|
datasourceController.verify
|
||||||
)
|
)
|
||||||
|
.get(
|
||||||
|
"/api/datasources/:datasourceId/tables",
|
||||||
|
authorized(permissions.BUILDER),
|
||||||
|
datasourceController.tables
|
||||||
|
)
|
||||||
.get(
|
.get(
|
||||||
"/api/datasources/:datasourceId",
|
"/api/datasources/:datasourceId",
|
||||||
authorized(
|
authorized(
|
||||||
|
|
|
@ -23,6 +23,10 @@ export interface VerifyDatasourceResponse {
|
||||||
error?: string
|
error?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface FetchTablesDatasourceResponse {
|
||||||
|
tables: string[]
|
||||||
|
}
|
||||||
|
|
||||||
export interface UpdateDatasourceRequest extends Datasource {
|
export interface UpdateDatasourceRequest extends Datasource {
|
||||||
datasource: Datasource
|
datasource: Datasource
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue