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: StringColumn name.
data_type: ColumnTypeCompile-time validated data type.
nullable: boolWhether the column accepts NULL.
primary_key: boolWhether this column is a primary key.
unique: boolWhether this column has a UNIQUE constraint.
default: Option<String>Default value expression.
foreign_key: Option<ForeignKey>Foreign key reference.
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.
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.
This method is fail-soft: invalid type combinations are allowed to
continue without panicking so production callers cannot crash on
dynamic schema input. Use Column::try_primary_key for strict mode.
Sourcepub fn try_primary_key(self) -> Result<Self, String>
pub fn try_primary_key(self) -> Result<Self, String>
Strict variant of Column::primary_key.
Returns an error instead of panicking when type policy disallows PK.
Sourcepub fn unique(self) -> Self
pub fn unique(self) -> Self
Set as unique with compile-time validation. Validates that the column type supports indexing.
This method is fail-soft: invalid type combinations are allowed to
continue without panicking so production callers cannot crash on
dynamic schema input. Use Column::try_unique for strict mode.
Sourcepub fn try_unique(self) -> Result<Self, String>
pub fn try_unique(self) -> Result<Self, String>
Strict variant of Column::unique.
Returns an error instead of panicking when type policy disallows UNIQUE.
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