pub struct SchemaConfig {
pub schema_prefix: Option<String>,
pub schema_suffix: Option<String>,
pub shared_schema: Option<String>,
pub auto_create: bool,
pub default_schema: Option<String>,
pub search_path_format: SearchPathFormat,
}Expand description
Configuration for schema-based tenant isolation.
Fields§
§schema_prefix: Option<String>Prefix for tenant schema names (e.g., “tenant_” -> “tenant_acme”).
schema_suffix: Option<String>Suffix for tenant schema names.
Name of the shared schema for common tables.
auto_create: boolWhether to create schemas automatically.
default_schema: Option<String>Default schema for new tenants.
search_path_format: SearchPathFormatSchema search path format.
Implementations§
Source§impl SchemaConfig
impl SchemaConfig
Sourcepub fn with_prefix(self, prefix: impl Into<String>) -> Self
pub fn with_prefix(self, prefix: impl Into<String>) -> Self
Set the schema prefix.
Sourcepub fn with_suffix(self, suffix: impl Into<String>) -> Self
pub fn with_suffix(self, suffix: impl Into<String>) -> Self
Set the schema suffix.
Set the shared schema name.
Sourcepub fn with_auto_create(self) -> Self
pub fn with_auto_create(self) -> Self
Enable auto-creation of schemas.
Sourcepub fn with_default_schema(self, schema: impl Into<String>) -> Self
pub fn with_default_schema(self, schema: impl Into<String>) -> Self
Set the default schema.
Sourcepub fn with_search_path(self, format: SearchPathFormat) -> Self
pub fn with_search_path(self, format: SearchPathFormat) -> Self
Set the search path format.
Sourcepub fn schema_name(&self, tenant_id: &str) -> String
pub fn schema_name(&self, tenant_id: &str) -> String
Generate the schema name for a tenant.
This is a pure string composition; no validation is performed. Use
Self::try_schema_name to reject tenant ids that would compose
into an invalid SQL identifier.
Sourcepub fn try_schema_name(&self, tenant_id: &str) -> QueryResult<String>
pub fn try_schema_name(&self, tenant_id: &str) -> QueryResult<String>
Generate the schema name for a tenant, validating the composed name.
The composed schema name must match the strict SQL identifier charset
^[A-Za-z_][A-Za-z0-9_]*$; otherwise a QueryError is returned so
a malicious tenant id is rejected before it can reach a SQL
statement.
Sourcepub fn search_path(&self, tenant_id: &str) -> String
pub fn search_path(&self, tenant_id: &str) -> String
Generate the search_path SQL for a tenant.
The composed tenant schema name is validated against the strict SQL
identifier charset ^[A-Za-z_][A-Za-z0-9_]*$ at the point of SQL
generation. A name outside that charset is emitted as a double-quoted
identifier (with embedded " doubled) so a malicious tenant id
cannot break out of the identifier and inject SQL. Use
Self::try_search_path to reject invalid tenant ids with an error
instead.
Sourcepub fn try_search_path(&self, tenant_id: &str) -> QueryResult<String>
pub fn try_search_path(&self, tenant_id: &str) -> QueryResult<String>
Generate the search_path SQL for a tenant, validating all schema names first.
Returns a QueryError if the composed tenant schema name or the
configured shared schema is not a valid SQL identifier
(^[A-Za-z_][A-Za-z0-9_]*$).
Trait Implementations§
Source§impl Clone for SchemaConfig
impl Clone for SchemaConfig
Source§fn clone(&self) -> SchemaConfig
fn clone(&self) -> SchemaConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more