An open API service indexing awesome lists of open source software.

https://github.com/poissonconsulting/dbflobr

An R package to read and write files to SQLite databases as BLOBs
https://github.com/poissonconsulting/dbflobr

blob cran databases flob sqlite

Last synced: 3 months ago
JSON representation

An R package to read and write files to SQLite databases as BLOBs

Awesome Lists containing this project

README

        

---
output: github_document
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# dbflobr

[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
[![R-CMD-check](https://github.com/poissonconsulting/dbflobr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/poissonconsulting/dbflobr/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/poissonconsulting/dbflobr/graph/badge.svg)](https://app.codecov.io/gh/poissonconsulting/dbflobr)
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
[![CRAN status](https://www.r-pkg.org/badges/version/dbflobr)](https://cran.r-project.org/package=dbflobr)
![CRAN downloads](https://cranlogs.r-pkg.org/badges/dbflobr)

`dbflobr` reads and writes files to SQLite databases as [flobs](https://github.com/poissonconsulting/flobr).
A flob is a [blob](https://github.com/tidyverse/blob) that preserves the file extension.

## Installation

To install the latest release from [CRAN](https://cran.r-project.org)
```r
install.packages("dbflobr")
```

To install the developmental version from [GitHub](https://github.com/poissonconsulting/dbflobr)
```r
# install.packages("remotes")
remotes::install_github("poissonconsulting/dbflobr")
```

## Demonstration

```{r}
library(dbflobr)

# convert a file to flob using flobr
flob <- flobr::flob(system.file("extdata", "flobr.pdf", package = "flobr"))
str(flob)

# create a SQLite database connection
conn <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")

# create a table 'Table1' of data
DBI::dbWriteTable(conn, "Table1", data.frame(IntColumn = c(1L, 2L)))

DBI::dbReadTable(conn, "Table1")

# specify which row to add the flob to by providing a key
key <- data.frame(IntColumn = 2L)

# write the flob to the database in column 'BlobColumn'
write_flob(flob, "BlobColumn", "Table1", key, conn, exists = FALSE)

DBI::dbReadTable(conn, "Table1")

# read the flob
flob2 <- read_flob("BlobColumn", "Table1", key, conn)
str(flob2)

# delete the flob
delete_flob("BlobColumn", "Table1", key, conn)

DBI::dbReadTable(conn, "Table1")

# close the connection
DBI::dbDisconnect(conn)
```

## Inspiration

- [blob](https://github.com/tidyverse/blob)
- [flobr](https://github.com/poissonconsulting/flobr)

## Contribution

Please report any [issues](https://github.com/poissonconsulting/dbflobr/issues).

[Pull requests](https://github.com/poissonconsulting/dbflobr/pulls) are always welcome.

## Code of Conduct

Please note that the dbflobr project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html).
By contributing to this project, you agree to abide by its terms