Skip to content

Commit

Permalink
Merge pull request #58 from OHDSI/sqlite_dates
Browse files Browse the repository at this point in the history
convert dates to numbers when loading data to sqlite
  • Loading branch information
ginberg authored Jul 28, 2023
2 parents de2f359 + 8686477 commit c1ea79d
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions R/EunomiaData.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,20 @@ extractLoadData <- function(from, to, dbms = "sqlite", verbose = interactive())
# CDM table and column names should be lowercase: https://github.com/OHDSI/CommonDataModel/issues/509#issuecomment-1315754238
names(tableData) <- tolower(names(tableData))
tableName <- tools::file_path_sans_ext(tolower(dataFiles[i]))

if (dbms == "sqlite") {
# Convert dates and datetime to UNIX timestamp for sqlite
for (i in seq_len(ncol(tableData))) {
column <- tableData[[i]]
if (inherits(column, "Date")) {
tableData[, i] <- as.numeric(as.POSIXct(as.character(column), origin = "1970-01-01", tz = "GMT"))
}
if (inherits(column, "POSIXct")) {
tableData[, i] <- as.numeric(as.POSIXct(column, origin = "1970-01-01", tz = "GMT"))
}
}
}

DBI::dbWriteTable(conn = connection, name = tableName, value = tableData)
if (verbose) {
cli::cat_bullet(tableName, bullet = 1)
Expand Down

0 comments on commit c1ea79d

Please sign in to comment.