Struct migration::ColumnDef

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

Specification of a table column

Implementations§

§

impl ColumnDef

pub fn new<T>(name: T) -> ColumnDefwhere T: 'static + Iden,

Construct a table column

pub fn new_with_type<T>(name: T, types: ColumnType) -> ColumnDefwhere T: 'static + Iden,

Construct a table column with column type

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

Set column not null

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

Set column null

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

Set default value of a column

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

Set column auto increment

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

Set column unique constraint

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

Set column as primary key

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

Set column type as char with custom length

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

Set column type as char

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

Set column type as string with custom length

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

Set column type as string

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

Set column type as text

pub fn tiny_integer_len(&mut self, length: u32) -> &mut ColumnDef

Set column type as tiny_integer with custom length

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

Set column type as tiny_integer

pub fn small_integer_len(&mut self, length: u32) -> &mut ColumnDef

Set column type as small_integer with custom length

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

Set column type as small_integer

pub fn integer_len(&mut self, length: u32) -> &mut ColumnDef

Set column type as integer with custom length

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

Set column type as integer

pub fn big_integer_len(&mut self, length: u32) -> &mut ColumnDef

Set column type as big_integer with custom length

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

Set column type as big_integer

pub fn tiny_unsigned_len(&mut self, length: u32) -> &mut ColumnDef

Set column type as tiny_unsigned with custom length

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

Set column type as tiny_unsigned

pub fn small_unsigned_len(&mut self, length: u32) -> &mut ColumnDef

Set column type as small_unsigned with custom length

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

Set column type as small_unsigned

pub fn unsigned_len(&mut self, length: u32) -> &mut ColumnDef

Set column type as unsigned with custom length

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

Set column type as unsigned

pub fn big_unsigned_len(&mut self, length: u32) -> &mut ColumnDef

Set column type as big_unsigned with custom length

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

Set column type as big_unsigned

pub fn float_len(&mut self, precision: u32) -> &mut ColumnDef

Set column type as float with custom precision

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

Set column type as float

pub fn double_len(&mut self, precision: u32) -> &mut ColumnDef

Set column type as double with custom precision

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

Set column type as double

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

Set column type as decimal with custom precision and scale

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

Set column type as decimal

pub fn date_time_len(&mut self, precision: u32) -> &mut ColumnDef

Set column type as date_time with custom precision

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

Set column type as date_time

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

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),
    vec![
        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(" ")
);

pub fn timestamp_len(&mut self, precision: u32) -> &mut ColumnDef

Set column type as timestamp with custom precision

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

Set column type as timestamp

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

Set column type as timestamp with time zone. Postgres only

pub fn timestamp_with_time_zone_len(&mut self, precision: u32) -> &mut ColumnDef

Set column type as timestamp with time zone plus custom precision

pub fn time_len(&mut self, precision: u32) -> &mut ColumnDef

Set column type as time with custom precision

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

Set column type as time

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

Set column type as date

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

Set column type as binary with custom length

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

Set column type as binary

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

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

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

Set column type as binary with variable length

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

Set column type as boolean

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

Set column type as money with custom precision and scale

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

Set column type as money

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

Set column type as json. On MySQL, this is equivalent to json_binary. On MariaDB, this is equivalent to text. On PgSQL, this is equivalent to json.

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

Set column type as json binary. On MySQL, this is equivalent to json. On MariaDB, this is equivalent to text. On PgSQL, this is equivalent to jsonb.

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

Set column type as uuid

pub fn custom<T>(&mut self, n: T) -> &mut ColumnDefwhere T: 'static + Iden,

Use a custom type on this column.

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

Set column type as enum.

pub fn array(&mut self, elem_type: String) -> &mut ColumnDef

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

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

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

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

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

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

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

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

Some extra options in custom string

pub fn get_column_name(&self) -> String

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

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

pub fn take(&mut self) -> ColumnDef

Trait Implementations§

§

impl Clone for ColumnDef

§

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
§

impl Debug for ColumnDef

§

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

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,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · 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> Same<T> for T

§

type Output = T

Should always be Self
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.
const: unstable · 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.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more