Skip to content

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

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
Notifications You must be signed in to change notification settings

poissonconsulting/dbflobr

Repository files navigation

dbflobr

Lifecycle: stable R-CMD-check Codecov test coverage License: MIT CRAN status CRAN downloads

dbflobr reads and writes files to SQLite databases as flobs. A flob is a blob that preserves the file extension.

Installation

To install the latest release from CRAN

install.packages("dbflobr")

To install the developmental version from GitHub

# install.packages("remotes")
remotes::install_github("poissonconsulting/dbflobr")

Demonstration

library(dbflobr)

# convert a file to flob using flobr
flob <- flobr::flob(system.file("extdata", "flobr.pdf", package = "flobr"))
str(flob)
#> List of 1
#>  $ /Library/Frameworks/R.framework/Versions/4.1/Resources/library/flobr/extdata/flobr.pdf: raw [1:133851] 58 0a 00 00 ...
#>  - attr(*, "class")= chr [1:2] "flob" "blob"

# 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")
#>   IntColumn
#> 1         1
#> 2         2

# 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")
#>   IntColumn      BlobColumn
#> 1         1            <NA>
#> 2         2 blob[133.85 kB]

# read the flob
flob2 <- read_flob("BlobColumn", "Table1", key, conn)
str(flob2)
#> List of 1
#>  $ BlobColumn: raw [1:133851] 58 0a 00 00 ...
#>  - attr(*, "class")= chr [1:2] "flob" "blob"

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

DBI::dbReadTable(conn, "Table1")
#>   IntColumn BlobColumn
#> 1         1       <NA>
#> 2         2       <NA>

# close the connection
DBI::dbDisconnect(conn)

Inspiration

Contribution

Please report any issues.

Pull requests are always welcome.

Code of Conduct

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

About

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

Topics

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages