Revert to testing against mssql 2017, attempt to get relationship aggreggation working.
This commit is contained in:
parent
eefb1f01a3
commit
12db64513b
|
@ -913,30 +913,25 @@ class InternalBuilder {
|
||||||
const fieldList: string = relationshipFields
|
const fieldList: string = relationshipFields
|
||||||
.map(field => jsonField(field))
|
.map(field => jsonField(field))
|
||||||
.join(",")
|
.join(",")
|
||||||
let rawJsonArray: Knex.Raw, limit: number
|
let select: Knex.Raw, limit: number
|
||||||
switch (sqlClient) {
|
switch (sqlClient) {
|
||||||
case SqlClient.SQL_LITE:
|
case SqlClient.SQL_LITE:
|
||||||
rawJsonArray = this.knex.raw(
|
select = this.knex.raw(`json_group_array(json_object(${fieldList}))`)
|
||||||
`json_group_array(json_object(${fieldList}))`
|
|
||||||
)
|
|
||||||
limit = getBaseLimit()
|
limit = getBaseLimit()
|
||||||
break
|
break
|
||||||
case SqlClient.POSTGRES:
|
case SqlClient.POSTGRES:
|
||||||
rawJsonArray = this.knex.raw(
|
select = this.knex.raw(`json_agg(json_build_object(${fieldList}))`)
|
||||||
`json_agg(json_build_object(${fieldList}))`
|
|
||||||
)
|
|
||||||
limit = 1
|
limit = 1
|
||||||
break
|
break
|
||||||
case SqlClient.MY_SQL:
|
case SqlClient.MY_SQL:
|
||||||
case SqlClient.ORACLE:
|
case SqlClient.ORACLE:
|
||||||
rawJsonArray = this.knex.raw(
|
select = this.knex.raw(`json_arrayagg(json_object(${fieldList}))`)
|
||||||
`json_arrayagg(json_object(${fieldList}))`
|
|
||||||
)
|
|
||||||
limit = getBaseLimit()
|
limit = getBaseLimit()
|
||||||
break
|
break
|
||||||
case SqlClient.MS_SQL:
|
case SqlClient.MS_SQL:
|
||||||
rawJsonArray = this.knex.raw(`json_array(json_object(${fieldList}))`)
|
// Cursed, needs some code later instead
|
||||||
limit = 1
|
select = this.knex.raw(`*`)
|
||||||
|
limit = getBaseLimit()
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
throw new Error(`JSON relationships not implement for ${this.client}`)
|
throw new Error(`JSON relationships not implement for ${this.client}`)
|
||||||
|
@ -944,8 +939,8 @@ class InternalBuilder {
|
||||||
// SQL Server uses TOP - which performs a little differently to the normal LIMIT syntax
|
// 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
|
// it reduces the result set rather than limiting how much data it filters over
|
||||||
const primaryKey = `${toAlias}.${toPrimary || toKey}`
|
const primaryKey = `${toAlias}.${toPrimary || toKey}`
|
||||||
let subQuery = this.knex
|
let subQuery: Knex.QueryBuilder | Knex.Raw = this.knex
|
||||||
.select(rawJsonArray)
|
.select(select)
|
||||||
.from(toTableWithSchema)
|
.from(toTableWithSchema)
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
// add sorting to get consistent order
|
// add sorting to get consistent order
|
||||||
|
@ -985,6 +980,13 @@ class InternalBuilder {
|
||||||
if (this.client === SqlClient.SQL_LITE) {
|
if (this.client === SqlClient.SQL_LITE) {
|
||||||
subQuery = this.addJoinFieldCheck(subQuery, relationship)
|
subQuery = this.addJoinFieldCheck(subQuery, relationship)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.client === SqlClient.MS_SQL) {
|
||||||
|
subQuery = this.knex.raw(
|
||||||
|
`(SELECT a.* FROM (${subQuery}) AS a FOR JSON PATH)`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
query = query.select({ [relationship.column]: subQuery })
|
query = query.select({ [relationship.column]: subQuery })
|
||||||
}
|
}
|
||||||
return query
|
return query
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
MSSQL_SHA=sha256:c4369c38385eba011c10906dc8892425831275bb035d5ce69656da8e29de50d8
|
MSSQL_SHA=sha256:3b913841850a4d57fcfcb798be06acc88ea0f2acc5418bc0c140a43e91c4a545
|
||||||
MYSQL_SHA=sha256:9de9d54fecee6253130e65154b930978b1fcc336bcc86dfd06e89b72a2588ebe
|
MYSQL_SHA=sha256:9de9d54fecee6253130e65154b930978b1fcc336bcc86dfd06e89b72a2588ebe
|
||||||
POSTGRES_SHA=sha256:bd0d8e485d1aca439d39e5ea99b931160bd28d862e74c786f7508e9d0053090e
|
POSTGRES_SHA=sha256:bd0d8e485d1aca439d39e5ea99b931160bd28d862e74c786f7508e9d0053090e
|
||||||
MONGODB_SHA=sha256:afa36bca12295b5f9dae68a493c706113922bdab520e901bd5d6c9d7247a1d8d
|
MONGODB_SHA=sha256:afa36bca12295b5f9dae68a493c706113922bdab520e901bd5d6c9d7247a1d8d
|
||||||
|
|
|
@ -343,9 +343,9 @@ class SqlServerIntegration extends Sql implements DatasourcePlus {
|
||||||
err.number
|
err.number
|
||||||
)
|
)
|
||||||
if (readableMessage) {
|
if (readableMessage) {
|
||||||
throw new Error(readableMessage)
|
throw new Error(readableMessage, { cause: err })
|
||||||
} else {
|
} else {
|
||||||
throw new Error(err.message as string)
|
throw new Error(err.message as string, { cause: err })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue