Types
Pool[T] = ref object defaultSize: Natural conns: seq[T] getDbProc: proc (): T poolExhaustedPolicy: PoolExhaustedPolicy lock: Lock
PoolExhaustedError = object of CatchableError
PoolExhaustedPolicy = enum pepRaise, pepExtend
Procs
func add[T: DbConn](pool: var Pool; dbConn: T)
-
Add a connection to the pool.
Use to return a borrowed connection to the pool.
func defaultSize(pool: Pool): Natural
proc newPool[T: DbConn](defaultSize: Positive; getDbProc: proc (): T = getDb; poolExhaustedPolicy = pepRaise): Pool[T]
-
Create a connection pool of the given size.
poolExhaustedPolicy defines how the pool reacts when a connection is requested but the pool has no connection available:
- pepRaise (default) means throw PoolExhaustedError
- pepExtend means throw “add another connection to the pool.”
proc pop[T: DbConn](pool: var Pool[T]): T
-
Take a connection from the pool.
If you're calling this manually, don't forget to add it back!