pub struct TableDef {
pub name: String,
pub columns: Vec<ColumnDef>,
pub primary_key: Vec<String>,
pub indexes: Vec<IndexDef>,
pub constraints: Vec<Constraint>,
pub version: u32,
pub created_at: u64,
pub updated_at: u64,
}Expand description
Table definition containing all metadata.
Fields§
§name: StringTable name (unique within database).
columns: Vec<ColumnDef>Column definitions in order.
primary_key: Vec<String>Primary key column names (can be composite).
indexes: Vec<IndexDef>Index definitions.
constraints: Vec<Constraint>Table-level constraints.
version: u32Schema version (for migrations).
created_at: u64Creation timestamp.
updated_at: u64Last modification timestamp.
Implementations§
Source§impl TableDef
impl TableDef
Sourcepub fn new_at(name: impl Into<String>, now: u64) -> Self
pub fn new_at(name: impl Into<String>, now: u64) -> Self
Create a definition with an explicit host clock (Unix seconds).
Sourcepub fn add_column(self, column: ColumnDef) -> Self
pub fn add_column(self, column: ColumnDef) -> Self
Add a column to the table.
Sourcepub fn primary_key(self, columns: Vec<String>) -> Self
pub fn primary_key(self, columns: Vec<String>) -> Self
Set primary key columns.
Sourcepub fn add_constraint(self, constraint: Constraint) -> Self
pub fn add_constraint(self, constraint: Constraint) -> Self
Add a constraint.
Sourcepub fn get_column(&self, name: &str) -> Option<&ColumnDef>
pub fn get_column(&self, name: &str) -> Option<&ColumnDef>
Get a column by name.
Sourcepub fn column_index(&self, name: &str) -> Option<usize>
pub fn column_index(&self, name: &str) -> Option<usize>
Get a column’s ordinal by name.
Sourcepub fn is_primary_key_column(&self, name: &str) -> bool
pub fn is_primary_key_column(&self, name: &str) -> bool
Check whether a column is part of the primary key.
Sourcepub fn validate(&self) -> Result<(), TableDefError>
pub fn validate(&self) -> Result<(), TableDefError>
Validate references within the table definition.
Trait Implementations§
impl Eq for TableDef
impl StructuralPartialEq for TableDef
Auto Trait Implementations§
impl Forget for TableDef
impl Freeze for TableDefwhere
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
PhantomData<ColumnDef>: Freeze,
PhantomData<String>: Freeze,
PhantomData<IndexDef>: Freeze,
PhantomData<Constraint>: Freeze,
impl Move for TableDef
impl RefUnwindSafe for TableDef
impl Send for TableDef
impl Sync for TableDef
impl Unpin for TableDef
impl UnsafeUnpin for TableDefwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<ColumnDef>: UnsafeUnpin,
PhantomData<String>: UnsafeUnpin,
PhantomData<IndexDef>: UnsafeUnpin,
PhantomData<Constraint>: UnsafeUnpin,
impl UnwindSafe for TableDef
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more