Create SQL snippets to build SQL queries.

FROM(...)

WHERE(..., cond = TRUE)

AND(...)

OR(...)

GROUP_BY(...)

LIMIT(n = 1)

DESC(x)

ORDER_BY(...)

Functions

  • FROM: Create FROM SQL snippet with optional table aliases

  • WHERE: Generate WHERE SQL snippet if cond evaluates to TRUE, with arguments to WHERE concatenated by AND

  • AND: Concatenate arguments with AND

  • OR: Concatenate arguments with OR

  • GROUP_BY: Create GROUP BY SQL snippet, arguments are column names separated by commas

  • LIMIT: Create LIMIT SQL snippet

  • DESC: Add DESC or ASC after column name

  • ORDER_BY: Create ORDER BY SQL snippet, arguments are column names separated by commas

Examples

FROM('table1', 'table2')
#> [1] "FROM table1 , table2 "
FROM(t1 = 'table1', t2 = 'table2')
#> [1] "FROM table1 t1, table2 t2"
WHERE('col1 IS NOT NULL')
#> [1] "WHERE col1 IS NOT NULL"
WHERE(cond = TRUE, 'col1 = 2', 'col2 >= 10')
#> [1] "WHERE col1 = 2 AND col2 >= 10"
WHERE(cond = FALSE, 'col1 = 2', 'col2 >= 10')
#> [1] ""
AND(eq(id = 3, class = 'text_value'), geq(date = '2017-06-14'))
#> [1] "id=3 AND `class`=\"text_value\" AND `date`>=\"2017-06-14\""
OR(eq(id = 9, id = 12), leq(id = 5))
#> [1] "id=9 OR id=12 OR id<=5"
GROUP_BY('col1', 'col2', 'col3')
#> [1] "GROUP BY col1, col2, col3"
LIMIT(10)
#> [1] "LIMIT 10"
ORDER_BY('col1', 'col2', 'col3')
#> [1] "ORDER BY col1, col2, col3"
ORDER_BY(DESC('col1'), 'col2', ASC('col3'))
#> [1] "ORDER BY col1 DESC, col2, col3 ASC"