knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "README-"
)

lazysql

Travis-CI Build Status
AppVeyor Build Status
Coverage Status
CRAN_Status_Badge
Project Status: Active - The project has reached a stable, usable state and is being actively developed.

Lazy SQL programming.

Helper functions to build SQL statements under program control for use with dbGetQuery, dbSendQuery, sqldf, etc. They are intended to increase speed of coding and to reduce coding errors. Arguments are carefully checked, in particular SQL identifiers such as names of tables or columns.

Currently implemented are:

More patterns will be added as required.

Examples

date_between

date1 <- as.Date("2016-02-22")
date2 <- as.Date("2016-02-11")

# SQL expression for date range
(sql_expr1 <- lazysql::date_between("STD_1", c(date1, date2)))

# SQL expression for single date
(sql_expr2 <- lazysql::date_between("STD_1", date1))

# sample SQL statements
paste("select * from TEST_TABLE where", sql_expr1)

paste("select * from TEST_TABLE where", sql_expr2)

in_condition

# SQL expressions
lazysql::in_condition("COL_1", 1:3)

lazysql::in_condition("COL_1", 1:3, "not")

lazysql::in_condition("COL_1", LETTERS[2:3])

lazysql::in_condition("COL_1", LETTERS[2:3], "not")

natural_key

# SQL expression
(sql_expr <- lazysql::natural_key(c("TAB1", "tab_2"),c("COL1", "col_2")))

# sample SQL JOIN statement
paste("select * from TAB1, TAB2 where", sql_expr)

Installation

Get the released version from CRAN:

install.packages("lazysql")

Get the development version from github:

if (!"devtools" %in% installed.packages()) install.packages("devtools")
devtools::install_github("UweBlock/lazysql")

Contributor Code of Conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.



UweBlock/lazysql documentation built on May 9, 2019, 9:41 p.m.