Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
1d7c955805 | |||
9625ac6a5e |
@ -1,6 +1,6 @@
|
||||
# Package
|
||||
|
||||
version = "1.0.1"
|
||||
version = "1.0.2"
|
||||
author = "Jonathan Bernard"
|
||||
description = "Lightweight Postgres ORM for Nim."
|
||||
license = "GPL-3.0"
|
||||
|
@ -62,6 +62,8 @@ proc maintain(pool: DbConnPool): void =
|
||||
let freeConns = pool.conns.filterIt(it.free)
|
||||
if pool.conns.len > pool.cfg.poolSize and freeConns.len > 0:
|
||||
let numToCull = min(freeConns.len, pool.conns.len - pool.cfg.poolSize)
|
||||
|
||||
if numToCull > 0:
|
||||
let toCull = freeConns[0..numToCull]
|
||||
pool.conns.keepIf((pc) => toCull.allIt(it.id != pc.id))
|
||||
for culled in toCull:
|
||||
@ -93,5 +95,5 @@ proc release*(pool: DbConnPool, connId: int): void =
|
||||
|
||||
template withConn*(pool: DbConnPool, stmt: untyped): untyped =
|
||||
let (connId, conn {.inject.}) = take(pool)
|
||||
stmt
|
||||
release(pool, connId)
|
||||
try: stmt
|
||||
finally: release(pool, connId)
|
||||
|
Reference in New Issue
Block a user