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