1
0
Fork 0
mirror of synced 2024-06-29 19:41:03 +12:00

Fix for issue with aliasing not quite working as expected when interacting with very old datasources, there is a flag 'isSQL' which was not set in old versions, this is now set when retrieving datasources to avoid issues with it being unset.

This commit is contained in:
mike12345567 2024-03-19 14:48:56 +00:00
parent 0f245d4b38
commit 5c01ba0095
2 changed files with 16 additions and 6 deletions

View file

@ -30,9 +30,15 @@ import {
} from "../../../db/utils"
import sdk from "../../index"
import { setupCreationAuth as googleSetupCreationAuth } from "../../../integrations/googlesheets"
import { helpers } from "@budibase/shared-core"
const ENV_VAR_PREFIX = "env."
function addDatasourceFlags(datasource: Datasource) {
datasource.isSQL = helpers.isSQL(datasource)
return datasource
}
export async function fetch(opts?: {
enriched: boolean
}): Promise<Datasource[]> {
@ -56,7 +62,7 @@ export async function fetch(opts?: {
} as Datasource
// Get external datasources
const datasources = (
let datasources = (
await db.allDocs<Datasource>(
getDatasourceParams(null, {
include_docs: true,
@ -75,6 +81,7 @@ export async function fetch(opts?: {
}
}
datasources = datasources.map(datasource => addDatasourceFlags(datasource))
if (opts?.enriched) {
const envVars = await getEnvironmentVariables()
const promises = datasources.map(datasource =>
@ -150,6 +157,7 @@ async function enrichDatasourceWithValues(
}
export async function enrich(datasource: Datasource) {
datasource = addDatasourceFlags(datasource)
const { datasource: response } = await enrichDatasourceWithValues(datasource)
return response
}
@ -159,7 +167,8 @@ export async function get(
opts?: { enriched: boolean }
): Promise<Datasource> {
const appDb = context.getAppDB()
const datasource = await appDb.get<Datasource>(datasourceId)
let datasource = await appDb.get<Datasource>(datasourceId)
datasource = addDatasourceFlags(datasource)
if (opts?.enriched) {
return (await enrichDatasourceWithValues(datasource)).datasource
} else {
@ -271,13 +280,14 @@ export function mergeConfigs(update: Datasource, old: Datasource) {
export async function getExternalDatasources(): Promise<Datasource[]> {
const db = context.getAppDB()
const externalDatasources = await db.allDocs<Datasource>(
let dsResponse = await db.allDocs<Datasource>(
getDatasourcePlusParams(undefined, {
include_docs: true,
})
)
return externalDatasources.rows.map(r => r.doc!)
const externalDatasources = dsResponse.rows.map(r => r.doc!)
return externalDatasources.map(datasource => addDatasourceFlags(datasource))
}
export async function save(

View file

@ -14,7 +14,7 @@ import { makeExternalQuery } from "../../../integrations/base/query"
import { Format } from "../../../api/controllers/view/exporters"
import sdk from "../.."
import { isRelationshipColumn } from "../../../db/utils"
import { SqlClient } from "../../../integrations/utils"
import { SqlClient, isSQL } from "../../../integrations/utils"
const SQL_CLIENT_SOURCE_MAP: Record<SourceName, SqlClient | undefined> = {
[SourceName.POSTGRES]: SqlClient.POSTGRES,
@ -37,7 +37,7 @@ const SQL_CLIENT_SOURCE_MAP: Record<SourceName, SqlClient | undefined> = {
}
export function getSQLClient(datasource: Datasource): SqlClient {
if (!datasource.isSQL) {
if (!isSQL(datasource)) {
throw new Error("Cannot get SQL Client for non-SQL datasource")
}
const lookup = SQL_CLIENT_SOURCE_MAP[datasource.source]