Skip to main content

ColumnDef

Struct ColumnDef 

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

Column definition for CREATE TABLE

This struct represents a column definition, including its type, constraints, and default value.

§Examples

use reinhardt_query::types::ddl::{ColumnDef, ColumnType};

// id INTEGER PRIMARY KEY AUTO_INCREMENT
let id_col = ColumnDef::new("id")
    .column_type(ColumnType::Integer)
    .primary_key(true)
    .auto_increment(true);

// name VARCHAR(100) NOT NULL
let name_col = ColumnDef::new("name")
    .column_type(ColumnType::String(Some(100)))
    .not_null(true);

Implementations§

Source§

impl ColumnDef

Source

pub fn new<T>(name: T) -> Self
where T: IntoIden,

Create a new column definition

Source

pub fn column_type(self, column_type: ColumnType) -> Self

Set the column type

Source

pub fn not_null(self, not_null: bool) -> Self

Set NOT NULL constraint

Source

pub fn unique(self, unique: bool) -> Self

Set UNIQUE constraint

Source

pub fn primary_key(self, primary_key: bool) -> Self

Set PRIMARY KEY constraint

Source

pub fn auto_increment(self, auto_increment: bool) -> Self

Set AUTO_INCREMENT attribute

Source

pub fn default(self, value: SimpleExpr) -> Self

Set DEFAULT value

Source

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

Set CHECK constraint

Source

pub fn comment<S: Into<String>>(self, comment: S) -> Self

Set column comment

Source

pub fn integer(self) -> Self

Set column type to INTEGER

Source

pub fn big_integer(self) -> Self

Set column type to BIGINT

Source

pub fn small_integer(self) -> Self

Set column type to SMALLINT

Source

pub fn tiny_integer(self) -> Self

Set column type to TINYINT

Source

pub fn string(self) -> Self

Set column type to VARCHAR (no length limit)

Source

pub fn string_len(self, len: u32) -> Self

Set column type to VARCHAR(len)

Source

pub fn char(self) -> Self

Set column type to CHAR (no length limit)

Source

pub fn char_len(self, len: u32) -> Self

Set column type to CHAR(len)

Source

pub fn text(self) -> Self

Set column type to TEXT

Source

pub fn boolean(self) -> Self

Set column type to BOOLEAN

Source

pub fn float(self) -> Self

Set column type to FLOAT

Source

pub fn double(self) -> Self

Set column type to DOUBLE

Source

pub fn decimal(self, precision: u32, scale: u32) -> Self

Set column type to DECIMAL(precision, scale)

Source

pub fn date(self) -> Self

Set column type to DATE

Source

pub fn time(self) -> Self

Set column type to TIME

Source

pub fn date_time(self) -> Self

Set column type to DATETIME

Source

pub fn timestamp(self) -> Self

Set column type to TIMESTAMP

Source

pub fn timestamp_with_time_zone(self) -> Self

Set column type to TIMESTAMPTZ

Source

pub fn uuid(self) -> Self

Set column type to UUID

Source

pub fn json(self) -> Self

Set column type to JSON

Source

pub fn json_binary(self) -> Self

Set column type to JSONB

Source

pub fn blob(self) -> Self

Set column type to BLOB

Source

pub fn binary(self, len: u32) -> Self

Set column type to BINARY(len)

Source

pub fn binary_len(self, len: u32) -> Self

Set column type to BINARY(len)

Alias for binary for reinhardt-query compatibility.

Source

pub fn var_binary(self, len: u32) -> Self

Set column type to VARBINARY(len)

Source

pub fn custom<S: Into<String>>(self, name: S) -> Self

Set column type to a custom type

Source

pub fn array(self, element_type: ColumnType) -> Self

Set column type to ARRAY of given element type

Trait Implementations§

Source§

impl Clone for ColumnDef

Source§

fn clone(&self) -> ColumnDef

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 ColumnDef

Source§

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

Formats the value using the given formatter. Read more

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