diff --git a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/PlusConfigForm.svelte b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/PlusConfigForm.svelte index cd19523476..b81e818d5f 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/PlusConfigForm.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/PlusConfigForm.svelte @@ -8,6 +8,7 @@ notifications, Modal, Table, + Toggle, } from "@budibase/bbui" import { datasources, integrations, tables } from "stores/backend" import CreateEditRelationship from "components/backend/Datasources/CreateEditRelationship.svelte" @@ -15,6 +16,7 @@ import ArrayRenderer from "components/common/renderers/ArrayRenderer.svelte" import ConfirmDialog from "components/common/ConfirmDialog.svelte" import { goto } from "@roxi/routify" + import ValuesList from "components/common/ValuesList.svelte" export let datasource export let save @@ -31,6 +33,8 @@ let createExternalTableModal let selectedFromRelationship, selectedToRelationship let confirmDialog + let specificTables = null + let requireSpecificTables = false $: integration = datasource && $integrations[datasource.source] $: plusTables = datasource?.plus @@ -87,7 +91,7 @@ async function updateDatasourceSchema() { try { - await datasources.updateSchema(datasource) + await datasources.updateSchema(datasource, specificTables) notifications.success(`Datasource ${name} tables updated successfully.`) await tables.fetch() } catch (error) { @@ -150,6 +154,19 @@ warning={false} title="Confirm table fetch" > + { + requireSpecificTables = e.detail + specificTables = null + }} + thin + text="Fetch listed tables only (one per line)" + /> + {#if requireSpecificTables} + + {/if} +
If you have fetched tables from this database before, this action may overwrite any changes you made after your initial fetch. diff --git a/packages/builder/src/stores/backend/datasources.js b/packages/builder/src/stores/backend/datasources.js index 2423394c6a..07aeab1921 100644 --- a/packages/builder/src/stores/backend/datasources.js +++ b/packages/builder/src/stores/backend/datasources.js @@ -62,8 +62,11 @@ export function createDatasourcesStore() { unselect: () => { update(state => ({ ...state, selected: null })) }, - updateSchema: async datasource => { - const response = await API.buildDatasourceSchema(datasource?._id) + updateSchema: async (datasource, tablesFilter) => { + const response = await API.buildDatasourceSchema({ + datasourceId: datasource?._id, + tablesFilter, + }) return await updateDatasource(response) }, save: async (body, fetchSchema = false) => { diff --git a/packages/frontend-core/src/api/datasources.js b/packages/frontend-core/src/api/datasources.js index ff72fbf25b..eda7b3c860 100644 --- a/packages/frontend-core/src/api/datasources.js +++ b/packages/frontend-core/src/api/datasources.js @@ -11,10 +11,14 @@ export const buildDatasourceEndpoints = API => ({ /** * Prompts the server to build the schema for a datasource. * @param datasourceId the datasource ID to build the schema for + * @param tablesFilter list of specific table names to be build the schema */ - buildDatasourceSchema: async datasourceId => { + buildDatasourceSchema: async ({ datasourceId, tablesFilter }) => { return await API.post({ url: `/api/datasources/${datasourceId}/schema`, + body: { + tablesFilter, + }, }) }, diff --git a/packages/server/src/api/controllers/datasource.js b/packages/server/src/api/controllers/datasource.js index 36d345912e..4fafaa546c 100644 --- a/packages/server/src/api/controllers/datasource.js +++ b/packages/server/src/api/controllers/datasource.js @@ -50,9 +50,23 @@ exports.fetch = async function (ctx) { exports.buildSchemaFromDb = async function (ctx) { const db = getAppDB() const datasource = await db.get(ctx.params.datasourceId) + const tablesFilter = ctx.request.body.tablesFilter - const { tables, error } = await buildSchemaHelper(datasource) - datasource.entities = tables + let { tables, error } = await buildSchemaHelper(datasource) + if (tablesFilter) { + if (!datasource.entities) { + datasource.entities = {} + } + for (let key in tables) { + if ( + tablesFilter.some(filter => filter.toLowerCase() === key.toLowerCase()) + ) { + datasource.entities[key] = tables[key] + } + } + } else { + datasource.entities = tables + } const dbResp = await db.put(datasource) datasource._rev = dbResp.rev @@ -223,10 +237,9 @@ const buildSchemaHelper = async datasource => { // Connect to the DB and build the schema const connector = new Connector(datasource.config) await connector.buildSchema(datasource._id, datasource.entities) - datasource.entities = connector.tables // make sure they all have a display name selected - for (let entity of Object.values(datasource.entities)) { + for (let entity of Object.values(datasource.entities ?? {})) { if (entity.primaryDisplay) { continue }