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