Skip to main content

Schema

Struct Schema 

Source
pub struct Schema { /* private fields */ }
Expand description

Table schema definition

Implementations§

Source§

impl Schema

Source

pub fn new(table_name: impl Into<String>, columns: Vec<SchemaColumn>) -> Self

Create a new schema with the given table name and columns

Source

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

Source

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.

Source

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

Source

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

Source

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.

Source

pub fn column_count(&self) -> usize

Get the number of columns

Source

pub fn is_empty(&self) -> bool

Check if the schema has any columns

Source

pub fn table_name(&self) -> &str

Return the authoritative table name.

Source

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.

Source

pub fn columns(&self) -> &[SchemaColumn]

Return the authoritative column definitions.

Source

pub fn foreign_keys(&self) -> &[ForeignKeyConstraint]

Return the table foreign-key constraints.

Source

pub fn table_checks(&self) -> &[String]

Return the table-level CHECK expressions.

Source

pub fn constraints(&self) -> &[SchemaConstraint]

Return durable named SQL constraints in creation order.

Source

pub fn find_constraint(&self, name: &str) -> Option<&SchemaConstraint>

Return a named constraint using catalog case-insensitive identity.

Source

pub fn created_at(&self) -> DateTime<Utc>

Return the schema creation timestamp.

Source

pub fn updated_at(&self) -> DateTime<Utc>

Return the schema update timestamp.

Source

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

Source

pub fn get_column(&self, index: usize) -> Option<&SchemaColumn>

Get a column by index

Source

pub fn get_column_by_name(&self, name: &str) -> Option<&SchemaColumn>

Get a column by name (case-insensitive)

Source

pub fn get_column_index(&self, name: &str) -> Option<usize>

Get the column index by name (case-insensitive)

Source

pub fn get_column_type(&self, name: &str) -> Option<DataType>

Get the data type of a column by name

Source

pub fn has_column(&self, name: &str) -> bool

Check if a column exists by name

Source

pub fn column_names(&self) -> Vec<&str>

Get all column names as borrowed strings (allocates Vec but not strings)

Source

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.

Source

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.

Source

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.

Source

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

Source

pub fn primary_key_columns(&self) -> Vec<&SchemaColumn>

Get the primary key columns

Source

pub fn has_primary_key(&self) -> bool

Check if the schema has a primary key

Source

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

Source

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

Source

pub fn validate_column_count(&self, expected: usize) -> Result<()>

Validate column count matches expected value

Source

pub fn mark_updated(&mut self)

Mark the schema as updated (sets updated_at to now)

Source

pub fn rename_table(&mut self, name: impl Into<String>)

Rename the table while keeping its normalized identity synchronized.

Source

pub fn add_column(&mut self, column: SchemaColumn) -> Result<()>

Add a column to the schema

Source

pub fn remove_column(&mut self, name: &str) -> Result<SchemaColumn>

Remove a column by name

Source

pub fn rename_column( &mut self, old_name: &str, new_name: impl Into<String>, ) -> Result<()>

Rename a column

Source

pub fn modify_column( &mut self, name: &str, data_type: Option<DataType>, nullable: Option<bool>, ) -> Result<()>

Modify a column’s properties (except name)

Source

pub fn set_column_default( &mut self, name: &str, default_expr: Option<String>, default_value: Option<Value>, ) -> Result<()>

Set or replace a column default expression and its pre-computed value.

Source

pub fn set_column_check( &mut self, name: &str, check_expr: Option<String>, ) -> Result<()>

Set or replace a column CHECK expression.

Trait Implementations§

Source§

impl Clone for Schema

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Schema

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Schema

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Schema

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Schema

Source§

impl PartialEq for Schema

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl RowSchema for Schema

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> CompactArcDrop for T

Source§

unsafe fn drop_and_dealloc(ptr: *mut u8)

Drop the contained data and deallocate the header+data allocation. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V