This is an R package for rendering parameterized SQL, and translating it to different SQL dialects. SqlRender can also be used as a stand-alone Java library.
This exampe shows the use of parameters, as well as SqlRender's {if} ? {then} : {else} syntax:
sql <- renderSql("SELECT * FROM @a; {@b != ''}?{USE @b;}", a = "my_table", b = "my_schema")$sql
will produce the variable sql
containing this value:
"SELECT * FROM my_table; USE my_schema;"
subsequently running this code
sql <- translateSql(sql, "sql server", "oracle")$sql
will produce the variable sql
containing this value:
"SELECT * FROM my_table; ALTER SESSION SET current_schema = my_schema;"
The SqlRender package is an R package wrapped around a Java library. The rJava package is used as interface.
The Java library is available as a JAR file.
Running the package requires R with the package rJava installed. Also requires Java 1.6 or higher.
Use these commands in R to download and install the SqlRender package:
install.packages("devtools")
library("devtools")
install_github("ohdsi/SqlRender")
You can fetch the JAR file in the inst/java folder of this repository, or use Maven:
<repositories>
<repository>
<id>ohdsi</id>
<name>repo.ohdsi.org</name>
<url>http://repo.ohdsi.org:8085/nexus/content/repositories/releases</url>
</repository>
<repository>
<id>ohdsi.snapshots</id>
<name>repo.ohdsi.org-snapshots</name>
<url>http://repo.ohdsi.org:8085/nexus/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
2: Include the SqlRender dependency in your pom.xml
<dependency>
<groupId>org.ohdsi.sql</groupId>
<artifactId>SqlRender</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
SqlRender is licensed under Apache License 2.0
SqlRender is being developed in R Studio.
Stable. The code is actively being used in several projects.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.