stack: Multiple PostgreSQL connections

Description Usage Arguments Details Examples

Description

Manage multiple connections on a stack

Usage

1
2
3
4
5
6
7
8
9

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

 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
## 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)
## End(Not run)

thk686/rpg documentation built on Sept. 5, 2019, 11:13 p.m.