pub struct ColumnDef { /* private fields */ }Expand description
Specification of a table column
Implementations
sourceimpl ColumnDef
impl ColumnDef
sourcepub fn new_with_type<T: 'static>(name: T, types: ColumnType) -> Self where
T: Iden,
pub fn new_with_type<T: 'static>(name: T, types: ColumnType) -> Self where
T: Iden,
Construct a table column with column type
sourcepub fn default<T>(&mut self, value: T) -> &mut Self where
T: Into<Value>,
pub fn default<T>(&mut self, value: T) -> &mut Self where
T: Into<Value>,
Set default value of a column
sourcepub fn auto_increment(&mut self) -> &mut Self
pub fn auto_increment(&mut self) -> &mut Self
Set column auto increment
sourcepub fn unique_key(&mut self) -> &mut Self
pub fn unique_key(&mut self) -> &mut Self
Set column unique constraint
sourcepub fn primary_key(&mut self) -> &mut Self
pub fn primary_key(&mut self) -> &mut Self
Set column as primary key
sourcepub fn char_len(&mut self, length: u32) -> &mut Self
pub fn char_len(&mut self, length: u32) -> &mut Self
Set column type as char with custom length
sourcepub fn string_len(&mut self, length: u32) -> &mut Self
pub fn string_len(&mut self, length: u32) -> &mut Self
Set column type as string with custom length
sourcepub fn tiny_integer_len(&mut self, length: u32) -> &mut Self
pub fn tiny_integer_len(&mut self, length: u32) -> &mut Self
Set column type as tiny_integer with custom length
sourcepub fn tiny_integer(&mut self) -> &mut Self
pub fn tiny_integer(&mut self) -> &mut Self
Set column type as tiny_integer
sourcepub fn small_integer_len(&mut self, length: u32) -> &mut Self
pub fn small_integer_len(&mut self, length: u32) -> &mut Self
Set column type as small_integer with custom length
sourcepub fn small_integer(&mut self) -> &mut Self
pub fn small_integer(&mut self) -> &mut Self
Set column type as small_integer
sourcepub fn integer_len(&mut self, length: u32) -> &mut Self
pub fn integer_len(&mut self, length: u32) -> &mut Self
Set column type as integer with custom length
sourcepub fn big_integer_len(&mut self, length: u32) -> &mut Self
pub fn big_integer_len(&mut self, length: u32) -> &mut Self
Set column type as big_integer with custom length
sourcepub fn big_integer(&mut self) -> &mut Self
pub fn big_integer(&mut self) -> &mut Self
Set column type as big_integer
sourcepub fn float_len(&mut self, precision: u32) -> &mut Self
pub fn float_len(&mut self, precision: u32) -> &mut Self
Set column type as float with custom precision
sourcepub fn double_len(&mut self, precision: u32) -> &mut Self
pub fn double_len(&mut self, precision: u32) -> &mut Self
Set column type as double with custom precision
sourcepub fn decimal_len(&mut self, precision: u32, scale: u32) -> &mut Self
pub fn decimal_len(&mut self, precision: u32, scale: u32) -> &mut Self
Set column type as decimal with custom precision and scale
sourcepub fn date_time_len(&mut self, precision: u32) -> &mut Self
pub fn date_time_len(&mut self, precision: u32) -> &mut Self
Set column type as date_time with custom precision
sourcepub fn interval(
&mut self,
fields: Option<PgInterval>,
precision: Option<u32>
) -> &mut Self
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),
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(" ")
);sourcepub fn timestamp_len(&mut self, precision: u32) -> &mut Self
pub fn timestamp_len(&mut self, precision: u32) -> &mut Self
Set column type as timestamp with custom precision
sourcepub fn timestamp_with_time_zone(&mut self) -> &mut Self
pub fn timestamp_with_time_zone(&mut self) -> &mut Self
Set column type as timestamp with time zone. Postgres only
sourcepub fn timestamp_with_time_zone_len(&mut self, precision: u32) -> &mut Self
pub fn timestamp_with_time_zone_len(&mut self, precision: u32) -> &mut Self
Set column type as timestamp with time zone plus custom precision
sourcepub fn time_len(&mut self, precision: u32) -> &mut Self
pub fn time_len(&mut self, precision: u32) -> &mut Self
Set column type as time with custom precision
sourcepub fn binary_len(&mut self, length: u32) -> &mut Self
pub fn binary_len(&mut self, length: u32) -> &mut Self
Set column type as binary with custom length
sourcepub fn money_len(&mut self, precision: u32, scale: u32) -> &mut Self
pub fn money_len(&mut self, precision: u32, scale: u32) -> &mut Self
Set column type as money with custom precision and scale
sourcepub fn json(&mut self) -> &mut Self
pub fn json(&mut self) -> &mut Self
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.
sourcepub fn json_binary(&mut self) -> &mut Self
pub fn json_binary(&mut self) -> &mut Self
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.
sourcepub fn custom<T: 'static>(&mut self, n: T) -> &mut Self where
T: Iden,
pub fn custom<T: 'static>(&mut self, n: T) -> &mut Self where
T: Iden,
Use a custom type on this column.
sourcepub fn enumeration<N, S, V>(&mut self, name: N, variants: V) -> &mut Self where
N: ToString,
S: ToString,
V: IntoIterator<Item = S>,
pub fn enumeration<N, S, V>(&mut self, name: N, variants: V) -> &mut Self where
N: ToString,
S: ToString,
V: IntoIterator<Item = S>,
Set column type as enum.
sourcepub fn array(&mut self, elem_type: String) -> &mut Self
pub fn array(&mut self, elem_type: String) -> &mut Self
Set column type as an array with a specified element type. This is only supported on Postgres.
pub fn get_column_name(&self) -> String
pub fn get_column_type(&self) -> Option<&ColumnType>
pub fn get_column_spec(&self) -> &Vec<ColumnSpec>
pub fn take(&mut self) -> Self
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for ColumnDef
impl Send for ColumnDef
impl Sync for ColumnDef
impl Unpin for ColumnDef
impl !UnwindSafe for ColumnDef
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more