1
0
Fork 0
mirror of synced 2024-07-06 15:00:49 +12:00

Adding SQL export functionality and settings tab for SQL databases.

This commit is contained in:
mike12345567 2023-06-28 16:52:45 +01:00
parent 25d0f3f518
commit d8fae3a348
6 changed files with 64 additions and 4 deletions

View file

@ -0,0 +1,38 @@
<script>
import { Body, Button, Layout, notifications } from "@budibase/bbui"
import Panel from "./Panel.svelte"
import { API } from "api"
import { downloadText } from "@budibase/frontend-core"
export let datasource
async function download() {
if (!datasource?._id) {
notifications.error("Datasource invalid")
}
const response = await API.fetchExternalSchema(datasource._id)
downloadText(`${datasource.name}-dump.sql`, response.schema)
}
</script>
<Panel>
<div class="main">
<Layout gap="S" noPadding>
<Body size="L" weight="700">Troubleshooting</Body>
<Body>Download your schema to share with the Budibase team</Body>
<div class="download-button">
<Button cta on:click={download}>Download</Button>
</div>
</Layout>
</div>
</Panel>
<style>
.main {
margin-top: calc(var(--spacing-l) * -1);
}
.download-button {
padding-top: var(--spacing-s);
}
</style>

View file

@ -10,6 +10,7 @@
import RestAuthenticationPanel from "./_components/panels/Authentication/index.svelte"
import RestVariablesPanel from "./_components/panels/Variables/index.svelte"
import PromptQueryModal from "./_components/PromptQueryModal.svelte"
import SettingsPanel from "./_components/panels/Settings.svelte"
import { helpers } from "@budibase/shared-core"
let selectedPanel = null
@ -88,7 +89,7 @@
{:else if selectedPanel === "Variables"}
<RestVariablesPanel {datasource} />
{:else if selectedPanel === "Settings"}
<Body>Settings</Body>
<SettingsPanel {datasource} />
{:else}
<Body>Something went wrong</Body>
{/if}

View file

@ -83,4 +83,10 @@ export const buildDatasourceEndpoints = API => ({
body: { datasource },
})
},
fetchExternalSchema: async datasourceId => {
return await API.get({
url: `/api/datasources/${datasourceId}/schema/external`,
})
},
})

View file

@ -0,0 +1,13 @@
export function downloadText(filename, text) {
if (typeof text === "object") {
text = JSON.stringify(text)
}
const blob = new Blob([text], { type: "plain/text" })
const url = URL.createObjectURL(blob)
const link = document.createElement("a")
link.href = url
link.download = filename
link.click()
URL.revokeObjectURL(url)
}

View file

@ -5,3 +5,4 @@ export * as RoleUtils from "./roles"
export * as Utils from "./utils"
export { memo, derivedMemo } from "./memo"
export { createWebsocket } from "./websocket"
export { downloadText } from "./download"

View file

@ -427,8 +427,8 @@ export async function destroy(ctx: UserCtx) {
}
export async function find(ctx: UserCtx) {
const database = context.getAppDB()
const datasource = await database.get(ctx.params.datasourceId)
const db = context.getAppDB()
const datasource = await db.get(ctx.params.datasourceId)
ctx.body = await sdk.datasources.removeSecretSingle(datasource)
}
@ -443,7 +443,8 @@ export async function query(ctx: UserCtx) {
}
export async function getExternalSchema(ctx: UserCtx) {
const { datasource } = ctx.request.body
const db = context.getAppDB()
const datasource = await db.get(ctx.params.datasourceId)
const enrichedDatasource = await getAndMergeDatasource(datasource)
const connector = await getConnector(enrichedDatasource)