Column

Struct Column 

Source
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

Source

pub fn new(name: impl Into<String>, data_type: ColumnType) -> Self

Create a new column with compile-time type validation.

Source

pub fn not_null(self) -> Self

Source

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).

Source

pub fn unique(self) -> Self

Set as unique with compile-time validation.

Validates that the column type supports indexing.

Source

pub fn default(self, val: impl Into<String>) -> Self

Source

pub fn references(self, table: &str, column: &str) -> Self

Add a foreign key reference to another table.

§Example
Column::new("user_id", ColumnType::Uuid)
    .references("users", "id")
    .on_delete(FkAction::Cascade)
Source

pub fn on_delete(self, action: FkAction) -> Self

Set the ON DELETE action for the foreign key.

Source

pub fn on_update(self, action: FkAction) -> Self

Set the ON UPDATE action for the foreign key.

Source

pub fn check(self, expr: CheckExpr) -> Self

Add a CHECK constraint (AST-native)

Source

pub fn check_named(self, name: impl Into<String>, expr: CheckExpr) -> Self

Add a named CHECK constraint

Source

pub fn deferrable(self) -> Self

Make foreign key DEFERRABLE

Source

pub fn initially_deferred(self) -> Self

Make foreign key DEFERRABLE INITIALLY DEFERRED

Source

pub fn initially_immediate(self) -> Self

Make foreign key DEFERRABLE INITIALLY IMMEDIATE

Source

pub fn generated_stored(self, expr: impl Into<String>) -> Self

GENERATED ALWAYS AS (expr) STORED

Source

pub fn generated_identity(self) -> Self

GENERATED ALWAYS AS IDENTITY

Source

pub fn generated_by_default(self) -> Self

GENERATED BY DEFAULT AS IDENTITY

Trait Implementations§

Source§

impl Clone for Column

Source§

fn clone(&self) -> Column

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Column

Source§

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

Formats the value using the given formatter. Read more

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> 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> 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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.