pub struct ColumnDef {
pub name: ColumnName,
pub type: ColumnType,
pub nullable: bool,
pub default: Option<StringOrBool>,
pub comment: Option<String>,
pub primary_key: Option<PrimaryKeySyntax>,
pub unique: Option<StrOrBoolOrArray>,
pub index: Option<StrOrBoolOrArray>,
pub foreign_key: Option<ForeignKeySyntax>,
}Expand description
Definition of a single table column, including its type, nullability, and inline constraints.
Inline constraints (primary_key, unique, index, foreign_key) are the preferred way to
declare constraints in model JSON files. Call TableDef::normalize to convert them into
table-level TableConstraint entries before diffing or SQL generation.
Use ColumnDef::new to construct a column programmatically, then chain the setter methods
(.primary_key(), .unique(), .index(), .foreign_key(), .default(), .comment()) to
attach optional fields.
Fields§
§name: ColumnName§type: ColumnType§nullable: bool§default: Option<StringOrBool>§comment: Option<String>§primary_key: Option<PrimaryKeySyntax>§unique: Option<StrOrBoolOrArray>§index: Option<StrOrBoolOrArray>§foreign_key: Option<ForeignKeySyntax>Implementations§
Source§impl ColumnDef
impl ColumnDef
Sourcepub fn new(
name: impl Into<ColumnName>,
type: ColumnType,
nullable: bool,
) -> Self
pub fn new( name: impl Into<ColumnName>, type: ColumnType, nullable: bool, ) -> Self
Construct a new column with required fields only.
Use the .primary_key(), .unique(), .index(), .foreign_key(),
.default(), .comment() setters to add optional fields.
§Examples
use vespertide_core::{ColumnDef, ColumnType, SimpleColumnType};
let id = ColumnDef::new("id", ColumnType::Simple(SimpleColumnType::Integer), false);Sourcepub fn primary_key(self, pk: PrimaryKeySyntax) -> Self
pub fn primary_key(self, pk: PrimaryKeySyntax) -> Self
Mark this column as part of the primary key.
Sourcepub fn unique(self, unique: StrOrBoolOrArray) -> Self
pub fn unique(self, unique: StrOrBoolOrArray) -> Self
Add a unique constraint to this column.
Sourcepub fn index(self, index: StrOrBoolOrArray) -> Self
pub fn index(self, index: StrOrBoolOrArray) -> Self
Add an index on this column.
Sourcepub fn foreign_key(self, fk: ForeignKeySyntax) -> Self
pub fn foreign_key(self, fk: ForeignKeySyntax) -> Self
Add a foreign key reference from this column.
Sourcepub fn default(self, default: StringOrBool) -> Self
pub fn default(self, default: StringOrBool) -> Self
Set the column default value.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for ColumnDef
impl<'de> Deserialize<'de> for ColumnDef
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for ColumnDef
Source§impl JsonSchema for ColumnDef
impl JsonSchema for ColumnDef
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreimpl 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 UnsafeUnpin 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more