Tidying up one of the weirder things knex can do.
This commit is contained in:
parent
654a417d66
commit
c34c219e8f
|
@ -30,6 +30,7 @@ import {
|
||||||
buildExternalRelationships,
|
buildExternalRelationships,
|
||||||
buildSqlFieldList,
|
buildSqlFieldList,
|
||||||
generateIdForRow,
|
generateIdForRow,
|
||||||
|
isKnexNoRowReadResponse,
|
||||||
isManyToMany,
|
isManyToMany,
|
||||||
sqlOutputProcessing,
|
sqlOutputProcessing,
|
||||||
} from "./utils"
|
} from "./utils"
|
||||||
|
@ -433,8 +434,7 @@ export class ExternalRequest<T extends Operation> {
|
||||||
})
|
})
|
||||||
// this is the response from knex if no rows found
|
// this is the response from knex if no rows found
|
||||||
const rows: Row[] =
|
const rows: Row[] =
|
||||||
!Array.isArray(response) ||
|
!Array.isArray(response) || isKnexNoRowReadResponse(response)
|
||||||
(response.length === 1 && "read" in response[0])
|
|
||||||
? []
|
? []
|
||||||
: response
|
: response
|
||||||
const storeTo = isManyToMany(field)
|
const storeTo = isManyToMany(field)
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
import {
|
import {
|
||||||
|
DatasourcePlusQueryResponse,
|
||||||
|
DSPlusOperation,
|
||||||
FieldType,
|
FieldType,
|
||||||
ManyToManyRelationshipFieldMetadata,
|
ManyToManyRelationshipFieldMetadata,
|
||||||
RelationshipFieldMetadata,
|
RelationshipFieldMetadata,
|
||||||
|
@ -192,3 +194,11 @@ export function buildSqlFieldList(
|
||||||
}
|
}
|
||||||
return fields
|
return fields
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isKnexNoRowReadResponse(resp: DatasourcePlusQueryResponse) {
|
||||||
|
return (
|
||||||
|
!Array.isArray(resp) ||
|
||||||
|
resp.length === 0 ||
|
||||||
|
(DSPlusOperation.READ in resp[0] && resp[0].read === true)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ import {
|
||||||
processDates,
|
processDates,
|
||||||
processFormulas,
|
processFormulas,
|
||||||
} from "../../../../utilities/rowProcessor"
|
} from "../../../../utilities/rowProcessor"
|
||||||
import { updateRelationshipColumns } from "./sqlUtils"
|
import { isKnexNoRowReadResponse, updateRelationshipColumns } from "./sqlUtils"
|
||||||
import {
|
import {
|
||||||
basicProcessing,
|
basicProcessing,
|
||||||
generateIdForRow,
|
generateIdForRow,
|
||||||
|
@ -137,7 +137,7 @@ export async function sqlOutputProcessing(
|
||||||
relationships: RelationshipsJson[],
|
relationships: RelationshipsJson[],
|
||||||
opts?: { sqs?: boolean }
|
opts?: { sqs?: boolean }
|
||||||
): Promise<Row[]> {
|
): Promise<Row[]> {
|
||||||
if (!Array.isArray(rows) || rows.length === 0 || "read" in rows[0]) {
|
if (isKnexNoRowReadResponse(rows)) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
let finalRows: { [key: string]: Row } = {}
|
let finalRows: { [key: string]: Row } = {}
|
||||||
|
|
|
@ -187,7 +187,7 @@ export interface Schema {
|
||||||
}
|
}
|
||||||
|
|
||||||
// return these when an operation occurred but we got no response
|
// return these when an operation occurred but we got no response
|
||||||
enum DSPlusOperation {
|
export enum DSPlusOperation {
|
||||||
CREATE = "create",
|
CREATE = "create",
|
||||||
READ = "read",
|
READ = "read",
|
||||||
UPDATE = "update",
|
UPDATE = "update",
|
||||||
|
|
Loading…
Reference in New Issue