remove all of the `fnc` variables

This commit is contained in:
Sam Rose 2024-10-23 17:21:14 +01:00
parent a120ce4e14
commit ebcbadfd3a
No known key found for this signature in database
2 changed files with 31 additions and 30 deletions

View File

@ -719,12 +719,12 @@ class InternalBuilder {
return q return q
} }
q = q.where(subQuery => { return q.where(subQuery => {
if (mode === filters?.notContains) { if (mode === filters?.notContains) {
subQuery = subQuery.not subQuery = subQuery.not
} }
subQuery.where(subSubQuery => { return subQuery.where(subSubQuery => {
for (const elem of value) { for (const elem of value) {
if (mode === filters?.containsAny) { if (mode === filters?.containsAny) {
subSubQuery = subSubQuery.or subSubQuery = subSubQuery.or
@ -743,21 +743,8 @@ class InternalBuilder {
`%${lower}%` `%${lower}%`
) )
} }
return subSubQuery
}) })
if (mode === filters?.notContains) {
subQuery = subQuery.or.whereNull(
// @ts-expect-error knex types are wrong, raw is fine here
this.rawQuotedIdentifier(key)
)
}
return subQuery
}) })
return q
}) })
} }
} }
@ -890,7 +877,7 @@ class InternalBuilder {
} }
if (this.client === SqlClient.MS_SQL) { if (this.client === SqlClient.MS_SQL) {
return q.whereRaw(`CASE WHEN ?? = ? THEN 1 ELSE 0 END = 1`, [ return q.whereRaw(`CASE WHEN ?? = ? THEN 1 ELSE 0 END = 1`, [
this.quotedIdentifier(key), this.rawQuotedIdentifier(key),
value, value,
]) ])
} else if (this.client === SqlClient.ORACLE) { } else if (this.client === SqlClient.ORACLE) {
@ -909,20 +896,30 @@ class InternalBuilder {
} }
if (filters.notEqual) { if (filters.notEqual) {
iterate(filters.notEqual, BasicOperator.NOT_EQUAL, (q, key, value) => { iterate(filters.notEqual, BasicOperator.NOT_EQUAL, (q, key, value) => {
const fnc = shouldOr ? "orWhereRaw" : "whereRaw" if (shouldOr) {
q = q.or
}
if (this.client === SqlClient.MS_SQL) { if (this.client === SqlClient.MS_SQL) {
return q[fnc]( return q.whereRaw(`CASE WHEN ?? = ? THEN 1 ELSE 0 END = 0`, [
`CASE WHEN ${this.quotedIdentifier(key)} = ? THEN 1 ELSE 0 END = 0`, this.rawQuotedIdentifier(key),
[value] value,
) ])
} else if (this.client === SqlClient.ORACLE) { } else if (this.client === SqlClient.ORACLE) {
const identifier = this.convertClobs(key) const identifier = this.convertClobs(key)
return q[fnc]( return (
`(${identifier} IS NOT NULL AND ${identifier} != ?) OR ${identifier} IS NULL`, q
[value] .where(subq =>
subq.not
// @ts-expect-error knex types are wrong, raw is fine here
.whereNull(identifier)
.and.where(identifier, "!=", value)
)
// @ts-expect-error knex types are wrong, raw is fine here
.or.whereNull(identifier)
) )
} else { } else {
return q[fnc](`COALESCE(${this.quotedIdentifier(key)} != ?, TRUE)`, [ return q.whereRaw(`COALESCE(?? != ?, TRUE)`, [
this.rawQuotedIdentifier(key),
value, value,
]) ])
} }
@ -930,14 +927,18 @@ class InternalBuilder {
} }
if (filters.empty) { if (filters.empty) {
iterate(filters.empty, BasicOperator.EMPTY, (q, key) => { iterate(filters.empty, BasicOperator.EMPTY, (q, key) => {
const fnc = shouldOr ? "orWhereNull" : "whereNull" if (shouldOr) {
return q[fnc](key) q = q.or
}
return q.whereNull(key)
}) })
} }
if (filters.notEmpty) { if (filters.notEmpty) {
iterate(filters.notEmpty, BasicOperator.NOT_EMPTY, (q, key) => { iterate(filters.notEmpty, BasicOperator.NOT_EMPTY, (q, key) => {
const fnc = shouldOr ? "orWhereNotNull" : "whereNotNull" if (shouldOr) {
return q[fnc](key) q = q.or
}
return q.whereNotNull(key)
}) })
} }
if (filters.contains) { if (filters.contains) {

View File

@ -793,7 +793,7 @@ describe.each([
}) })
const stringTypes = [FieldType.STRING, FieldType.LONGFORM] as const const stringTypes = [FieldType.STRING, FieldType.LONGFORM] as const
describe.each(stringTypes)("%s", type => { describe.only.each(stringTypes)("%s", type => {
beforeAll(async () => { beforeAll(async () => {
tableOrViewId = await createTableOrView({ tableOrViewId = await createTableOrView({
name: { name: "name", type }, name: { name: "name", type },