Skip to content

Instantly share code, notes, and snippets.

@dstnbrkr
Created May 22, 2012 18:10
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 dstnbrkr/2770652 to your computer and use it in GitHub Desktop.
Save dstnbrkr/2770652 to your computer and use it in GitHub Desktop.
predicate templates
// the query:
// foo amount:15
// first becomes an array of predicate templates
[ "${column} like '%foo%'", "${column} >= 14 and ${column} <= 16" ]
// next, we inspect the model to find which columns to search on
// and repeat each query for each property
[ [ "description like '%foo%'", "memo like '%foo%'" ], [ "amount >= 14 and amount <= 16" ] ]
// the subarrays get OR'd
[ "description like '%foo%' OR memo like '%foo%'", "amount >= 14 and amount <= 16" ]
// then the entire array gets AND'd
"(description like '%foo%' OR memo like '%foo%') AND (amount >= 14 and amount <= 16)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment