Skip to content

Commit

Permalink
add db_write_table.MySQLConnection
Browse files Browse the repository at this point in the history
  • Loading branch information
kongdd committed Oct 10, 2023
1 parent 1e48cfa commit 44ce3a5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ S3method(db_table_temporary,"Microsoft SQL Server")
S3method(db_table_temporary,DBIConnection)
S3method(db_table_temporary,HDB)
S3method(db_write_table,DBIConnection)
S3method(db_write_table,MySQLConnection)
S3method(db_write_table,PostgreSQLConnection)
S3method(dbplyr_as_join_by,character)
S3method(dbplyr_as_join_by,default)
Expand Down
34 changes: 34 additions & 0 deletions R/db-io.R
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,40 @@ db_write_table.DBIConnection <- function(con,
table
}

#' @export
db_write_table.MySQLConnection <- function(con,
table,
types,
values,
temporary = TRUE,
...,
overwrite = FALSE) {
table <- as_table_ident(table)
check_character(types, allow_null = TRUE)
check_named(types)
check_bool(temporary)
check_bool(overwrite)

name <- vctrs::field(table, "table")
tryCatch(
dbWriteTable(
con,
name = name, #table_ident_to_id(table),
value = values,
field.types = types,
temporary = temporary,
overwrite = overwrite,
...,
row.names = FALSE
)
error = function(cnd) {
msg <- "Can't write table table {.field {format(table, con = con)}}."
cli_abort(msg, parent = cnd)
}
)
table
}

# Utility functions ------------------------------------------------------------

create_indexes <- function(con, table, indexes = NULL, unique = FALSE, ...) {
Expand Down

0 comments on commit 44ce3a5

Please sign in to comment.