pub struct ColumnDef {
pub table: &'static str,
pub name: &'static str,
pub sql_type: &'static str,
pub not_null: bool,
pub autoincrement: bool,
pub primary_key: bool,
pub unique: bool,
pub default: Option<&'static str>,
pub generated: Option<GeneratedDef>,
}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?
autoincrement: boolIs this column AUTOINCREMENT?
primary_key: boolIs this column a PRIMARY KEY?
unique: boolIs this column UNIQUE?
default: Option<&'static str>Default value as string (if any)
generated: Option<GeneratedDef>Generated column configuration
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
Sourcepub const fn primary_key(self) -> Self
pub const fn primary_key(self) -> Self
Set PRIMARY KEY (also sets NOT NULL)
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 into_column(self) -> Column
pub const fn into_column(self) -> Column
Convert to runtime Column type
Trait Implementations§
impl Copy for ColumnDef
impl Eq for ColumnDef
impl StructuralPartialEq for ColumnDef
Auto Trait Implementations§
impl Freeze for ColumnDef
impl RefUnwindSafe for ColumnDef
impl Send for ColumnDef
impl Sync for ColumnDef
impl Unpin for ColumnDef
impl UnwindSafe for ColumnDef
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more