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:
parent
0f245d4b38
commit
5c01ba0095
|
@ -30,9 +30,15 @@ import {
|
||||||
} from "../../../db/utils"
|
} from "../../../db/utils"
|
||||||
import sdk from "../../index"
|
import sdk from "../../index"
|
||||||
import { setupCreationAuth as googleSetupCreationAuth } from "../../../integrations/googlesheets"
|
import { setupCreationAuth as googleSetupCreationAuth } from "../../../integrations/googlesheets"
|
||||||
|
import { helpers } from "@budibase/shared-core"
|
||||||
|
|
||||||
const ENV_VAR_PREFIX = "env."
|
const ENV_VAR_PREFIX = "env."
|
||||||
|
|
||||||
|
function addDatasourceFlags(datasource: Datasource) {
|
||||||
|
datasource.isSQL = helpers.isSQL(datasource)
|
||||||
|
return datasource
|
||||||
|
}
|
||||||
|
|
||||||
export async function fetch(opts?: {
|
export async function fetch(opts?: {
|
||||||
enriched: boolean
|
enriched: boolean
|
||||||
}): Promise<Datasource[]> {
|
}): Promise<Datasource[]> {
|
||||||
|
@ -56,7 +62,7 @@ export async function fetch(opts?: {
|
||||||
} as Datasource
|
} as Datasource
|
||||||
|
|
||||||
// Get external datasources
|
// Get external datasources
|
||||||
const datasources = (
|
let datasources = (
|
||||||
await db.allDocs<Datasource>(
|
await db.allDocs<Datasource>(
|
||||||
getDatasourceParams(null, {
|
getDatasourceParams(null, {
|
||||||
include_docs: true,
|
include_docs: true,
|
||||||
|
@ -75,6 +81,7 @@ export async function fetch(opts?: {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
datasources = datasources.map(datasource => addDatasourceFlags(datasource))
|
||||||
if (opts?.enriched) {
|
if (opts?.enriched) {
|
||||||
const envVars = await getEnvironmentVariables()
|
const envVars = await getEnvironmentVariables()
|
||||||
const promises = datasources.map(datasource =>
|
const promises = datasources.map(datasource =>
|
||||||
|
@ -150,6 +157,7 @@ async function enrichDatasourceWithValues(
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function enrich(datasource: Datasource) {
|
export async function enrich(datasource: Datasource) {
|
||||||
|
datasource = addDatasourceFlags(datasource)
|
||||||
const { datasource: response } = await enrichDatasourceWithValues(datasource)
|
const { datasource: response } = await enrichDatasourceWithValues(datasource)
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
@ -159,7 +167,8 @@ export async function get(
|
||||||
opts?: { enriched: boolean }
|
opts?: { enriched: boolean }
|
||||||
): Promise<Datasource> {
|
): Promise<Datasource> {
|
||||||
const appDb = context.getAppDB()
|
const appDb = context.getAppDB()
|
||||||
const datasource = await appDb.get<Datasource>(datasourceId)
|
let datasource = await appDb.get<Datasource>(datasourceId)
|
||||||
|
datasource = addDatasourceFlags(datasource)
|
||||||
if (opts?.enriched) {
|
if (opts?.enriched) {
|
||||||
return (await enrichDatasourceWithValues(datasource)).datasource
|
return (await enrichDatasourceWithValues(datasource)).datasource
|
||||||
} else {
|
} else {
|
||||||
|
@ -271,13 +280,14 @@ export function mergeConfigs(update: Datasource, old: Datasource) {
|
||||||
export async function getExternalDatasources(): Promise<Datasource[]> {
|
export async function getExternalDatasources(): Promise<Datasource[]> {
|
||||||
const db = context.getAppDB()
|
const db = context.getAppDB()
|
||||||
|
|
||||||
const externalDatasources = await db.allDocs<Datasource>(
|
let dsResponse = await db.allDocs<Datasource>(
|
||||||
getDatasourcePlusParams(undefined, {
|
getDatasourcePlusParams(undefined, {
|
||||||
include_docs: true,
|
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(
|
export async function save(
|
||||||
|
|
|
@ -14,7 +14,7 @@ import { makeExternalQuery } from "../../../integrations/base/query"
|
||||||
import { Format } from "../../../api/controllers/view/exporters"
|
import { Format } from "../../../api/controllers/view/exporters"
|
||||||
import sdk from "../.."
|
import sdk from "../.."
|
||||||
import { isRelationshipColumn } from "../../../db/utils"
|
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> = {
|
const SQL_CLIENT_SOURCE_MAP: Record<SourceName, SqlClient | undefined> = {
|
||||||
[SourceName.POSTGRES]: SqlClient.POSTGRES,
|
[SourceName.POSTGRES]: SqlClient.POSTGRES,
|
||||||
|
@ -37,7 +37,7 @@ const SQL_CLIENT_SOURCE_MAP: Record<SourceName, SqlClient | undefined> = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getSQLClient(datasource: Datasource): SqlClient {
|
export function getSQLClient(datasource: Datasource): SqlClient {
|
||||||
if (!datasource.isSQL) {
|
if (!isSQL(datasource)) {
|
||||||
throw new Error("Cannot get SQL Client for non-SQL datasource")
|
throw new Error("Cannot get SQL Client for non-SQL datasource")
|
||||||
}
|
}
|
||||||
const lookup = SQL_CLIENT_SOURCE_MAP[datasource.source]
|
const lookup = SQL_CLIENT_SOURCE_MAP[datasource.source]
|
||||||
|
|
Loading…
Reference in New Issue