-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix lessThan operator not applying column case
- Loading branch information
1 parent
03c4481
commit 0f3aea8
Showing
2 changed files
with
92 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
...server/src/engine/api/graphql/graphql-query-runner/utils/compute-where-condition-parts.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { ObjectLiteral } from 'typeorm'; | ||
|
||
import { | ||
GraphqlQueryRunnerException, | ||
GraphqlQueryRunnerExceptionCode, | ||
} from 'src/engine/api/graphql/graphql-query-runner/errors/graphql-query-runner.exception'; | ||
|
||
type WhereConditionParts = { | ||
sql: string; | ||
params: ObjectLiteral; | ||
}; | ||
|
||
export const computeWhereConditionParts = ( | ||
operator: string, | ||
objectNameSingular: string, | ||
key: string, | ||
value: any, | ||
): WhereConditionParts => { | ||
const uuid = Math.random().toString(36).slice(2, 7); | ||
|
||
switch (operator) { | ||
case 'eq': | ||
return { | ||
sql: `"${objectNameSingular}"."${key}" = :${key}${uuid}`, | ||
params: { [`${key}${uuid}`]: value }, | ||
}; | ||
case 'neq': | ||
return { | ||
sql: `"${objectNameSingular}"."${key}" != :${key}${uuid}`, | ||
params: { [`${key}${uuid}`]: value }, | ||
}; | ||
case 'gt': | ||
return { | ||
sql: `"${objectNameSingular}"."${key}" > :${key}${uuid}`, | ||
params: { [`${key}${uuid}`]: value }, | ||
}; | ||
case 'gte': | ||
return { | ||
sql: `"${objectNameSingular}"."${key}" >= :${key}${uuid}`, | ||
params: { [`${key}${uuid}`]: value }, | ||
}; | ||
case 'lt': | ||
return { | ||
sql: `"${objectNameSingular}"."${key}" < :${key}${uuid}`, | ||
params: { [`${key}${uuid}`]: value }, | ||
}; | ||
case 'lte': | ||
return { | ||
sql: `"${objectNameSingular}"."${key}" <= :${key}${uuid}`, | ||
params: { [`${key}${uuid}`]: value }, | ||
}; | ||
case 'in': | ||
return { | ||
sql: `"${objectNameSingular}"."${key}" IN (:...${key}${uuid})`, | ||
params: { [`${key}${uuid}`]: value }, | ||
}; | ||
case 'is': | ||
return { | ||
sql: `"${objectNameSingular}"."${key}" IS ${value === 'NULL' ? 'NULL' : 'NOT NULL'}`, | ||
params: {}, | ||
}; | ||
case 'like': | ||
return { | ||
sql: `"${objectNameSingular}"."${key}" LIKE :${key}${uuid}`, | ||
params: { [`${key}${uuid}`]: `${value}` }, | ||
}; | ||
case 'ilike': | ||
return { | ||
sql: `"${objectNameSingular}"."${key}" ILIKE :${key}${uuid}`, | ||
params: { [`${key}${uuid}`]: `${value}` }, | ||
}; | ||
case 'startsWith': | ||
return { | ||
sql: `"${objectNameSingular}"."${key}" LIKE :${key}${uuid}`, | ||
params: { [`${key}${uuid}`]: `${value}` }, | ||
}; | ||
case 'endsWith': | ||
return { | ||
sql: `"${objectNameSingular}"."${key}" LIKE :${key}${uuid}`, | ||
params: { [`${key}${uuid}`]: `${value}` }, | ||
}; | ||
default: | ||
throw new GraphqlQueryRunnerException( | ||
`Operator "${operator}" is not supported`, | ||
GraphqlQueryRunnerExceptionCode.UNSUPPORTED_OPERATOR, | ||
); | ||
} | ||
}; |