pub struct ColumnMetadata {
pub name: String,
pub data_type: ResolvedType,
pub not_null: bool,
pub primary_key: bool,
pub unique: bool,
pub default: Option<Expr>,
}Expand description
Metadata for a column in a table.
Contains the column name, data type, and constraint information.
§Examples
use alopex_sql::catalog::ColumnMetadata;
use alopex_sql::planner::types::ResolvedType;
let column = ColumnMetadata::new("id", ResolvedType::Integer)
.with_not_null(true)
.with_primary_key(true);
assert_eq!(column.name, "id");
assert_eq!(column.data_type, ResolvedType::Integer);
assert!(column.not_null);
assert!(column.primary_key);Fields§
§name: StringColumn name.
data_type: ResolvedTypeColumn data type (normalized).
not_null: boolNOT NULL constraint.
primary_key: boolPRIMARY KEY constraint.
unique: boolUNIQUE constraint.
default: Option<Expr>DEFAULT value expression.
Implementations§
Source§impl ColumnMetadata
impl ColumnMetadata
Sourcepub fn new(name: impl Into<String>, data_type: ResolvedType) -> Self
pub fn new(name: impl Into<String>, data_type: ResolvedType) -> Self
Create a new column metadata with the given name and data type.
All constraints default to false, and default is None.
Sourcepub fn with_not_null(self, not_null: bool) -> Self
pub fn with_not_null(self, not_null: bool) -> Self
Set the NOT NULL constraint.
Sourcepub fn with_primary_key(self, primary_key: bool) -> Self
pub fn with_primary_key(self, primary_key: bool) -> Self
Set the PRIMARY KEY constraint.
Sourcepub fn with_unique(self, unique: bool) -> Self
pub fn with_unique(self, unique: bool) -> Self
Set the UNIQUE constraint.
Sourcepub fn with_default(self, default: Expr) -> Self
pub fn with_default(self, default: Expr) -> Self
Set the DEFAULT value.
Trait Implementations§
Source§impl Clone for ColumnMetadata
impl Clone for ColumnMetadata
Source§fn clone(&self) -> ColumnMetadata
fn clone(&self) -> ColumnMetadata
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ColumnMetadata
impl Debug for ColumnMetadata
Source§impl From<&ColumnMetadata> for PersistedColumnMeta
impl From<&ColumnMetadata> for PersistedColumnMeta
Source§fn from(value: &ColumnMetadata) -> Self
fn from(value: &ColumnMetadata) -> Self
Converts to this type from the input type.
Source§impl From<PersistedColumnMeta> for ColumnMetadata
impl From<PersistedColumnMeta> for ColumnMetadata
Source§fn from(value: PersistedColumnMeta) -> Self
fn from(value: PersistedColumnMeta) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for ColumnMetadata
impl RefUnwindSafe for ColumnMetadata
impl Send for ColumnMetadata
impl Sync for ColumnMetadata
impl Unpin for ColumnMetadata
impl UnwindSafe for ColumnMetadata
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