knitr::opts_chunk$set(
  collapse = TRUE,
  dpi=200,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

RSQL

Downloads Downloads

Allows the user to generate and execute select, insert, update and delete 'SQL' queries the underlying database without having to explicitly write 'SQL' code.

| Release | Usage | Development | |:--------|:------|:------------| || minimal R version | R-CMD-check | | CRAN | | codecov | |||Project Status: Active – The project has reached a stable, usable state and is being actively developed.|

How to get started

install.packages("RSQL")

How to get started (Development version)

Install the R package using the following commands on the R console:

devtools::install_github("rOpenStats/RSQL", build_opts = NULL)

A simple example

To get started execute the following commands:

# 0.  Load libraries
library(RSQL)
# 1.  RSQL
db.name <- getMtcarsdbPath()
rsql <- createRSQL(drv = RSQLite::SQLite(), dbname = db.name)
query_sql <- rsql$gen_select(
    select_fields = c("*"),
    table = "mtcars")

query_sql <- rsql$gen_select(
    select_fields = c("mpg", "cyl", "disp", "hp", "drat", "wt", "qsec", "vs", "am"),
    table = "mtcars",
    where_fields = "gear",
    where_values = 4)
query_sql

rsql$execute_select(query_sql)
update_sql <- rsql$gen_update(
    update_fields = c("vs"),
    values = 1,
    table = "mtcars",
    where_fields = "gear",
    where_values = 4)
update_sql
rsql$execute_update(update_sql)
rsql$execute_select(query_sql)
insert.df <- c(4, rep(99, 9))
names(insert.df) <- c("gear", "mpg", "cyl", "disp", "hp", "drat", "wt", "qsec", "vs", "am")
insert.df <- as.data.frame(t(insert.df))
insert_sql <- rsql$gen_insert(
    values = insert.df,
    table = "mtcars")
rsql$execute_insert(insert_sql)
rsql$execute_select(query_sql)

Troubleshooting

Please note that the 'RSQL' project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.



rOpenStats/RSQL documentation built on Aug. 25, 2023, 2:17 a.m.