pub struct Schema { /* private fields */ }Expand description
Table schema definition
Implementations§
Source§impl Schema
impl Schema
Sourcepub fn new(table_name: impl Into<String>, columns: Vec<SchemaColumn>) -> Self
pub fn new(table_name: impl Into<String>, columns: Vec<SchemaColumn>) -> Self
Create a new schema with the given table name and columns
Sourcepub fn with_foreign_keys(
table_name: impl Into<String>,
columns: Vec<SchemaColumn>,
foreign_keys: Vec<ForeignKeyConstraint>,
) -> Self
pub fn with_foreign_keys( table_name: impl Into<String>, columns: Vec<SchemaColumn>, foreign_keys: Vec<ForeignKeyConstraint>, ) -> Self
Create a new schema with columns and foreign key constraints
Sourcepub fn with_constraints(
table_name: impl Into<String>,
columns: Vec<SchemaColumn>,
foreign_keys: Vec<ForeignKeyConstraint>,
table_checks: Vec<String>,
) -> Self
pub fn with_constraints( table_name: impl Into<String>, columns: Vec<SchemaColumn>, foreign_keys: Vec<ForeignKeyConstraint>, table_checks: Vec<String>, ) -> Self
Create a new schema with all table-level constraints.
Sourcepub fn with_timestamps(
table_name: impl Into<String>,
columns: Vec<SchemaColumn>,
created_at: DateTime<Utc>,
updated_at: DateTime<Utc>,
) -> Self
pub fn with_timestamps( table_name: impl Into<String>, columns: Vec<SchemaColumn>, created_at: DateTime<Utc>, updated_at: DateTime<Utc>, ) -> Self
Create a new schema with explicit timestamps
Sourcepub fn with_timestamps_and_foreign_keys(
table_name: impl Into<String>,
columns: Vec<SchemaColumn>,
foreign_keys: Vec<ForeignKeyConstraint>,
created_at: DateTime<Utc>,
updated_at: DateTime<Utc>,
) -> Self
pub fn with_timestamps_and_foreign_keys( table_name: impl Into<String>, columns: Vec<SchemaColumn>, foreign_keys: Vec<ForeignKeyConstraint>, created_at: DateTime<Utc>, updated_at: DateTime<Utc>, ) -> Self
Create a new schema with explicit timestamps and foreign key constraints
Sourcepub fn with_timestamps_and_constraints(
table_name: impl Into<String>,
columns: Vec<SchemaColumn>,
foreign_keys: Vec<ForeignKeyConstraint>,
table_checks: Vec<String>,
created_at: DateTime<Utc>,
updated_at: DateTime<Utc>,
) -> Self
pub fn with_timestamps_and_constraints( table_name: impl Into<String>, columns: Vec<SchemaColumn>, foreign_keys: Vec<ForeignKeyConstraint>, table_checks: Vec<String>, created_at: DateTime<Utc>, updated_at: DateTime<Utc>, ) -> Self
Create a schema with explicit timestamps and all table constraints.
Sourcepub fn column_count(&self) -> usize
pub fn column_count(&self) -> usize
Get the number of columns
Sourcepub fn table_name(&self) -> &str
pub fn table_name(&self) -> &str
Return the authoritative table name.
Sourcepub fn catalog_id(&self) -> [u8; 16]
pub fn catalog_id(&self) -> [u8; 16]
Return the durable 128-bit catalog identity. Detached schemas expose the reserved all-zero value until an engine admits them.
Sourcepub fn columns(&self) -> &[SchemaColumn]
pub fn columns(&self) -> &[SchemaColumn]
Return the authoritative column definitions.
Sourcepub fn foreign_keys(&self) -> &[ForeignKeyConstraint]
pub fn foreign_keys(&self) -> &[ForeignKeyConstraint]
Return the table foreign-key constraints.
Sourcepub fn table_checks(&self) -> &[String]
pub fn table_checks(&self) -> &[String]
Return the table-level CHECK expressions.
Sourcepub fn constraints(&self) -> &[SchemaConstraint]
pub fn constraints(&self) -> &[SchemaConstraint]
Return durable named SQL constraints in creation order.
Sourcepub fn find_constraint(&self, name: &str) -> Option<&SchemaConstraint>
pub fn find_constraint(&self, name: &str) -> Option<&SchemaConstraint>
Return a named constraint using catalog case-insensitive identity.
Sourcepub fn created_at(&self) -> DateTime<Utc>
pub fn created_at(&self) -> DateTime<Utc>
Return the schema creation timestamp.
Sourcepub fn updated_at(&self) -> DateTime<Utc>
pub fn updated_at(&self) -> DateTime<Utc>
Return the schema update timestamp.
Sourcepub fn find_column(&self, name: &str) -> Option<(usize, &SchemaColumn)>
pub fn find_column(&self, name: &str) -> Option<(usize, &SchemaColumn)>
Find a column by name (case-insensitive) Returns the column index and reference OPTIMIZATION: Uses cached column_index_map for O(1) lookup
Sourcepub fn get_column(&self, index: usize) -> Option<&SchemaColumn>
pub fn get_column(&self, index: usize) -> Option<&SchemaColumn>
Get a column by index
Sourcepub fn get_column_by_name(&self, name: &str) -> Option<&SchemaColumn>
pub fn get_column_by_name(&self, name: &str) -> Option<&SchemaColumn>
Get a column by name (case-insensitive)
Sourcepub fn get_column_index(&self, name: &str) -> Option<usize>
pub fn get_column_index(&self, name: &str) -> Option<usize>
Get the column index by name (case-insensitive)
Sourcepub fn get_column_type(&self, name: &str) -> Option<DataType>
pub fn get_column_type(&self, name: &str) -> Option<DataType>
Get the data type of a column by name
Sourcepub fn has_column(&self, name: &str) -> bool
pub fn has_column(&self, name: &str) -> bool
Check if a column exists by name
Sourcepub fn column_names(&self) -> Vec<&str>
pub fn column_names(&self) -> Vec<&str>
Get all column names as borrowed strings (allocates Vec but not strings)
Sourcepub fn column_names_owned(&self) -> &[String]
pub fn column_names_owned(&self) -> &[String]
Get all column names as owned strings (cached - only clones once)
This is more efficient than calling .columns.iter().map(|c| c.name.clone()).collect()
repeatedly, as the result is computed once and cached.
Sourcepub fn column_names_arc(&self) -> CompactArc<Vec<String>>
pub fn column_names_arc(&self) -> CompactArc<Vec<String>>
Get column names as Arc for zero-copy sharing with results
This is the most efficient way to pass column names to ExecutorResult::with_arc_columns
as it avoids any string cloning after the first call.
Sourcepub fn column_names_lower_arc(&self) -> CompactArc<Vec<String>>
pub fn column_names_lower_arc(&self) -> CompactArc<Vec<String>>
Get lowercase column names as Arc for zero-copy sharing
Uses the pre-computed name_lower from each SchemaColumn, avoiding
per-query to_lowercase() calls.
Sourcepub fn column_index_map(&self) -> &AHashMap<String, usize>
pub fn column_index_map(&self) -> &AHashMap<String, usize>
Get a cached map of lowercase column names to their indices OPTIMIZATION: Cached to avoid creating this map on every query
Sourcepub fn primary_key_columns(&self) -> Vec<&SchemaColumn>
pub fn primary_key_columns(&self) -> Vec<&SchemaColumn>
Get the primary key columns
Sourcepub fn has_primary_key(&self) -> bool
pub fn has_primary_key(&self) -> bool
Check if the schema has a primary key
Sourcepub fn primary_key_indices(&self) -> &[usize]
pub fn primary_key_indices(&self) -> &[usize]
Get the primary key column indices (cached for performance) OPTIMIZATION: Cached to avoid allocating Vec on every call
Sourcepub fn pk_column_index(&self) -> Option<usize>
pub fn pk_column_index(&self) -> Option<usize>
Get the single primary key column index (cached for performance) Returns None if there’s no PK or if PK is not an integer type OPTIMIZATION: Cached to avoid iteration on every INSERT
Sourcepub fn validate_column_count(&self, expected: usize) -> Result<()>
pub fn validate_column_count(&self, expected: usize) -> Result<()>
Validate column count matches expected value
Sourcepub fn mark_updated(&mut self)
pub fn mark_updated(&mut self)
Mark the schema as updated (sets updated_at to now)
Sourcepub fn rename_table(&mut self, name: impl Into<String>)
pub fn rename_table(&mut self, name: impl Into<String>)
Rename the table while keeping its normalized identity synchronized.
Sourcepub fn add_column(&mut self, column: SchemaColumn) -> Result<()>
pub fn add_column(&mut self, column: SchemaColumn) -> Result<()>
Add a column to the schema
Sourcepub fn remove_column(&mut self, name: &str) -> Result<SchemaColumn>
pub fn remove_column(&mut self, name: &str) -> Result<SchemaColumn>
Remove a column by name
Sourcepub fn rename_column(
&mut self,
old_name: &str,
new_name: impl Into<String>,
) -> Result<()>
pub fn rename_column( &mut self, old_name: &str, new_name: impl Into<String>, ) -> Result<()>
Rename a column
Sourcepub fn modify_column(
&mut self,
name: &str,
data_type: Option<DataType>,
nullable: Option<bool>,
) -> Result<()>
pub fn modify_column( &mut self, name: &str, data_type: Option<DataType>, nullable: Option<bool>, ) -> Result<()>
Modify a column’s properties (except name)