Generate SQL snippets comparing variables and values. sqrrl
provides two
types of each function. Functions without an underscore, like eq
, take an
unlimited number of arguments and value pairs, where each argument is assumed
to be single valued and the argument name is used as the column name.
Functions with an underscore, like eq_
, take a vector of columns and a
vector of values that are zipped together. Infix operators are also provided
for LIKE
and IN
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | eq(a = 1, b = 'value') # "a=1" "b=\"value\""
eq_(letters[1:3], 1:3) # "a=1" "b=2" "c=3"
neq(a = 1, b = 'value') # "a!=1" "b!=\"value\""
neq_(letters[1:3], 1:3) # "a!=1" "b!=2" "c!=3"
lt(a = 1, b = '2017-01-01') # "a<1" "b<\"2017-01-01\""
lt_(letters[1:3], 10:12) # "a<10" "b<11" "c<12"
leq(a = 1, b = '2017-01-01')# "a<=1" "b<=\"2017-01-01\""
leq_(letters[1:3], 10:12) # "a<=10" "b<=11" "c<=12"
gt(a = 1, b = '2017-01-01') # "a>1" "b>\"2017-01-01\""
gt_(letters[1:3], 10:12) # "a>10" "b>11" "c>12"
geq(a = 1, b = '2017-01-01')# "a>=1" "b>=\"2017-01-01\""
geq_(letters[1:3], 10:12) # "a>=10" "b>=11" "c>=12"
in_('a', c(5, 7, 8)) # "a IN (5, 7, 8)"
'a' %IN% c(5, 7, 8) # "a IN (5, 7, 8)"
like_('a', 'Prefix%') # "a LIKE(\"Prefix%\")"
'a' %LIKE% 'Prefix%' # "a LIKE(\"Prefix%\")"
like('a', 'Prefix%', '%Suffix')
# "(a LIKE(\"Prefix%\") OR a LIKE(\"%Suffix\"))"
BETWEEN('a', 0, 10) # "a BETWEEN 0 AND 10"
BETWEEN('timestamp', '2016-01-01', '2017-01-01')
# "`timestamp` BETWEEN \"2016-01-01\" AND \"2017-01-01\""
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.