-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathREADME.Rmd
104 lines (77 loc) · 3.12 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
dpi=200,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# RSQL
[![Downloads](http://cranlogs.r-pkg.org/badges/RSQL?color=brightgreen)](https://www.r-pkg.org:443/pkg/RSQL)
[![Downloads](http://cranlogs.r-pkg.org/badges/grand-total/RSQL?color=brightgreen)](https://www.r-pkg.org:443/pkg/RSQL)
<!-- Database Agnostic Package to Generate and Process 'SQL' Queries in R. -->
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](https://img.shields.io/badge/R%3E%3D-3.4.0-blue.svg)](https://cran.r-project.org/) | [![R-CMD-check](https://github.com/rOpenStats/RSQL/workflows/R-CMD-check/badge.svg)](https://github.com/rOpenStats/RSQL/actions) |
| [![CRAN](http://www.r-pkg.org/badges/version/RSQL)](https://cran.r-project.org/package=RSQL) | | [![codecov](https://codecov.io/gh/rOpenStats/RSQL/branch/master/graph/badge.svg)](https://app.codecov.io/gh/rOpenStats/RSQL) |
|||[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)|
# How to get started
```R
install.packages("RSQL")
```
# How to get started (Development version)
Install the R package using the following commands on the R console:
```R
devtools::install_github("rOpenStats/RSQL", build_opts = NULL)
```
# A simple example
To get started execute the following commands:
```{r, load}
# 0. Load libraries
library(RSQL)
```
```{r, select}
# 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)
```
```{r, update}
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)
```
```{r, insert}
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](https://github.com/rOpenStats/RSQL/blob/master/CODE_OF_CONDUCT.md). By contributing to this project, you agree to abide by its terms.
<!--[![ropensci_footer](https://ropensci.org/public_images/ropensci_footer.png)](https://ropensci.org)-->