Skip to content

Instantly share code, notes, and snippets.

@joepie91
Created April 5, 2020 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joepie91/2c501df120bcf2090677b339e88c1486 to your computer and use it in GitHub Desktop.
Save joepie91/2c501df120bcf2090677b339e88c1486 to your computer and use it in GitHub Desktop.
// 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") ])))
})
]);
{ 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