1
0
Fork 0
mirror of synced 2024-07-09 00:06:05 +12:00

Add external schema endpoint

This commit is contained in:
Adria Navarro 2023-06-19 14:02:18 +01:00
parent dbcf7814a8
commit 7a4eb3113d
4 changed files with 24 additions and 1 deletions

View file

@ -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,
}
}

View file

@ -66,5 +66,10 @@ router
authorized(permissions.BUILDER),
datasourceController.destroy
)
.get(
"/api/datasources/:datasourceId/external-schema",
authorized(permissions.BUILDER),
datasourceController.getExternalSchema
)
export default router

View file

@ -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}`,

View file

@ -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 {