more consistent null handling
This commit is contained in:
parent
3bd56bdca7
commit
e4f7fa7fad
|
@ -1162,20 +1162,14 @@ class InternalBuilder {
|
||||||
const direction =
|
const direction =
|
||||||
value.direction === SortOrder.ASCENDING ? "asc" : "desc"
|
value.direction === SortOrder.ASCENDING ? "asc" : "desc"
|
||||||
|
|
||||||
// TODO: figure out a way to remove this conditional, not relying on
|
let nulls: "first" | "last" =
|
||||||
// the defaults of each datastore.
|
value.direction === SortOrder.ASCENDING ? "first" : "last"
|
||||||
let nulls: "first" | "last" | undefined = undefined
|
|
||||||
if (
|
|
||||||
this.client === SqlClient.POSTGRES ||
|
|
||||||
this.client === SqlClient.ORACLE
|
|
||||||
) {
|
|
||||||
nulls = value.direction === SortOrder.ASCENDING ? "first" : "last"
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.isAggregateField(key)) {
|
if (this.isAggregateField(key)) {
|
||||||
query = query.orderByRaw(`?? ??`, [
|
query = query.orderByRaw(`?? ?? nulls ??`, [
|
||||||
this.rawQuotedIdentifier(key),
|
this.rawQuotedIdentifier(key),
|
||||||
this.knex.raw(direction),
|
this.knex.raw(direction),
|
||||||
|
this.knex.raw(nulls as string),
|
||||||
])
|
])
|
||||||
} else {
|
} else {
|
||||||
let composite = `${aliased}.${key}`
|
let composite = `${aliased}.${key}`
|
||||||
|
@ -1186,9 +1180,10 @@ class InternalBuilder {
|
||||||
this.knex.raw(nulls as string),
|
this.knex.raw(nulls as string),
|
||||||
])
|
])
|
||||||
} else {
|
} else {
|
||||||
query = query.orderByRaw(`?? ??`, [
|
query = query.orderByRaw(`?? ?? nulls ??`, [
|
||||||
this.rawQuotedIdentifier(composite),
|
this.rawQuotedIdentifier(composite),
|
||||||
this.knex.raw(direction),
|
this.knex.raw(direction),
|
||||||
|
this.knex.raw(nulls as string),
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3650,6 +3650,49 @@ if (descriptions.length) {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("Fields with spaces", () => {
|
||||||
|
let table: Table
|
||||||
|
let otherTable: Table
|
||||||
|
let relatedRow: Row, mainRow: Row
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
otherTable = await config.api.table.save(defaultTable())
|
||||||
|
table = await config.api.table.save(
|
||||||
|
saveTableRequest({
|
||||||
|
schema: {
|
||||||
|
links: {
|
||||||
|
name: "links",
|
||||||
|
fieldName: "links",
|
||||||
|
type: FieldType.LINK,
|
||||||
|
tableId: otherTable._id!,
|
||||||
|
relationshipType: RelationshipType.ONE_TO_MANY,
|
||||||
|
},
|
||||||
|
"nameWithSpace ": {
|
||||||
|
name: "nameWithSpace ",
|
||||||
|
type: FieldType.STRING,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
)
|
||||||
|
relatedRow = await config.api.row.save(otherTable._id!, {
|
||||||
|
name: generator.word(),
|
||||||
|
description: generator.paragraph(),
|
||||||
|
})
|
||||||
|
mainRow = await config.api.row.save(table._id!, {
|
||||||
|
"nameWithSpace ": generator.word(),
|
||||||
|
tableId: table._id!,
|
||||||
|
links: [relatedRow._id],
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("Successfully returns rows that have spaces in their field names", async () => {
|
||||||
|
const { rows } = await config.api.row.search(table._id!)
|
||||||
|
expect(rows.length).toBe(1)
|
||||||
|
const row = rows[0]
|
||||||
|
expect(row["nameWithSpace "]).toBeDefined()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
if (!isInternal && !isOracle) {
|
if (!isInternal && !isOracle) {
|
||||||
describe("bigint ids", () => {
|
describe("bigint ids", () => {
|
||||||
let table1: Table, table2: Table
|
let table1: Table, table2: Table
|
||||||
|
|
Loading…
Reference in New Issue