pub struct Column {
pub name: String,
pub data_type: ColumnType,
pub nullable: bool,
pub primary_key: bool,
pub unique: bool,
pub default: Option<String>,
pub foreign_key: Option<ForeignKey>,
pub check: Option<CheckConstraint>,
pub generated: Option<Generated>,
}Expand description
A column definition with compile-time type safety.
Fields§
§name: String§data_type: ColumnType§nullable: bool§primary_key: bool§unique: bool§default: Option<String>§foreign_key: Option<ForeignKey>§check: Option<CheckConstraint>CHECK constraint (Phase 1)
generated: Option<Generated>GENERATED column (Phase 3)
Implementations§
Source§impl Column
impl Column
Sourcepub fn new(name: impl Into<String>, data_type: ColumnType) -> Self
pub fn new(name: impl Into<String>, data_type: ColumnType) -> Self
Create a new column with compile-time type validation.
pub fn not_null(self) -> Self
Sourcepub fn primary_key(self) -> Self
pub fn primary_key(self) -> Self
Set as primary key with compile-time validation.
Validates that the column type can be a primary key. Panics at runtime if type doesn’t support PK (caught in tests).
Sourcepub fn unique(self) -> Self
pub fn unique(self) -> Self
Set as unique with compile-time validation.
Validates that the column type supports indexing.
pub fn default(self, val: impl Into<String>) -> Self
Sourcepub fn references(self, table: &str, column: &str) -> Self
pub fn references(self, table: &str, column: &str) -> Self
Sourcepub fn check_named(self, name: impl Into<String>, expr: CheckExpr) -> Self
pub fn check_named(self, name: impl Into<String>, expr: CheckExpr) -> Self
Add a named CHECK constraint
Sourcepub fn deferrable(self) -> Self
pub fn deferrable(self) -> Self
Make foreign key DEFERRABLE
Sourcepub fn initially_deferred(self) -> Self
pub fn initially_deferred(self) -> Self
Make foreign key DEFERRABLE INITIALLY DEFERRED
Sourcepub fn initially_immediate(self) -> Self
pub fn initially_immediate(self) -> Self
Make foreign key DEFERRABLE INITIALLY IMMEDIATE
Sourcepub fn generated_stored(self, expr: impl Into<String>) -> Self
pub fn generated_stored(self, expr: impl Into<String>) -> Self
GENERATED ALWAYS AS (expr) STORED
Sourcepub fn generated_identity(self) -> Self
pub fn generated_identity(self) -> Self
GENERATED ALWAYS AS IDENTITY
Sourcepub fn generated_by_default(self) -> Self
pub fn generated_by_default(self) -> Self
GENERATED BY DEFAULT AS IDENTITY
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Column
impl RefUnwindSafe for Column
impl Send for Column
impl Sync for Column
impl Unpin for Column
impl UnwindSafe for Column
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