pub struct Column {
pub table: Cow<'static, str>,
pub name: Cow<'static, str>,
pub sql_type: Cow<'static, str>,
pub not_null: bool,
pub autoincrement: Option<bool>,
pub primary_key: Option<bool>,
pub unique: Option<bool>,
pub default: Option<Cow<'static, str>>,
pub generated: Option<Generated>,
pub collate: Option<Cow<'static, str>>,
pub ordinal_position: Option<i32>,
}Expand description
A table column, as stored in migration snapshots.
The boolean constraints are Option<bool> to match the snapshot format;
None and Some(false) both mean unset.
Fields§
§table: Cow<'static, str>Parent table name
name: Cow<'static, str>Column name
sql_type: Cow<'static, str>SQL type, such as "INTEGER" (serialized as type)
not_null: boolIs this column NOT NULL?
autoincrement: Option<bool>Is this column AUTOINCREMENT?
primary_key: Option<bool>Is this column a PRIMARY KEY?
unique: Option<bool>Is this column UNIQUE?
default: Option<Cow<'static, str>>DEFAULT value as SQL
generated: Option<Generated>Generated column configuration
collate: Option<Cow<'static, str>>Collation sequence (BINARY, NOCASE, RTRIM, or custom). None means
the default BINARY collation and no COLLATE clause is emitted.
ordinal_position: Option<i32>Ordinal position within the table (cid, 0-based).
This is primarily populated by introspection and used for stable codegen ordering.
Implementations§
Source§impl Column
impl Column
Sourcepub fn new(
table: impl Into<Cow<'static, str>>,
name: impl Into<Cow<'static, str>>,
sql_type: impl Into<Cow<'static, str>>,
) -> Self
pub fn new( table: impl Into<Cow<'static, str>>, name: impl Into<Cow<'static, str>>, sql_type: impl Into<Cow<'static, str>>, ) -> Self
Creates a nullable column with no constraints.
Sourcepub const fn autoincrement(self) -> Self
pub const fn autoincrement(self) -> Self
Marks the column AUTOINCREMENT. Unlike ColumnDef::autoincrement,
this does not set primary_key or not_null.
Sourcepub fn default_value(self, value: impl Into<Cow<'static, str>>) -> Self
pub fn default_value(self, value: impl Into<Cow<'static, str>>) -> Self
Sets the DEFAULT value, written as SQL.
Sourcepub const fn is_primary_key(&self) -> bool
pub const fn is_primary_key(&self) -> bool
Returns true if primary_key is Some(true).
Sourcepub const fn is_autoincrement(&self) -> bool
pub const fn is_autoincrement(&self) -> bool
Returns true if autoincrement is Some(true).
Source§impl Column
impl Column
Sourcepub fn to_column_sql(&self, inline_pk: bool, inline_unique: bool) -> String
pub fn to_column_sql(&self, inline_pk: bool, inline_unique: bool) -> String
Renders the column definition as used inside CREATE TABLE, such as
`name` TEXT NOT NULL.
inline_pk adds PRIMARY KEY (and AUTOINCREMENT, which is
otherwise dropped); inline_unique adds UNIQUE. NOT NULL is left
out only on an inline INTEGER PRIMARY KEY, which aliases the rowid
and is never NULL.
Sourcepub fn add_column_sql(&self) -> String
pub fn add_column_sql(&self) -> String
Renders ALTER TABLE ... ADD COLUMN ...;.
Sourcepub fn drop_column_sql(&self) -> String
pub fn drop_column_sql(&self) -> String
Renders ALTER TABLE ... DROP COLUMN ...;.