pub struct ColumnDef {
pub table: &'static str,
pub name: &'static str,
pub sql_type: &'static str,
pub not_null: bool,
pub primary_key: Option<PrimaryKeyKind>,
pub unique: bool,
pub default: Option<&'static str>,
pub generated: Option<GeneratedDef>,
pub collate: Option<&'static str>,
}Expand description
A column definition that can be built in a const.
Builder methods set one property each; into_column
converts to the runtime Column.
§Examples
use drizzle_types::sqlite::ddl::ColumnDef;
const ID: ColumnDef = ColumnDef::new("users", "id", "INTEGER")
.primary_key()
.autoincrement();
const COLUMNS: &[ColumnDef] = &[
ColumnDef::new("users", "id", "INTEGER").primary_key().autoincrement(),
ColumnDef::new("users", "name", "TEXT").not_null(),
ColumnDef::new("users", "email", "TEXT"),
];Fields§
§table: &'static strParent table name
name: &'static strColumn name
sql_type: &'static strSQL type, such as "INTEGER" or "TEXT"
not_null: boolNOT NULL
primary_key: Option<PrimaryKeyKind>Primary key form; None if not a primary key
unique: boolUNIQUE
default: Option<&'static str>DEFAULT value as SQL, such as "0" or "'active'"
generated: Option<GeneratedDef>Generated column configuration
collate: Option<&'static str>Collation name (BINARY, NOCASE, RTRIM, or a custom registered collation).
None means the default collation (BINARY) and no COLLATE clause is emitted.
Implementations§
Source§impl ColumnDef
impl ColumnDef
Sourcepub const fn new(
table: &'static str,
name: &'static str,
sql_type: &'static str,
) -> Self
pub const fn new( table: &'static str, name: &'static str, sql_type: &'static str, ) -> Self
Creates a nullable column with no constraints.
Sourcepub const fn autoincrement(self) -> Self
pub const fn autoincrement(self) -> Self
Makes the column PRIMARY KEY AUTOINCREMENT (and NOT NULL).
Sourcepub const fn primary_key(self) -> Self
pub const fn primary_key(self) -> Self
Makes the column PRIMARY KEY (and NOT NULL), keeping
AUTOINCREMENT if already set.
Sourcepub const fn primary(self) -> Self
pub const fn primary(self) -> Self
Same as primary_key.
Sourcepub const fn default_value(self, value: &'static str) -> Self
pub const fn default_value(self, value: &'static str) -> Self
Sets the DEFAULT value, written as SQL.
Sourcepub const fn generated_stored(self, expression: &'static str) -> Self
pub const fn generated_stored(self, expression: &'static str) -> Self
Makes the column GENERATED ALWAYS AS (expression) STORED.
Sourcepub const fn generated_virtual(self, expression: &'static str) -> Self
pub const fn generated_virtual(self, expression: &'static str) -> Self
Makes the column GENERATED ALWAYS AS (expression) VIRTUAL.
Sourcepub const fn collate(self, name: &'static str) -> Self
pub const fn collate(self, name: &'static str) -> Self
Sets the column’s COLLATE sequence.
name should be a built-in collation (BINARY, NOCASE, RTRIM) or
one registered on the connection with sqlite3_create_collation.
Sourcepub const fn into_column(self) -> Column
pub const fn into_column(self) -> Column
Converts to the runtime Column.