Handling aliasing in column conversions.
This commit is contained in:
parent
6a0e46a0a6
commit
8d7267691d
|
@ -699,19 +699,18 @@ class SqlQueryBuilder extends SqlTableQueryBuilder {
|
||||||
|
|
||||||
convertJsonStringColumns(
|
convertJsonStringColumns(
|
||||||
table: Table,
|
table: Table,
|
||||||
results: Record<string, any>[]
|
results: Record<string, any>[],
|
||||||
|
aliases?: Record<string, string>
|
||||||
): Record<string, any>[] {
|
): Record<string, any>[] {
|
||||||
for (const [name, field] of Object.entries(table.schema)) {
|
for (const [name, field] of Object.entries(table.schema)) {
|
||||||
if (!this._isJsonColumn(field)) {
|
if (!this._isJsonColumn(field)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
const tableName = aliases?.[table.name] || table.name
|
||||||
|
const fullName = `${tableName}.${name}`
|
||||||
for (let row of results) {
|
for (let row of results) {
|
||||||
const columnNames = Object.keys(row)
|
if (typeof row[fullName] === "string") {
|
||||||
const fullColumnName = columnNames.find(
|
row[fullName] = JSON.parse(row[fullName])
|
||||||
column => column.includes(`.${name}`) || column === name
|
|
||||||
)
|
|
||||||
if (fullColumnName && typeof row[fullColumnName] === "string") {
|
|
||||||
row[fullColumnName] = JSON.parse(row[fullColumnName])
|
|
||||||
}
|
}
|
||||||
if (typeof row[name] === "string") {
|
if (typeof row[name] === "string") {
|
||||||
row[name] = JSON.parse(row[name])
|
row[name] = JSON.parse(row[name])
|
||||||
|
|
|
@ -506,7 +506,11 @@ class SqlServerIntegration extends Sql implements DatasourcePlus {
|
||||||
const queryFn = (query: any, op: string) => this.internalQuery(query, op)
|
const queryFn = (query: any, op: string) => this.internalQuery(query, op)
|
||||||
const processFn = (result: any) => {
|
const processFn = (result: any) => {
|
||||||
if (json?.meta?.table && result.recordset) {
|
if (json?.meta?.table && result.recordset) {
|
||||||
return this.convertJsonStringColumns(json.meta.table, result.recordset)
|
return this.convertJsonStringColumns(
|
||||||
|
json.meta.table,
|
||||||
|
result.recordset,
|
||||||
|
json.tableAliases
|
||||||
|
)
|
||||||
} else if (result.recordset) {
|
} else if (result.recordset) {
|
||||||
return result.recordset
|
return result.recordset
|
||||||
}
|
}
|
||||||
|
|
|
@ -390,7 +390,11 @@ class MySQLIntegration extends Sql implements DatasourcePlus {
|
||||||
this.internalQuery(query, { connect: false, disableCoercion: true })
|
this.internalQuery(query, { connect: false, disableCoercion: true })
|
||||||
const processFn = (result: any) => {
|
const processFn = (result: any) => {
|
||||||
if (json?.meta?.table && Array.isArray(result)) {
|
if (json?.meta?.table && Array.isArray(result)) {
|
||||||
return this.convertJsonStringColumns(json.meta.table, result)
|
return this.convertJsonStringColumns(
|
||||||
|
json.meta.table,
|
||||||
|
result,
|
||||||
|
json.tableAliases
|
||||||
|
)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue