pub struct TenantConn { /* private fields */ }Expand description
A database handle bound to the request’s tenant.
Obtained only as an axum extractor, and only on a route the resolution layer covers. There is no constructor:
use cratefield_core::TenantConn;
// No public constructor: a handler cannot build a handle for a
// tenant it was not given.
let _conn = TenantConn { tenant: todo!(), db: db() };Naming it is fine, which is what keeps a handler signature writable:
use cratefield_core::TenantConn;
async fn handler(_db: TenantConn) {}Implementations§
Source§impl TenantConn
impl TenantConn
Sourcepub fn tenancy(&self) -> Tenancy
pub fn tenancy(&self) -> Tenancy
Which tenancy shape served this request: a registry resolved it, or the deployment has no registry and this host is the one implicit tenant.
A routing fact, not a membership fact (#385):
Tenancy::FromRegistry says the registry named this tenant for
this host, and nothing about who the caller is to it. A rule that
needs membership reads this to fail closed under
Tenancy::FromRegistry — where “any verified caller” and “a
member of this tenant” are different sets — and to serve under
Tenancy::Sole, where they are the same set.
Trait Implementations§
Source§impl Clone for TenantConn
impl Clone for TenantConn
Source§impl Database for TenantConn
impl Database for TenantConn
fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
stmt: &'life1 Statement,
) -> Pin<Box<dyn Future<Output = Result<u64, DbError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn query<'life0, 'life1, 'async_trait>(
&'life0 self,
stmt: &'life1 Statement,
) -> Pin<Box<dyn Future<Output = Result<Rows, DbError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn batch_atomic<'life0, 'life1, 'async_trait>(
&'life0 self,
stmts: &'life1 [Statement],
) -> Pin<Box<dyn Future<Output = Result<(), DbError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§impl Debug for TenantConn
impl Debug for TenantConn
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Names the tenant and never the handle. Display for DbError
already scrubs a DSN out of a message (#135), but Debug
derives raw, and a database handle has no business being printed
at all — so this does not derive. The tenancy bit is shown: it is
a routing fact with nothing secret in it, and it is the first
question anyone debugging a refused request asks — did a registry
even resolve this tenant (#385)?