replace outputpath with outputfolder for consitent argument names in the package.
This commit is contained in:
parent
57d40c2a7d
commit
f7a42d5482
42
R/writeDDL.R
42
R/writeDDL.R
|
@ -22,95 +22,95 @@
|
|||
#'
|
||||
#' @param targetDialect The dialect of the target database. Choices are "oracle", "postgresql", "pdw", "redshift", "impala", "netezza", "bigquery", "sql server"
|
||||
#' @param cdmVersion The version of the CDM you are creating, e.g. 5.3, 5.4
|
||||
#' @param outputpath The directory or folder where the SQL file should be saved.
|
||||
#' @param outputfolder The directory or folder where the SQL file should be saved.
|
||||
#' @param cdmDatabaseSchema The schema of the CDM instance where the DDL will be run. For example, this would be "ohdsi.dbo" when testing on sql server.
|
||||
#' Defaults to "@cdmDatabaseSchema"
|
||||
#'
|
||||
#' @export
|
||||
writeDdl <- function(targetDialect, cdmVersion, outputpath, cdmDatabaseSchema = "@cdmDatabaseSchema") {
|
||||
writeDdl <- function(targetDialect, cdmVersion, outputfolder, cdmDatabaseSchema = "@cdmDatabaseSchema") {
|
||||
|
||||
# argument checks
|
||||
stopifnot(targetDialect %in% c("oracle", "postgresql", "pdw", "redshift", "impala", "netezza", "bigquery", "sql server"))
|
||||
stopifnot(cdmVersion %in% listSupportedVersions())
|
||||
stopifnot(is.character(cdmDatabaseSchema))
|
||||
|
||||
if(missing(outputpath)) {
|
||||
outputpath <- file.path("ddl", cdmVersion, gsub(" ", "_", targetDialect))
|
||||
if(missing(outputfolder)) {
|
||||
outputfolder <- file.path("ddl", cdmVersion, gsub(" ", "_", targetDialect))
|
||||
}
|
||||
|
||||
if(!dir.exists(outputpath)) dir.create(outputpath, showWarnings = FALSE, recursive = TRUE)
|
||||
if(!dir.exists(outputfolder)) dir.create(outputfolder, showWarnings = FALSE, recursive = TRUE)
|
||||
|
||||
sql <- createDdl(cdmVersion)
|
||||
sql <- SqlRender::render(sql = sql, cdmDatabaseSchema = cdmDatabaseSchema, targetDialect = targetDialect)
|
||||
sql <- SqlRender::translate(sql, targetDialect = targetDialect)
|
||||
|
||||
filename <- paste("OMOPCDM", gsub(" ", "_", targetDialect), cdmVersion, "ddl.sql", sep = "_")
|
||||
SqlRender::writeSql(sql = sql, targetFile = file.path(outputpath, filename))
|
||||
SqlRender::writeSql(sql = sql, targetFile = file.path(outputfolder, filename))
|
||||
invisible(filename)
|
||||
}
|
||||
|
||||
#' @describeIn writeDdl writePrimaryKeys Write the SQL code that creates the primary keys to a file.
|
||||
#' @export
|
||||
writePrimaryKeys <- function(targetDialect, cdmVersion, outputpath, cdmDatabaseSchema = "@cdmDatabaseSchema") {
|
||||
writePrimaryKeys <- function(targetDialect, cdmVersion, outputfolder, cdmDatabaseSchema = "@cdmDatabaseSchema") {
|
||||
|
||||
# argument checks
|
||||
stopifnot(targetDialect %in% c("oracle", "postgresql", "pdw", "redshift", "impala", "netezza", "bigquery", "sql server"))
|
||||
stopifnot(cdmVersion %in% listSupportedVersions())
|
||||
stopifnot(is.character(cdmDatabaseSchema))
|
||||
|
||||
if(missing(outputpath)) {
|
||||
outputpath <- file.path("ddl", cdmVersion, gsub(" ", "_", targetDialect))
|
||||
if(missing(outputfolder)) {
|
||||
outputfolder <- file.path("ddl", cdmVersion, gsub(" ", "_", targetDialect))
|
||||
}
|
||||
|
||||
if(!dir.exists(outputpath)) dir.create(outputpath, showWarnings = FALSE, recursive = TRUE)
|
||||
if(!dir.exists(outputfolder)) dir.create(outputfolder, showWarnings = FALSE, recursive = TRUE)
|
||||
|
||||
sql <- createPrimaryKeys(cdmVersion)
|
||||
sql <- SqlRender::render(sql = sql, cdmDatabaseSchema = cdmDatabaseSchema, targetDialect = targetDialect)
|
||||
sql <- SqlRender::translate(sql, targetDialect = targetDialect)
|
||||
|
||||
filename <- paste("OMOPCDM", gsub(" ", "_", targetDialect), cdmVersion, "primary", "keys.sql", sep = "_")
|
||||
SqlRender::writeSql(sql = sql, targetFile = file.path(outputpath, filename))
|
||||
SqlRender::writeSql(sql = sql, targetFile = file.path(outputfolder, filename))
|
||||
invisible(filename)
|
||||
}
|
||||
|
||||
#' @describeIn writeDdl writeForeignKeys Write the SQL code that creates the foreign keys to a file.
|
||||
#' @export
|
||||
writeForeignKeys <- function(targetDialect, cdmVersion, outputpath, cdmDatabaseSchema = "@cdmDatabaseSchema") {
|
||||
writeForeignKeys <- function(targetDialect, cdmVersion, outputfolder, cdmDatabaseSchema = "@cdmDatabaseSchema") {
|
||||
|
||||
# argument checks
|
||||
stopifnot(targetDialect %in% c("oracle", "postgresql", "pdw", "redshift", "impala", "netezza", "bigquery", "sql server"))
|
||||
stopifnot(cdmVersion %in% listSupportedVersions())
|
||||
stopifnot(is.character(cdmDatabaseSchema))
|
||||
|
||||
if(missing(outputpath)) {
|
||||
outputpath <- file.path("ddl", cdmVersion, gsub(" ", "_", targetDialect))
|
||||
if(missing(outputfolder)) {
|
||||
outputfolder <- file.path("ddl", cdmVersion, gsub(" ", "_", targetDialect))
|
||||
}
|
||||
|
||||
if(!dir.exists(outputpath)) dir.create(outputpath, showWarnings = FALSE, recursive = TRUE)
|
||||
if(!dir.exists(outputfolder)) dir.create(outputfolder, showWarnings = FALSE, recursive = TRUE)
|
||||
|
||||
sql <- createForeignKeys(cdmVersion)
|
||||
sql <- SqlRender::render(sql = sql, cdmDatabaseSchema = cdmDatabaseSchema, targetDialect = targetDialect)
|
||||
sql <- SqlRender::translate(sql, targetDialect = targetDialect)
|
||||
|
||||
filename <- paste("OMOPCDM", gsub(" ", "_", targetDialect), cdmVersion, "constraints.sql", sep = "_")
|
||||
SqlRender::writeSql(sql = sql, targetFile = file.path(outputpath, filename))
|
||||
SqlRender::writeSql(sql = sql, targetFile = file.path(outputfolder, filename))
|
||||
invisible(filename)
|
||||
}
|
||||
|
||||
#' @describeIn writeDdl writeIndex Write the rendered and translated sql that creates recommended indexes to a file.
|
||||
#' @export
|
||||
writeIndex <- function(targetDialect, cdmVersion, outputpath, cdmDatabaseSchema = "@cdmDatabaseSchema") {
|
||||
writeIndex <- function(targetDialect, cdmVersion, outputfolder, cdmDatabaseSchema = "@cdmDatabaseSchema") {
|
||||
|
||||
# argument checks
|
||||
stopifnot(targetDialect %in% c("oracle", "postgresql", "pdw", "redshift", "impala", "netezza", "bigquery", "sql server"))
|
||||
stopifnot(cdmVersion %in% listSupportedVersions())
|
||||
stopifnot(is.character(cdmDatabaseSchema))
|
||||
|
||||
if(missing(outputpath)) {
|
||||
outputpath <- file.path("ddl", cdmVersion, gsub(" ", "_", targetDialect))
|
||||
if(missing(outputfolder)) {
|
||||
outputfolder <- file.path("ddl", cdmVersion, gsub(" ", "_", targetDialect))
|
||||
}
|
||||
|
||||
if(!dir.exists(outputpath)) dir.create(outputpath, showWarnings = FALSE, recursive = TRUE)
|
||||
if(!dir.exists(outputfolder)) dir.create(outputfolder, showWarnings = FALSE, recursive = TRUE)
|
||||
|
||||
sqlFilename <- paste0("OMOP_CDM_indices_v", cdmVersion, ".sql")
|
||||
sql <- readr::read_file(system.file(file.path("sql", "sql_server", sqlFilename), package = "CommonDataModel"))
|
||||
|
@ -118,6 +118,6 @@ writeIndex <- function(targetDialect, cdmVersion, outputpath, cdmDatabaseSchema
|
|||
sql <- SqlRender::translate(sql, targetDialect = targetDialect)
|
||||
|
||||
filename <- paste("OMOPCDM", gsub(" ", "_", targetDialect), cdmVersion, "indices.sql", sep = "_")
|
||||
SqlRender::writeSql(sql = sql, targetFile = file.path(outputpath, filename))
|
||||
SqlRender::writeSql(sql = sql, targetFile = file.path(outputfolder, filename))
|
||||
invisible(filename)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue