Pool
#struct PoolA pool of connections, for programs that need several at once.
| Name | Type | Description |
|---|---|---|
conns | Vector<dyn Connection> | The connections. |
taken | Vector<int> | Which connections are taken. |
limit | int = 0 | The greatest number of connections. |
import db
import db.sqlite
func main:
mut pool := db.NewPool(2)
repeat 3:
println db.Add(pool, sqlite.Conn(sqlite.Open(":memory:")))
end
println db.Size(pool), db.Idle(pool), db.InUse(pool)
one := db.Acquire(pool)
two := db.Acquire(pool)
three := db.Acquire(pool)
println db.Leased(one), db.Leased(three), three == db.NO_LEASE
println db.Idle(pool), db.InUse(pool)
c := db.Conn(pool, one)
println db.QueryInt(c, "SELECT 6 * 7")
db.Release(pool, one)
db.Release(pool, two)
println db.Idle(pool), db.DropDead(pool)
db.CloseAll(pool)
db.Free(pool)
endtrue true false 2 2 0 true false true 0 2 42 2 0