import_all_flobs: Import all flobs.

View source: R/import.R

import_all_flobsR Documentation

Import all flobs.

Description

Import flobs to SQLite database from directory. Table and column names are matched to directory names within main directory. Values in file names are matched to table primary key to determine where to write flob.

Usage

import_all_flobs(
  conn,
  dir = ".",
  sep = "_-_",
  pattern = ".*",
  sub = FALSE,
  exists = FALSE,
  replace = FALSE
)

Arguments

conn

A SQLite connection object.

dir

A string of the path to the directory to import the files from. Files need to be within nested folders like 'table1/column1/a.csv'. This structure is created automatically if save_all_flobs() function is used.

sep

A string of the separator between values in file names.

pattern

A regular expression specifying the pattern file names must match.

sub

A logical scalar specifying whether to import flobs based on their filename (sub = FALSE) or the name of their subdirectory (sub = TRUE) which must only contain 1 file. If sub = NA and replace = TRUE then the names of the subdirectories are used irrespective of whether they include files and existing flobs are deleted if the corresponding subdirectory is empty. If sub = TRUE or sub = NA then recursion is just one subfolder deep.

exists

A logical scalar specifying whether the column must (TRUE) or mustn't (FALSE) already exist or whether it doesn't matter (NA). IF FALSE, a new BLOB column is created.

replace

A flag indicating whether to replace existing flobs (TRUE) or not (FALSE).

Value

An invisible named list indicating directory path, file names and whether files were successfully written to database.

Examples

conn <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
DBI::dbGetQuery(conn, "CREATE TABLE Table1 (CharColumn TEXT PRIMARY KEY NOT NULL)")
DBI::dbWriteTable(conn, "Table1", data.frame(CharColumn = c("a", "b")), append = TRUE)
flob <- flobr::flob_obj
write_flob(flob, "BlobColumn", "Table1", data.frame(CharColumn = "a"), conn)
dir <- file.path(tempdir(), "import_all")
save_all_flobs(conn = conn, dir = dir)
import_all_flobs(conn, dir, exists = TRUE, replace = TRUE)
DBI::dbDisconnect(conn)

dbflobr documentation built on Aug. 20, 2022, 1:06 a.m.