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
Const-friendly column definition for compile-time schema definitions.
§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 (e.g., “INTEGER”, “TEXT”, “REAL”, “BLOB”)
not_null: boolIs this column NOT NULL?
primary_key: Option<PrimaryKeyKind>Primary-key variant (None if not a primary key)
unique: boolIs this column UNIQUE?
default: Option<&'static str>Default value as string (if any)
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
Create a new column definition
Sourcepub const fn autoincrement(self) -> Self
pub const fn autoincrement(self) -> Self
Set AUTOINCREMENT (implies PRIMARY KEY and NOT NULL)
Sourcepub const fn primary_key(self) -> Self
pub const fn primary_key(self) -> Self
Set PRIMARY KEY (also sets NOT NULL). Preserves AUTOINCREMENT if already set.
Sourcepub const fn default_value(self, value: &'static str) -> Self
pub const fn default_value(self, value: &'static str) -> Self
Set default value
Sourcepub const fn generated_stored(self, expression: &'static str) -> Self
pub const fn generated_stored(self, expression: &'static str) -> Self
Set as generated stored column
Sourcepub const fn generated_virtual(self, expression: &'static str) -> Self
pub const fn generated_virtual(self, expression: &'static str) -> Self
Set as generated virtual column
Sourcepub const fn collate(self, name: &'static str) -> Self
pub const fn collate(self, name: &'static str) -> Self
Set the collation sequence for this column.
name should be one of SQLite’s built-in collations (BINARY,
NOCASE, RTRIM) or a custom collation that’s registered on the
connection at runtime via sqlite3_create_collation.
Sourcepub const fn into_column(self) -> Column
pub const fn into_column(self) -> Column
Convert to runtime Column type