pub struct ColumnInfo {
pub name: &'static str,
pub sql_type: &'static str,
pub is_primary_key: bool,
pub is_nullable: bool,
pub create_time: bool,
pub update_time: bool,
pub unique: bool,
pub index: bool,
pub foreign_table: Option<&'static str>,
pub foreign_key: Option<&'static str>,
}Expand description
Metadata information about a database column.
This structure contains all the information needed to generate SQL table
definitions and handle type conversions between Rust and SQL. It is populated
automatically by the #[derive(Model)] macro based on struct field types
and #[orm(...)] attributes.
§Fields
name- Column name (field name from struct)sql_type- SQL type string (e.g., “INTEGER”, “TEXT”, “UUID”, “TIMESTAMPTZ”)is_primary_key- Whether this is the primary key columnis_nullable- Whether NULL values are allowed (from Option) create_time- Auto-populate with CURRENT_TIMESTAMP on insertupdate_time- Auto-update timestamp on modification (future feature)unique- Whether UNIQUE constraint should be addedindex- Whether to create an index on this columnforeign_table- Name of referenced table (for foreign keys)foreign_key- Name of referenced column (for foreign keys)
§Example
// For this field:
#[orm(size = 50, unique, index)]
username: String,
// The generated ColumnInfo would be:
ColumnInfo {
name: "username",
sql_type: "VARCHAR(50)",
is_primary_key: false,
is_nullable: false,
create_time: false,
update_time: false,
unique: true,
index: true,
foreign_table: None,
foreign_key: None,
}§SQL Type Mapping
The sql_type field contains the SQL type based on the Rust type:
i32→"INTEGER"i64→"BIGINT"String→"TEXT"or"VARCHAR(N)"with size attributebool→"BOOLEAN"f64→"DOUBLE PRECISION"Uuid→"UUID"DateTime<Utc>→"TIMESTAMPTZ"NaiveDateTime→"TIMESTAMP"NaiveDate→"DATE"NaiveTime→"TIME"Option<T>→ Same as T, butis_nullable = true
Fields§
§name: &'static strThe column name in the database.
This is derived from the struct field name and is typically converted
to snake_case when generating SQL. The r# prefix is stripped if present
(for Rust keywords used as field names).
§Example
// Field: user_id: i32
name: "user_id"
// Field: r#type: String (type is a Rust keyword)
name: "r#type" // The r# will be stripped in SQL generationsql_type: &'static strThe SQL type of the column (e.g., “TEXT”, “INTEGER”, “TIMESTAMPTZ”).
This string is used directly in CREATE TABLE statements. It must be a valid SQL type for the target database.
§Example
// i32 field
sql_type: "INTEGER"
// UUID field
sql_type: "UUID"
// String with size = 100
sql_type: "VARCHAR(100)"is_primary_key: boolWhether this column is a Primary Key.
Set to true via #[orm(primary_key)] attribute. A table should have
exactly one primary key column.
§SQL Impact
- Adds
PRIMARY KEYconstraint - Implicitly makes column
NOT NULL - Creates a unique index automatically
§Example
#[orm(primary_key)]
id: Uuid,
// is_primary_key: trueis_nullable: boolWhether this column allows NULL values.
Automatically set to true when the field type is Option<T>,
otherwise false for non-optional types.
§SQL Impact
false: AddsNOT NULLconstrainttrue: Allows NULL values
§Example
// Required field
username: String,
// is_nullable: false → NOT NULL
// Optional field
middle_name: Option<String>,
// is_nullable: true → allows NULLcreate_time: boolWhether this column should be automatically populated with the creation timestamp.
Set via #[orm(create_time)] attribute. When true, the column gets
a DEFAULT CURRENT_TIMESTAMP constraint.
§SQL Impact
- Adds
DEFAULT CURRENT_TIMESTAMP - Column is auto-populated on INSERT
§Example
#[orm(create_time)]
created_at: DateTime<Utc>,
// create_time: true
// SQL: created_at TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMPupdate_time: boolWhether this column should be automatically updated on modification.
Set via #[orm(update_time)] attribute. This is a future feature
not yet fully implemented.
§Future Implementation
When implemented, this will:
- Add database trigger or application-level update
- Auto-update timestamp on every UPDATE
§Example
#[orm(update_time)]
updated_at: DateTime<Utc>,
// update_time: true (future feature)unique: boolWhether this column has a UNIQUE constraint.
Set via #[orm(unique)] attribute. Ensures no two rows can have
the same value in this column (NULL values may be exempt depending
on database).
§SQL Impact
- Adds
UNIQUEconstraint - Creates a unique index automatically
§Example
#[orm(unique)]
username: String,
// unique: true
// SQL: username VARCHAR(255) UNIQUEindex: boolWhether an index should be created for this column.
Set via #[orm(index)] attribute. Creates a database index to speed
up queries that filter or sort by this column.
§SQL Impact
- Creates separate
CREATE INDEXstatement - Index name:
idx_{table}_{column}
§Example
#[orm(index)]
email: String,
// index: true
// SQL: CREATE INDEX idx_user_email ON user (email)foreign_table: Option<&'static str>The name of the foreign table, if this is a Foreign Key.
Set via #[orm(foreign_key = "Table::Column")] attribute. Contains
the name of the referenced table.
§Example
#[orm(foreign_key = "User::id")]
user_id: Uuid,
// foreign_table: Some("User")foreign_key: Option<&'static str>The name of the foreign column, if this is a Foreign Key.
Set via #[orm(foreign_key = "Table::Column")] attribute. Contains
the name of the referenced column in the foreign table.
§Example
#[orm(foreign_key = "User::id")]
user_id: Uuid,
// foreign_key: Some("id")
// SQL: FOREIGN KEY (user_id) REFERENCES user (id)Trait Implementations§
Source§impl Clone for ColumnInfo
impl Clone for ColumnInfo
Source§fn clone(&self) -> ColumnInfo
fn clone(&self) -> ColumnInfo
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ColumnInfo
impl RefUnwindSafe for ColumnInfo
impl Send for ColumnInfo
impl Sync for ColumnInfo
impl Unpin for ColumnInfo
impl UnwindSafe for ColumnInfo
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,
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