-
-
Save joepie91/2c501df120bcf2090677b339e88c1486 to your computer and use it in GitHub Desktop.
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
// Assume that the below numbers were generated by some external code somehow, and we don't know upfront which one is going to be lowest | |
let a = 523; | |
let b = 62; | |
let query = select("projects", [ | |
where({ | |
active: true, | |
score: not(lessThan(anyOf([ a, b, sql("44 + 33"), parameter("foo") ]))) | |
}) | |
]); |
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
{ type: 'select', | |
table: { type: 'tableName', name: 'projects' }, | |
clauses: | |
[ { type: 'where', | |
expression: | |
{ type: 'expression', | |
left: { type: 'columnName', name: 'active' }, | |
condition: | |
{ type: 'condition', | |
conditionType: 'equals', | |
expression: { type: 'literalValue', value: true } } } }, | |
{ type: 'where', | |
expression: | |
{ type: 'expression', | |
left: { type: 'columnName', name: 'score' }, | |
condition: | |
{ type: 'notCondition', | |
condition: | |
{ type: 'condition', | |
conditionType: 'lessThan', | |
expression: | |
{ type: 'anyOf', | |
items: | |
[ { type: 'literalValue', value: 523 }, | |
{ type: 'literalValue', value: 62 }, | |
{ type: 'sqlExpression', sql: '44 + 33', parameters: [] }, | |
{ type: 'placeholder', name: 'foo' } ] } } } } } ] } | |
{ query: | |
'SELECT * FROM projects WHERE active = ? AND NOT (score < ANY (ARRAY[?, ?, (44 + 33), ?]));', | |
params: [ true, 523, 62, { type: 'placeholder', name: 'foo' } ], | |
placeholders: [ 'foo' ] } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment