generated from r-dbi/RKazam
-
Notifications
You must be signed in to change notification settings - Fork 5
/
README.Rmd
89 lines (63 loc) · 1.98 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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# adbi
<!-- badges: start -->
[![rcc](https://github.com/r-dbi/adbi/workflows/rcc/badge.svg)](https://github.com/r-dbi/adbi/actions)
[![Codecov test coverage](https://codecov.io/gh/r-dbi/adbi/branch/main/graph/badge.svg)](https://app.codecov.io/gh/r-dbi/adbi?branch=main)
[![CRAN status](https://www.r-pkg.org/badges/version/adbi)](https://CRAN.R-project.org/package=adbi)
<!-- badges: end -->
Bringing [arrow-adbc](https://github.com/apache/arrow-adbc) to R via [DBI](https://github.com/r-dbi), adbi aims to provide DBI-compliant database access.
## Installation
You can install the development version of adbi from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("r-dbi/adbi")
```
## Example
The `data.frame` API of DBI is supported.
```{r df}
library(DBI)
# Create an SQLite connection using the adbcsqlite backend
con <- dbConnect(adbi::adbi("adbcsqlite"), uri = ":memory:")
# Write a table
dbWriteTable(con, "swiss", datasets::swiss)
# Query it
dbGetQuery(con, "SELECT * from swiss WHERE Agriculture < 40")
# Prepared statements
res <- dbSendQuery(con, "SELECT * from swiss WHERE Agriculture < ?")
dbBind(res, 30)
dbFetch(res)
dbBind(res, 20)
dbFetch(res)
# Cleanup
dbClearResult(res)
```
More interestingly, the recent arrow-extension API of DBI is supported as well.
```{r arrow}
# Queries
dbGetQueryArrow(con, "SELECT * from swiss WHERE Agriculture < 40")
# Prepared statements
res <- dbSendQueryArrow(con, "SELECT * from swiss WHERE Agriculture < ?")
dbBind(res, 30)
ret <- dbFetchArrow(res)
ret$length
dbBind(res, 20)
# Chunked fetches
while (!dbHasCompleted(res)) {
ret <- dbFetchArrowChunk(res)
message("fetched ", ret$length, " rows")
}
# Cleanup
dbClearResult(res)
dbDisconnect(con)
```