Learn R Programming

db.r (version 0.1.3)

db.new: Connection to a database

Description

Returns a structure that helps you query and interact with your database.

Usage

db.new(hostname = NA, port = NA, username = NA, password = NA, dbname = NA, filename = NA, dbtype = NA, profile = NA)

Arguments

hostname
the hostname for your database (i.e. dw.muppets.com)
port
the port for your database (i.e. 5432 or 3309)
username
the username for your database (i.e. kermit)
password
the password for your database (i.e. supersecret)
dbname
the dbname for your database (i.e. dw, production, staging)
filename
filepath to SQLite db
dbtype
the dbtype for your database (postgres, mysql, sqlite, or redshift)
profile
the profile for your database (a connection profile)

Examples

Run this code
db <- DemoDB()
db$query("select * from Artist;")
db$tables
db$tables$Artist
db$tables$Artist$head()
db$tables$Artist$all()
db$tables$Artist$sample()
db$query("select * from Artist;")
db$find_table("A*")
db$find_column("*Id*")
## Not run: 
# db <- db.new(username="kermit", password="rainbowconnection",
# db$save_credentails(profile="muppetdb")
# 
# db <- db.new(profile="mysql_local")
# db$query("select * from foo limit 10;")
# ## End(Not run)

Run the code above in your browser using DataLab