| Title: | Database Management with R |
|---|---|
| Description: | Provides functions to manage databases: select, update, insert, and delete records, list tables, backup tables as CSV files, and import CSV files as tables. |
| Authors: | Roberto Villegas-Diaz [aut, cre] (ORCID: <https://orcid.org/0000-0001-5036-8661>), SPECIAL Research Group @ University of Reading [cph] |
| Maintainer: | Roberto Villegas-Diaz <[email protected]> |
| License: | GPL-3 |
| Version: | 0.0.4 |
| Built: | 2026-05-12 06:32:23 UTC |
| Source: | https://github.com/special-uor/dabr |
Combine attributes from a vector of strings.
attributes(...)attributes(...)
... |
Strings. |
Combined string with all the attributes.
dabr::attributes("A", "B", "C") dabr::attributes(c("A", "B", "C")) dabr::attributes(c("A", "B", "C"), "D", "E", "F")dabr::attributes("A", "B", "C") dabr::attributes(c("A", "B", "C")) dabr::attributes(c("A", "B", "C"), "D", "E", "F")
Close connection to database
close_conn(conn, ...) ## S3 method for class 'MariaDBConnection' close_conn(conn, ...) ## Default S3 method: close_conn(conn, ...)close_conn(conn, ...) ## S3 method for class 'MariaDBConnection' close_conn(conn, ...) ## Default S3 method: close_conn(conn, ...)
conn |
DB connection object. |
... |
Optional parameters. |
Other DB functions:
delete(),
insert(),
list_tables(),
open_conn_mysql(),
select_all(),
select(),
update()
## Not run: conn <- open_conn_mysql("sys", "root") close_conn(conn) ## End(Not run)## Not run: conn <- open_conn_mysql("sys", "root") close_conn(conn) ## End(Not run)
DELETE queryExecute DELETE query
delete(conn, ...) ## S3 method for class 'MariaDBConnection' delete(conn, ..., quiet = FALSE)delete(conn, ...) ## S3 method for class 'MariaDBConnection' delete(conn, ..., quiet = FALSE)
conn |
DB connection object. |
... |
|
quiet |
Boolean flag to hide status messages. |
Other DB functions:
close_conn(),
insert(),
list_tables(),
open_conn_mysql(),
select_all(),
select(),
update()
## Not run: conn <- open_conn_mysql("sys", "root") out <- delete(conn, "DELETE sys_config SET value = 1") close_conn(conn) ## End(Not run)## Not run: conn <- open_conn_mysql("sys", "root") out <- delete(conn, "DELETE sys_config SET value = 1") close_conn(conn) ## End(Not run)
Get attributes of a table
get_attr(conn, ...) ## S3 method for class 'MariaDBConnection' get_attr(conn, name, ...)get_attr(conn, ...) ## S3 method for class 'MariaDBConnection' get_attr(conn, name, ...)
conn |
DB connection object. |
... |
Optional parameters. |
name |
Table name. |
List of attributes for table name.
INSERT queryExecute INSERT query
insert(conn, ...) ## S3 method for class 'MariaDBConnection' insert(conn, ..., quiet = FALSE)insert(conn, ...) ## S3 method for class 'MariaDBConnection' insert(conn, ..., quiet = FALSE)
conn |
DB connection object. |
... |
|
quiet |
Boolean flag to hide status messages. |
Other DB functions:
close_conn(),
delete(),
list_tables(),
open_conn_mysql(),
select_all(),
select(),
update()
## Not run: conn <- open_conn_mysql("sys", "root") query <- paste0( "INSERT INTO sys_config (variable, value, set_time, set_by) VALUES ", "('test_var', 999, '", Sys.time(), "', NULL)" ) out <- insert(conn, query) close_conn(conn) ## End(Not run)## Not run: conn <- open_conn_mysql("sys", "root") query <- paste0( "INSERT INTO sys_config (variable, value, set_time, set_by) VALUES ", "('test_var', 999, '", Sys.time(), "', NULL)" ) out <- insert(conn, query) close_conn(conn) ## End(Not run)
Verify if connection object is still valid, is connected to the database server.
is.connected(conn, ...) ## S3 method for class 'MariaDBConnection' is.connected(conn, ...)is.connected(conn, ...) ## S3 method for class 'MariaDBConnection' is.connected(conn, ...)
conn |
DB connection object. |
... |
Optional parameters. |
Connection status.
List tables
list_tables(conn, ...) ## S3 method for class 'MariaDBConnection' list_tables(conn, quiet = FALSE, attr = TRUE, ...)list_tables(conn, ...) ## S3 method for class 'MariaDBConnection' list_tables(conn, quiet = FALSE, attr = TRUE, ...)
conn |
DB connection object. |
... |
Optional parameters. |
quiet |
Boolean flag to hide status messages. |
attr |
Boolean flag to list the attributes of each table. |
If quiet = TRUE returns a list with the tables' names. If
attr = TRUE includes each attribute of the tables.
Other DB functions:
close_conn(),
delete(),
insert(),
open_conn_mysql(),
select_all(),
select(),
update()
Uses RMariaDB to open a connection to a MySQL database.
open_conn_mysql( dbname, user = "root", password = NULL, host = "127.0.0.1", port = 3306 )open_conn_mysql( dbname, user = "root", password = NULL, host = "127.0.0.1", port = 3306 )
dbname |
Database/Schema name. |
user |
Username of database owner. |
password |
Password (default: |
host |
Database host, it can be local (default) or remote. |
port |
Database port. |
MariaDBConnection connection object.
Other DB functions:
close_conn(),
delete(),
insert(),
list_tables(),
select_all(),
select(),
update()
## Not run: conn <- open_conn_mysql("sys") ## End(Not run)## Not run: conn <- open_conn_mysql("sys") ## End(Not run)
Add single quotes to string.
quote(str)quote(str)
str |
String. |
String surrounded by single quotes
dabr::quote("A") dabr::quote("l'A")dabr::quote("A") dabr::quote("l'A")
SELECT queryExecute SELECT query
select(conn, ...) ## S3 method for class 'MariaDBConnection' select(conn, ..., quiet = FALSE)select(conn, ...) ## S3 method for class 'MariaDBConnection' select(conn, ..., quiet = FALSE)
conn |
DB connection object. |
... |
|
quiet |
Boolean flag to hide status messages. |
Data frame containing the selected records.
Other DB functions:
close_conn(),
delete(),
insert(),
list_tables(),
open_conn_mysql(),
select_all(),
update()
## Not run: conn <- open_conn_mysql("sys", "root") out <- select(conn, "SELECT variable, value FROM sys_config") close_conn(conn) ## End(Not run)## Not run: conn <- open_conn_mysql("sys", "root") out <- select(conn, "SELECT variable, value FROM sys_config") close_conn(conn) ## End(Not run)
Select all the records inside a particular table, use the table
parameter.
select_all(conn, ...) ## S3 method for class 'MariaDBConnection' select_all(conn, table, quiet = FALSE, ...)select_all(conn, ...) ## S3 method for class 'MariaDBConnection' select_all(conn, table, quiet = FALSE, ...)
conn |
|
... |
Optional parameters. |
table |
Name of the table. |
quiet |
Boolean flag to hide status messages. |
Data frame with records.
Other DB functions:
close_conn(),
delete(),
insert(),
list_tables(),
open_conn_mysql(),
select(),
update()
## Not run: conn <- dabr::open_conn_mysql("sys", "root") out <- dabr::select_all(conn, "sys_config") dabr::close_conn(conn) ## End(Not run)## Not run: conn <- dabr::open_conn_mysql("sys", "root") out <- dabr::select_all(conn, "sys_config") dabr::close_conn(conn) ## End(Not run)
UPDATE queryExecute UPDATE query
update(conn, ...) ## S3 method for class 'MariaDBConnection' update(conn, ..., quiet = FALSE)update(conn, ...) ## S3 method for class 'MariaDBConnection' update(conn, ..., quiet = FALSE)
conn |
DB connection object. |
... |
|
quiet |
Boolean flag to hide status messages. |
Other DB functions:
close_conn(),
delete(),
insert(),
list_tables(),
open_conn_mysql(),
select_all(),
select()
## Not run: conn <- open_conn_mysql("sys", "root") out <- update(conn, "UPDATE sys_config SET value = 1") close_conn(conn) ## End(Not run)## Not run: conn <- open_conn_mysql("sys", "root") out <- update(conn, "UPDATE sys_config SET value = 1") close_conn(conn) ## End(Not run)