From 44ce3a5d28826603b22b4f67b9a54032214403e1 Mon Sep 17 00:00:00 2001 From: Dongdong Kong Date: Tue, 10 Oct 2023 16:35:40 +0800 Subject: [PATCH] add db_write_table.MySQLConnection --- NAMESPACE | 1 + R/db-io.R | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/NAMESPACE b/NAMESPACE index a9bff8dd8..1fdbf45d7 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/R/db-io.R b/R/db-io.R index 7dcdfba47..2b9f838fa 100644 --- a/R/db-io.R +++ b/R/db-io.R @@ -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, ...) {