pool
Module[Pool]: an adapter over a pool of adapters.
Every call takes a connection (an adapter) from a utopia_pools::Pool,
puts it in this handle's settings (database, namespace, shared tables,
tenant, authorization, timeouts, debug, metadata), runs the call on it and
hands it back: reclaimed when the call succeeded, recovered (reconnected)
or discarded when it failed. A transaction pins one connection for its
whole body, retries included, so its statements share a session.
Timeouts are this handle's own: setting one opens no connection, and each connection is reset to them as it is checked out.
A connection whose call is cancelled (its future dropped) is destroyed, and so is a transaction's pinned connection when the handle is dropped: the pool frees their capacity rather than counting them lent forever.
use std::sync::Arc;
use utopia_database::Adapter;
use utopia_database::adapter::pool::{Pool, Pooled};
use utopia_database::adapter::postgres::Postgres;
use utopia_pools::Stack;
let connections = utopia_pools::Pool::new(
Stack::new(),
"postgres",
10,
|| async { Ok::<_, utopia_database::Error>(Pooled::new(Postgres::connect("postgres://root:password@localhost:5432/root").await?)) },
0.0,
)
.map_err(|e| utopia_database::Error::new(utopia_database::Kind::Exception, e.to_string()))?;
let adapter = Pool::new(connections);
adapter.set_database("appwrite")?;
adapter.create("appwrite").await?;Contents
use utopia_database::adapter::pool::Pool;pub struct Pool<S = Stack<Pooled>>An adapter over a pool of adapters. See the module docs.
Drop.use utopia_database::adapter::pool::Pooled;pub struct Pooled(pub Arc<dyn Adapter>)A pooled adapter: the resource of the utopia_pools::Pool a Pool
draws from.
Resource.