Description References See Also Examples
sql.template is a simple, mustache-based SQL templating library. It allows writing syntactically valid SQL that can execute as-is and simultaneously support injection of values programattically before sending the query for execution. It has three main functions
substitution using whisker
templates
tags that allow for unmasking/uncommenting of SQL templating code
read SQL from any connection-type object such as a file.
The package was designed so that the developers could share SQL code between developers from a shared or forked repository. It is very amenable to use with any of the R piping libraries.
http://en.wikipedia.org/wiki/Mustache_(template_system)
http://mustache.github
https://github.com/edwindj/whisker
sql
sqlutils: https://github.com/jbryer/sqlutils for an alternative
approach
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | sql = "
SELECT
*
FROM
{{table}}
WHERE
1 == 1
--fn: and FIRST_NAME = '{{first_name}}' /*ln: and LAST_NAME = '{{last_name}}'*/
"
replacement <- list( table = "pres", first_name = "Barack", last_name = "Obama" )
# COMPARE THE FOLLOWING:
sql_render( sql, replacement, render=FALSE, strip.comments = FALSE )
sql_render( sql, replacement ) # render
sql_render( sql, replacement, "fn" ) # render 'fn' tags
sql_render( sql, replacement, c("fn","ln") ) # render 'fn' tags
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.