Add external schema endpoint
This commit is contained in:
parent
dbcf7814a8
commit
7a4eb3113d
|
@ -26,6 +26,7 @@ import {
|
|||
IntegrationBase,
|
||||
DatasourcePlus,
|
||||
SourceName,
|
||||
Ctx,
|
||||
} from "@budibase/types"
|
||||
import sdk from "../../sdk"
|
||||
import { builderSocket } from "../../websockets"
|
||||
|
@ -441,3 +442,18 @@ export async function query(ctx: UserCtx) {
|
|||
ctx.throw(400, err)
|
||||
}
|
||||
}
|
||||
|
||||
export async function getExternalSchema(ctx: Ctx) {
|
||||
const { datasource } = ctx.request.body
|
||||
const enrichedDatasource = await getAndMergeDatasource(datasource)
|
||||
const connector = await getConnector(enrichedDatasource)
|
||||
|
||||
if (!connector.getExternalSchema) {
|
||||
ctx.throw(400, "Datasource does not support exporting external schema")
|
||||
}
|
||||
const response = await connector.getExternalSchema()
|
||||
|
||||
ctx.body = {
|
||||
schema: response,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,5 +66,10 @@ router
|
|||
authorized(permissions.BUILDER),
|
||||
datasourceController.destroy
|
||||
)
|
||||
.get(
|
||||
"/api/datasources/:datasourceId/external-schema",
|
||||
authorized(permissions.BUILDER),
|
||||
datasourceController.getExternalSchema
|
||||
)
|
||||
|
||||
export default router
|
||||
|
|
|
@ -181,6 +181,7 @@ class PostgresIntegration extends Sql implements DatasourcePlus {
|
|||
const response: ConnectionInfo = {
|
||||
connected: false,
|
||||
}
|
||||
|
||||
try {
|
||||
await this.openConnection()
|
||||
response.connected = true
|
||||
|
@ -385,7 +386,7 @@ class PostgresIntegration extends Sql implements DatasourcePlus {
|
|||
}
|
||||
}
|
||||
|
||||
async getSchema() {
|
||||
async getExternalSchema() {
|
||||
const dumpCommandParts = [
|
||||
`user=${this.config.user}`,
|
||||
`host=${this.config.host}`,
|
||||
|
|
|
@ -140,6 +140,7 @@ export interface IntegrationBase {
|
|||
update?(query: any): Promise<any[] | any>
|
||||
delete?(query: any): Promise<any[] | any>
|
||||
testConnection?(): Promise<ConnectionInfo>
|
||||
getExternalSchema?(): Promise<string>
|
||||
}
|
||||
|
||||
export interface DatasourcePlus extends IntegrationBase {
|
||||
|
|
Loading…
Reference in New Issue