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