Some efforts were undertaken to encrypt and to protect the password in the private area of the class. The class stores the password hidden and inaccessible. Please let me know, in case you discover a way how to access the password!
<- rocker::newDB() # New database handling object
db #> dctr | New object
$setupDriver( # Setup PostgreSQL database with stored password (password and user are hidden - default behavior)
db::Postgres(),
RPostgreshost = "127.0.0.1", port = "5432", dbname = "mydb",
user = "postgres", password = "password",
protect = c("password", "user")
)#> Dctr | Driver load RPostgres
$connect() # Open connection 1; Password is stored in the class and does not need to be provided.
db#> DCtr | Database connected
<- db$getQuery("SELECT * FROM mtcars;") # Get query 1
output1 #> DCtR | Send query 21 characters
#> DCtR | Fetch rows all -> Received 32 rows, 11 columns, 4824 bytes
#> DCtR | Rows fetched 32
#> DCtR | Has completed yes
#> DCtr | Clear result
$disconnect() # Close connection 1
db#> Dctr | Database disconnected
$connect() # Open connection 2; Password is stored in the class and does not need to be provided.
db#> DCtr | Database connected
<- db$getQuery("SELECT * FROM mtcars;") # Get query 2
output2 #> DCtR | Send query 21 characters
#> DCtR | Fetch rows all -> Received 32 rows, 11 columns, 4824 bytes
#> DCtR | Rows fetched 32
#> DCtR | Has completed yes
#> DCtr | Clear result
$disconnect() # Close connection 2
db#> Dctr | Database disconnected
$unloadDriver() # Reset database handling object
db#> dctr | Driver unload RPostgres
In case you do not want to store the password in the class, you will need to provide it each time a connection is opened.
<- rocker::newDB() # New database handling object
db #> dctr | New object
$setupDriver( # Setup PostgreSQL database without stored password
db::Postgres(),
RPostgreshost = "127.0.0.1", port = "5432", dbname = "mydb",
user = "postgres"
)#> Dctr | Driver load RPostgres
$connect(password = "password") # Open connection 1; Password needs to be provided.
db#> DCtr | Database connected
<- db$getQuery("SELECT * FROM mtcars;") # Get query 1
output1 #> DCtR | Send query 21 characters
#> DCtR | Fetch rows all -> Received 32 rows, 11 columns, 4824 bytes
#> DCtR | Rows fetched 32
#> DCtR | Has completed yes
#> DCtr | Clear result
$disconnect() # Close connection 1
db#> Dctr | Database disconnected
$connect(password = "password") # Open connection 2; Password needs to be provided.
db#> DCtr | Database connected
<- db$getQuery("SELECT * FROM mtcars;") # Get query 2
output2 #> DCtR | Send query 21 characters
#> DCtR | Fetch rows all -> Received 32 rows, 11 columns, 4824 bytes
#> DCtR | Rows fetched 32
#> DCtR | Has completed yes
#> DCtr | Clear result
$disconnect() # Close connection 2
db#> Dctr | Database disconnected
$unloadDriver() # Reset database handling object
db#> dctr | Driver unload RPostgres