wip
This commit is contained in:
parent
866e9dcadd
commit
e25d92a49e
|
@ -1191,8 +1191,9 @@ class InternalBuilder {
|
|||
return withSchema
|
||||
}
|
||||
|
||||
private buildJsonField(field: string): string {
|
||||
private buildJsonField(table: Table, field: string): string {
|
||||
const parts = field.split(".")
|
||||
const baseName = parts[parts.length - 1]
|
||||
let unaliased: string
|
||||
|
||||
let tableField: string
|
||||
|
@ -1205,9 +1206,21 @@ class InternalBuilder {
|
|||
tableField = unaliased
|
||||
}
|
||||
|
||||
const schema = table.schema[baseName]
|
||||
|
||||
const separator = this.client === SqlClient.ORACLE ? " VALUE " : ","
|
||||
let identifier = this.rawQuotedIdentifier(tableField)
|
||||
if (schema.type === FieldType.BIGINT) {
|
||||
identifier = this.castIntToString(identifier)
|
||||
} else if (schema.type === FieldType.LINK) {
|
||||
const otherTable = this.query.meta.tables![schema.tableId]
|
||||
const otherField = otherTable.schema[schema.fieldName]
|
||||
if (otherField.type === FieldType.BIGINT) {
|
||||
identifier = this.castIntToString(identifier)
|
||||
}
|
||||
} else if (schema.autocolumn && schema.autoReason === "foreign_key")
|
||||
return this.knex
|
||||
.raw(`?${separator}??`, [unaliased, this.rawQuotedIdentifier(tableField)])
|
||||
.raw(`?${separator}??`, [unaliased, identifier])
|
||||
.toString()
|
||||
}
|
||||
|
||||
|
@ -1272,7 +1285,7 @@ class InternalBuilder {
|
|||
Math.floor(this.maxFunctionParameters() / 2)
|
||||
)
|
||||
const fieldList: string = relationshipFields
|
||||
.map(field => this.buildJsonField(field))
|
||||
.map(field => this.buildJsonField(relatedTable!, field))
|
||||
.join(",")
|
||||
// SQL Server uses TOP - which performs a little differently to the normal LIMIT syntax
|
||||
// it reduces the result set rather than limiting how much data it filters over
|
||||
|
|
|
@ -3545,7 +3545,19 @@ if (descriptions.length) {
|
|||
await config.api.row.save(relatedTable._id!, { tableid: row.id })
|
||||
|
||||
const { rows } = await config.api.row.search(table._id!)
|
||||
expect(rows).toEqual([])
|
||||
expect(rows).toEqual([
|
||||
expect.objectContaining({
|
||||
_id: "%5B'1'%5D",
|
||||
_rev: "rev",
|
||||
id: "1",
|
||||
related: [
|
||||
{
|
||||
_id: "%5B'1'%5D",
|
||||
primaryDisplay: 1,
|
||||
},
|
||||
],
|
||||
}),
|
||||
])
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -39,10 +39,6 @@ if (types) {
|
|||
types.setTypeParser(1114, (val: any) => val) // timestamp
|
||||
types.setTypeParser(1082, (val: any) => val) // date
|
||||
types.setTypeParser(1184, (val: any) => val) // timestampz
|
||||
// types.setTypeParser(114, JSON.parse) // json
|
||||
// types.setTypeParser(3802, JSON.parse) // jsonb
|
||||
// types.setTypeParser(199, parseJsonArray) // json[]
|
||||
// types.setTypeParser(3807, parseJsonArray) // jsonb[]
|
||||
}
|
||||
|
||||
const JSON_REGEX = /'{\s*.*?\s*}'::json/gs
|
||||
|
|
Loading…
Reference in New Issue