Some work to correctly handle JSON columns from SQS as well.
This commit is contained in:
parent
90d646facb
commit
0c28d05d40
3 changed files with 16 additions and 17 deletions
|
@ -768,11 +768,11 @@ class SqlQueryBuilder extends SqlTableQueryBuilder {
|
|||
return results.length ? results : [{ [operation.toLowerCase()]: true }]
|
||||
}
|
||||
|
||||
convertJsonStringColumns(
|
||||
convertJsonStringColumns<T extends Record<string, any>>(
|
||||
table: Table,
|
||||
results: Record<string, any>[],
|
||||
results: T[],
|
||||
aliases?: Record<string, string>
|
||||
): Record<string, any>[] {
|
||||
): T[] {
|
||||
const tableName = getTableName(table)
|
||||
for (const [name, field] of Object.entries(table.schema)) {
|
||||
if (!this._isJsonColumn(field)) {
|
||||
|
@ -781,11 +781,11 @@ class SqlQueryBuilder extends SqlTableQueryBuilder {
|
|||
const aliasedTableName = (tableName && aliases?.[tableName]) || tableName
|
||||
const fullName = `${aliasedTableName}.${name}`
|
||||
for (let row of results) {
|
||||
if (typeof row[fullName] === "string") {
|
||||
row[fullName] = JSON.parse(row[fullName])
|
||||
if (typeof row[fullName as keyof T] === "string") {
|
||||
row[fullName as keyof T] = JSON.parse(row[fullName])
|
||||
}
|
||||
if (typeof row[name] === "string") {
|
||||
row[name] = JSON.parse(row[name])
|
||||
if (typeof row[name as keyof T] === "string") {
|
||||
row[name as keyof T] = JSON.parse(row[name])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 58338686c65024eb4140bb53965b618d9d647ec0
|
||||
Subproject commit 2b023157c53adf97bb4f8d4df61cf07c4ad13b07
|
|
@ -29,6 +29,8 @@ import AliasTables from "../sqlAlias"
|
|||
import { outputProcessing } from "../../../../utilities/rowProcessor"
|
||||
import pick from "lodash/pick"
|
||||
|
||||
const builder = new sql.Sql(SqlClient.SQL_LITE)
|
||||
|
||||
function buildInternalFieldList(
|
||||
table: Table,
|
||||
tables: Table[],
|
||||
|
@ -99,7 +101,6 @@ function buildTableMap(tables: Table[]) {
|
|||
}
|
||||
|
||||
async function runSqlQuery(json: QueryJson, tables: Table[]) {
|
||||
const builder = new sql.Sql(SqlClient.SQL_LITE)
|
||||
const alias = new AliasTables(tables.map(table => table.name))
|
||||
return await alias.queryWithAliasing(json, async json => {
|
||||
const query = builder._query(json, {
|
||||
|
@ -184,15 +185,13 @@ export async function search(
|
|||
try {
|
||||
const rows = await runSqlQuery(request, allTables)
|
||||
|
||||
// process from the format of tableId.column to expected format
|
||||
const processed = await sqlOutputProcessing(
|
||||
rows,
|
||||
table!,
|
||||
allTablesMap,
|
||||
relationships,
|
||||
{
|
||||
// process from the format of tableId.column to expected format also
|
||||
// make sure JSON columns corrected
|
||||
const processed = builder.convertJsonStringColumns<Row>(
|
||||
table,
|
||||
await sqlOutputProcessing(rows, table!, allTablesMap, relationships, {
|
||||
sqs: true,
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
// check for pagination final row
|
||||
|
|
Loading…
Reference in a new issue