pub trait Model:
Send
+ Sync
+ Debug
+ Serialize
+ for<'de> Deserialize<'de> {
type PrimaryKey: Clone + Send + Sync + Debug + Display + Default;
Show 16 methods
// Required methods
fn table_name() -> &'static str;
fn primary_key(&self) -> Option<Self::PrimaryKey>;
fn set_primary_key(&mut self, key: Self::PrimaryKey);
fn from_row(row: &PgRow) -> ModelResult<Self>
where Self: Sized;
fn to_fields(&self) -> HashMap<String, Value>;
// Provided methods
fn primary_key_name() -> &'static str { ... }
fn uses_timestamps() -> bool { ... }
fn uses_soft_deletes() -> bool { ... }
fn created_at(&self) -> Option<DateTime<Utc>> { ... }
fn set_created_at(&mut self, _timestamp: DateTime<Utc>) { ... }
fn updated_at(&self) -> Option<DateTime<Utc>> { ... }
fn set_updated_at(&mut self, _timestamp: DateTime<Utc>) { ... }
fn deleted_at(&self) -> Option<DateTime<Utc>> { ... }
fn set_deleted_at(&mut self, _timestamp: Option<DateTime<Utc>>) { ... }
fn is_soft_deleted(&self) -> bool { ... }
fn from_database_row(_row: &dyn DatabaseRow) -> ModelResult<Self>
where Self: Sized { ... }
}Expand description
Core trait for database models with standard ORM operations
Required Associated Types§
Required Methods§
Sourcefn table_name() -> &'static str
fn table_name() -> &'static str
Table name for this model
Sourcefn primary_key(&self) -> Option<Self::PrimaryKey>
fn primary_key(&self) -> Option<Self::PrimaryKey>
Get the primary key value for this model instance
Sourcefn set_primary_key(&mut self, key: Self::PrimaryKey)
fn set_primary_key(&mut self, key: Self::PrimaryKey)
Set the primary key value for this model instance
Sourcefn from_row(row: &PgRow) -> ModelResult<Self>where
Self: Sized,
fn from_row(row: &PgRow) -> ModelResult<Self>where
Self: Sized,
Create a model instance from a database row This will be automatically implemented by the derive macro
Provided Methods§
Sourcefn primary_key_name() -> &'static str
fn primary_key_name() -> &'static str
Primary key field name(s)
Sourcefn uses_timestamps() -> bool
fn uses_timestamps() -> bool
Check if this model uses timestamps (created_at, updated_at)
Sourcefn uses_soft_deletes() -> bool
fn uses_soft_deletes() -> bool
Check if this model supports soft deletes
Sourcefn created_at(&self) -> Option<DateTime<Utc>>
fn created_at(&self) -> Option<DateTime<Utc>>
Get created_at timestamp if available
Sourcefn set_created_at(&mut self, _timestamp: DateTime<Utc>)
fn set_created_at(&mut self, _timestamp: DateTime<Utc>)
Set created_at timestamp
Sourcefn updated_at(&self) -> Option<DateTime<Utc>>
fn updated_at(&self) -> Option<DateTime<Utc>>
Get updated_at timestamp if available
Sourcefn set_updated_at(&mut self, _timestamp: DateTime<Utc>)
fn set_updated_at(&mut self, _timestamp: DateTime<Utc>)
Set updated_at timestamp
Sourcefn deleted_at(&self) -> Option<DateTime<Utc>>
fn deleted_at(&self) -> Option<DateTime<Utc>>
Get deleted_at timestamp if available (for soft deletes)
Sourcefn set_deleted_at(&mut self, _timestamp: Option<DateTime<Utc>>)
fn set_deleted_at(&mut self, _timestamp: Option<DateTime<Utc>>)
Set deleted_at timestamp (for soft deletes)
Sourcefn is_soft_deleted(&self) -> bool
fn is_soft_deleted(&self) -> bool
Check if this model instance is soft deleted
Sourcefn from_database_row(_row: &dyn DatabaseRow) -> ModelResult<Self>where
Self: Sized,
fn from_database_row(_row: &dyn DatabaseRow) -> ModelResult<Self>where
Self: Sized,
Create a model instance from a database row (abstracted version) This will replace from_row in the future
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.