rok-tenant 0.3.9

Multi-tenancy support for the rok ecosystem (row-level and schema-level isolation)
Documentation
  • Coverage
  • 20%
    1 out of 5 items documented0 out of 1 items with examples
  • Size
  • Source code size: 11.66 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 477.51 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 14s Average build duration of successful builds.
  • all releases: 14s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ateeq1999

rok-tenant — Multi-tenancy for the rok ecosystem.

Provides row-level tenant isolation via task-local tenant ID storage and a Tower middleware that resolves the tenant per request.

Two resolution strategies are supported:

  • Shared table — A tenant_id column is filtered automatically via a global scope when #[model(tenant_scoped)] is applied.
  • Separate schemas — Use [TenantSource::Subdomain] to route each request to a dedicated PostgreSQL schema (integration with rok-orm schema switching is handled by the ORM layer).

Quick start

use rok_tenant::{TenantLayer, TenantSource, current_tenant_id};

// Extract tenant from X-Tenant-ID header
let app = Router::new()
    .nest("/", routes())
    .layer(TenantLayer::from_header("X-Tenant-ID"));

// Or from the subdomain
let app = Router::new()
    .nest("/", routes())
    .layer(TenantLayer::from_subdomain());

// Inside a handler or model method:
let tenant = current_tenant_id(); // → Option<i64>