Struct sea_query::table::ColumnDef

source ·
pub struct ColumnDef { /* private fields */ }
Expand description

Specification of a table column

Implementations§

source§

impl ColumnDef

source

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

Construct a table column

source

pub fn new_with_type<T>(name: T, types: ColumnType) -> Selfwhere T: IntoIden,

Construct a table column with column type

source

pub fn not_null(&mut self) -> &mut Self

Set column not null

source

pub fn null(&mut self) -> &mut Self

Set column null

source

pub fn default<T>(&mut self, value: T) -> &mut Selfwhere T: Into<SimpleExpr>,

Set default value of a column

source

pub fn auto_increment(&mut self) -> &mut Self

Set column auto increment

source

pub fn unique_key(&mut self) -> &mut Self

Set column unique constraint

source

pub fn primary_key(&mut self) -> &mut Self

Set column as primary key

source

pub fn char_len(&mut self, length: u32) -> &mut Self

Set column type as char with custom length

source

pub fn char(&mut self) -> &mut Self

Set column type as char

source

pub fn string_len(&mut self, length: u32) -> &mut Self

Set column type as string with custom length

source

pub fn string(&mut self) -> &mut Self

Set column type as string

source

pub fn text(&mut self) -> &mut Self

Set column type as text

source

pub fn tiny_integer(&mut self) -> &mut Self

Set column type as tiny_integer

source

pub fn small_integer(&mut self) -> &mut Self

Set column type as small_integer

source

pub fn integer(&mut self) -> &mut Self

Set column type as integer

source

pub fn big_integer(&mut self) -> &mut Self

Set column type as big_integer

source

pub fn tiny_unsigned(&mut self) -> &mut Self

Set column type as tiny_unsigned

source

pub fn small_unsigned(&mut self) -> &mut Self

Set column type as small_unsigned

source

pub fn unsigned(&mut self) -> &mut Self

Set column type as unsigned

source

pub fn big_unsigned(&mut self) -> &mut Self

Set column type as big_unsigned

source

pub fn float(&mut self) -> &mut Self

Set column type as float

source

pub fn double(&mut self) -> &mut Self

Set column type as double

source

pub fn decimal_len(&mut self, precision: u32, scale: u32) -> &mut Self

Set column type as decimal with custom precision and scale

source

pub fn decimal(&mut self) -> &mut Self

Set column type as decimal

source

pub fn date_time(&mut self) -> &mut Self

Set column type as date_time

source

pub fn interval( &mut self, fields: Option<PgInterval>, precision: Option<u32> ) -> &mut Self

Set column type as interval type with optional fields and precision. Postgres only

use sea_query::{tests_cfg::*, *};
assert_eq!(
    Table::create()
        .table(Glyph::Table)
        .col(
            ColumnDef::new(Alias::new("I1"))
                .interval(None, None)
                .not_null()
        )
        .col(
            ColumnDef::new(Alias::new("I2"))
                .interval(Some(PgInterval::YearToMonth), None)
                .not_null()
        )
        .col(
            ColumnDef::new(Alias::new("I3"))
                .interval(None, Some(42))
                .not_null()
        )
        .col(
            ColumnDef::new(Alias::new("I4"))
                .interval(Some(PgInterval::Hour), Some(43))
                .not_null()
        )
        .to_string(PostgresQueryBuilder),
    [
        r#"CREATE TABLE "glyph" ("#,
        r#""I1" interval NOT NULL,"#,
        r#""I2" interval YEAR TO MONTH NOT NULL,"#,
        r#""I3" interval(42) NOT NULL,"#,
        r#""I4" interval HOUR(43) NOT NULL"#,
        r#")"#,
    ]
    .join(" ")
);
source

pub fn timestamp(&mut self) -> &mut Self

Set column type as timestamp

source

pub fn timestamp_with_time_zone(&mut self) -> &mut Self

Set column type as timestamp with time zone. Postgres only

source

pub fn time(&mut self) -> &mut Self

Set column type as time

source

pub fn date(&mut self) -> &mut Self

Set column type as date

source

pub fn year(&mut self, length: Option<MySqlYear>) -> &mut Self

Set column type as year Only MySQL supports year

source

pub fn binary_len(&mut self, length: u32) -> &mut Self

Set column type as binary with custom length

source

pub fn binary(&mut self) -> &mut Self

Set column type as binary

source

pub fn blob(&mut self, size: BlobSize) -> &mut Self

Set column type as blob, but when given BlobSize::Blob(size) argument, this column map to binary(size) type instead.

source

pub fn var_binary(&mut self, length: u32) -> &mut Self

Set column type as binary with variable length

source

pub fn bit(&mut self, length: Option<u32>) -> &mut Self

Set column type as bit with variable length

source

pub fn varbit(&mut self, length: u32) -> &mut Self

Set column type as varbit with variable length

source

pub fn boolean(&mut self) -> &mut Self

Set column type as boolean

source

pub fn money_len(&mut self, precision: u32, scale: u32) -> &mut Self

Set column type as money with custom precision and scale

source

pub fn money(&mut self) -> &mut Self

Set column type as money

source

pub fn json(&mut self) -> &mut Self

Set column type as json.

source

pub fn json_binary(&mut self) -> &mut Self

Set column type as json binary.

source

pub fn uuid(&mut self) -> &mut Self

Set column type as uuid

source

pub fn custom<T>(&mut self, name: T) -> &mut Selfwhere T: IntoIden,

Use a custom type on this column.

source

pub fn enumeration<N, S, V>(&mut self, name: N, variants: V) -> &mut Selfwhere N: IntoIden, S: IntoIden, V: IntoIterator<Item = S>,

Set column type as enum.

source

pub fn array(&mut self, elem_type: ColumnType) -> &mut Self

Set column type as an array with a specified element type. This is only supported on Postgres.

source

pub fn cidr(&mut self) -> &mut Self

Set columnt type as cidr. This is only supported on Postgres.

source

pub fn inet(&mut self) -> &mut Self

Set columnt type as inet. This is only supported on Postgres.

source

pub fn mac_address(&mut self) -> &mut Self

Set columnt type as macaddr. This is only supported on Postgres.

source

pub fn extra(&mut self, string: String) -> &mut Self

Some extra options in custom string

source

pub fn get_column_name(&self) -> String

source

pub fn get_column_type(&self) -> Option<&ColumnType>

source

pub fn get_column_spec(&self) -> &Vec<ColumnSpec>

source

pub fn take(&mut self) -> Self

Trait Implementations§

source§

impl Clone for ColumnDef

source§

fn clone(&self) -> ColumnDef

Returns a copy 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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.