RMariaDB: MariaDB Driver for R

You are viewing an old version of this article. View the current version here.

Description

RMariaDB is a database interface and MariaDB driver for R. This version is aimed at full compliance with R's DBI specification.

The link to the package on CRAN (R Package Repository) can be accessed from: CRAN RMariaDB

The package can be installed in R with the following statement:

install.packages("RMariaDB")

And loaded in the R environment executing:

library(RMariaDB)

Basic notions on R Programming can be found in article: R Statistical Programming Using MariaDB as the Background Database

RMariaDB Package Function Examples

library(DBI)
# Connect to my-db as defined in ~/.my.cnf
con <- dbConnect(RMariaDB::MariaDB(), group = "my-db")

dbListTables(con)
dbWriteTable(con, "mtcars", mtcars)
dbListTables(con)

dbListFields(con, "mtcars")
dbReadTable(con, "mtcars")

# You can fetch all results:
res <- dbSendQuery(con, "SELECT * FROM mtcars WHERE cyl = 4")
dbFetch(res)
dbClearResult(res)

# Or a chunk at a time
res <- dbSendQuery(con, "SELECT * FROM mtcars WHERE cyl = 4")
while(!dbHasCompleted(res)){
  chunk <- dbFetch(res, n = 5)
  print(nrow(chunk))
}
# Clear the result
dbClearResult(res)

# Disconnect from the database
dbDisconnect(con)

Comments

Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.