dbLoginEM: Connect to the econModel database.

Description Usage Arguments Details Value Examples

View source: R/AmerAssocIndividInvestorsAAII.R

Description

Currently is only implemented to work on PostgreSQL or PostgreSQL-like databases. Try to connect or try to connect as "user".

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
dbLoginEM(
  driver,
  connName,
  user,
  password = user,
  host,
  dbname = user,
  port,
  tty,
  options,
  forceISOdate,
  env,
  display = TRUE,
  exec = TRUE
)

Arguments

driver

String. Defaults to getOption("econmodel_db_driver"). String. Default is "PostgreSQL". Currently only an implementation exists using PostgreSQL and PostgreSQL-like databases.

connName

String. Name of the database connection object. The default is "connEM".

user

String. Defaults to getOption("econmodel_db_user").

password

String. Defaults to "user". If missing, then defaults to getOption("econmodel_db_password").

host

String. Defaults to getOption("econmodel_db_host").

dbname

String. Defaults to "user". If missing, then defaults to getOption("econmodel_db_dbname").

port

Integer. Defaults to getOption("econmodel_db_port").

tty

Default to getOption("econmodel_db_tty").

options

Defaults to getOption("econmodel_db_dboptions").

forceISOdate

Logical. Default is getOption("econmodel_db_forceISOdate").

env

Environment. Default is the .Global environment. This is the environment to return the connection object "connEM".

display

Logical. Whether to display the query (defaults to TRUE).

exec

Logical. Whether to execute the query (defaults to TRUE).

Details

Upon namespace loading, the R option "econmodel_db_storage_name" is read. From this read value the other R options are set: "econmodel_db_user", "econmodel_db_password", and "econmodel_db_dbname".

See these mentioned defaults and other defaults in zzz.R.

If the R option "econmodel_db_storage_name" is not set, and thus the R options "econmodel_db_username", "econmodel_db_password", and "econmodel_db_dbname" are not set, and the user does not supply a "username", then "username", "password", and "dbname" default to the lowercase name of the tempdir().

Value

Invisibly a DBI connection in an object named "connEM" is created, connected, and assigned to the environment "env".

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
## Not run: 

# Reasons for an error:
#
# No permission
# Object already exists

# Tested with
# R 4.1.0
# PostgreSQL 13
# RStudio 1.4.17.17

# a typical workflow may follow #

# To change the default user to "postgres"
getOption("econmodel_db_user")
options(econmodel_db_storage_name = "postgres")
# In rstudio dev, do
#  (1) Session -> "Restart R",
#  (2) devtools::load_all(".")
getOption("econmodel_db_user")

dbLoginEM()
dbIsConnectedEM()
dbGetCurrentUserEM()
# "postgres"
dbGetInfoExtraEM()
dbCreateUserEM(user = "r_user", attributes = c("LOGIN", "CREATEDB", "CREATEROLE"))
dbExistsUserEM(user = "r_user")
dbCreateDbaseEM(dbname = "r_user")
dbLogoutEM()

dbLoginEM(user = "r_user")
dbIsConnectedEM()
dbGetCurrentUserEM()
# "r_user"
dbGetInfoExtraEM()
dbCreateSchemaEM(schema = "r_user")
dbGetInfoExtraEM()
dbLogoutEM()

# To change the default user to "r_user"
# if in package dev, in rstudio
# (1) Session -> "Restart R",
# (2) Session -> "Restart R",
# (3) options(econmodel_db_storage_name = "r_user")
# (4) devtools::load_all(".")
# (5) getOption("econmodel_db_user")

dbLoginEM()
dbGetCurrentUserEM()
dbGetInfoExtraEM()
dbLogoutEM()


## End(Not run)

AndreMikulec/econModel documentation built on June 30, 2021, 9:48 a.m.