| db_connect | R Documentation |
JSON configuration file.db_connect uses a JSON configuration file to create a database
connection. This configuration file will often exist outside a code package
so database credentials are not accidentally transmitted or shared.
db_connect(
file,
database,
config = TRUE,
foreign_keys = TRUE,
sslmode = NULL,
bigint = "integer64"
)
file |
|
database |
The name of the database within |
config |
A logical to skip the |
foreign_keys |
A logical for SQLite databases where foreign keys should
be enforced. Default is |
sslmode, bigint |
Deprecated arguments that will be ignored. |
If only one entry is in the JSON file, the database argument is
not needed.
If db_connect is attempted to be used with a file which is not
JSON, it will attempt to connect to an SQLite database, but it is
recommended that the config argument is set to FALSE in this
case.
MySQL, PostgreSQL, and SQLite connections are currently supported.
Database connection.
Stuart K. Grange
## Not run:
# Connect to an air quality database
db <- db_connect("connections.json", "air_quality")
# Use a json config file which looks similar to this:
string <- '
{
"driver": "MySQL",
"host": "172.31.4.159",
"database_name": "database_seven",
"user": "web",
"password": "read_password"
}'
# Connect, no need for second argument when one connection is present in
# configuration file
db_seven <- db_connect(string)
# A SQLite connection needs no configuration
con <- db_connect("../databases/air_quality_data.db", config = FALSE)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.