Learn R Programming

rpg (version 1.6)

push_conn: Multiple PostgreSQL connections

Description

Manage multiple connections on a stack

Usage

push_conn()

pop_conn()

swap_conn()

rotate_stack(n = 1L)

show_conn_stack()

Arguments

n

number of shifts

Details

These functions allow you to store multiple connections on a stack. They are only used for their side-effects. rpg stores an active connection pointer internally. This pointer can be moved onto the stack and manipulated. Once on the stack, the pointer is no longer active. You must use swap_conn or pop_conn to reactive a pushed connection, or call connect to create a new active connection.

push_conn pushes the current connection onto the connection stack leaving the active connection null.

pop_conn pops a connection off the stack and makes it active. Whatever connection was active when pop_conn is called will be disconnected and cleared. Use swap_conn to preserve the active connection.

swap_conn swaps the active connection with the connection on the top of the stack. If the stack is empty, the connection is swapped with a null connection.

rotate_stack moves the bottom of the stack to the top.

show_conn_stack returns a data frame with information about the connections on the stack.

Examples

Run this code
# NOT RUN {
# make some databases
dbs = paste0("rpgdb", 1:3)
lapply(paste("createdb", dbs), system)

# connect
connect(dbname = dbs[1]); push_conn()
connect(dbname = dbs[2]); push_conn()
connect(dbname = dbs[3]); push_conn()

show_conn_stack()
rotate_stack()
show_conn_stack()
rotate_stack(2)
show_conn_stack()
pop_conn()
show_conn_stack()
get_conn_info("dbname")
swap_conn()
show_conn_stack()
get_conn_info("dbname")
pop_conn()
show_conn_stack()
pop_conn()
show_conn_stack()
disconnect()
connect()
lapply(paste("dropdb", dbs), system)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab