Skip to content

Commit

Permalink
Added support for returning option for dbxUpsert for MariaDB 10.5+ - c…
Browse files Browse the repository at this point in the history
…loses #37
  • Loading branch information
ankane committed May 16, 2024
1 parent 51f6fda commit b8b4d7f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.2 (unreleased)

- Added support for `returning` option for `dbxUpsert` for MariaDB 10.5+

## 0.3.1 (2023-12-11)

- Added support for `dbxUpsert` for SQL Server
Expand Down
6 changes: 4 additions & 2 deletions R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@ selectOrExecute <- function(conn, sql, records, returning) {
execute(conn, sql)
invisible()
} else {
if (!isPostgres(conn)) {
stop("returning is only supported with Postgres")
# allow for any MySQL adapter for now
# TODO add detection for MariaDB
if (!isPostgres(conn) && !isMySQL(conn)) {
stop("returning is only supported with Postgres and MariaDB")
}

if (inherits(returning, "SQL")) {
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/helper-is.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ isRMariaDB <- function(conn) {
inherits(conn, "MariaDBConnection")
}

isMariaDB <- function(conn) {
# RMariaDB uses MySQLConnection for MySQL for 1.3+
# TODO add detection for other adapters
inherits(conn, "MariaDBConnection")
}

isSQLite <- function(conn) {
inherits(conn, "SQLiteConnection")
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/helper-run-upsert-tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ runUpsertTests <- function(db, redshift=FALSE) {
})

test_that("upsert returning works", {
skip_if(!isPostgres(db) || redshift)
skip_if(!(isPostgres(db) || isMariaDB(db)) || redshift)

events <- data.frame(id=c(1, 2), city=c("San Francisco", "Boston"), stringsAsFactors=FALSE)
res <- dbxUpsert(db, "events", events, where_cols=c("id"), returning=c("id", "city"))
Expand Down

0 comments on commit b8b4d7f

Please sign in to comment.