pub trait Model:
Sized
+ Send
+ Sync
+ Unpin
+ for<'r> FromRow<'r, AnyRow> {
// Required methods
fn table_name() -> &'static str;
fn fields() -> &'static [&'static str];
fn create<'life0, 'life1, 'async_trait>(
&'life0 mut self,
db: &'life1 (impl 'async_trait + Database),
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn update<'life0, 'life1, 'async_trait>(
&'life0 mut self,
db: &'life1 (impl 'async_trait + Database),
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
db: &'life1 (impl 'async_trait + Database),
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn force_delete<'life0, 'life1, 'async_trait>(
&'life0 self,
db: &'life1 (impl 'async_trait + Database),
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
// Provided methods
fn has_soft_delete() -> bool { ... }
fn find<'life0, 'async_trait>(
db: &'life0 (impl 'async_trait + Database),
id: i64,
) -> Pin<Box<dyn Future<Output = Result<Option<Self>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn all<'life0, 'async_trait>(
db: &'life0 (impl 'async_trait + Database),
) -> Pin<Box<dyn Future<Output = Result<Vec<Self>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn validate(&self) -> Result<(), String> { ... }
fn save<'life0, 'life1, 'async_trait>(
&'life0 mut self,
db: &'life1 (impl 'async_trait + Database),
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
}Expand description
Model trait for database entities
Required Methods§
Sourcefn table_name() -> &'static str
fn table_name() -> &'static str
Get the table name
Sourcefn create<'life0, 'life1, 'async_trait>(
&'life0 mut self,
db: &'life1 (impl 'async_trait + Database),
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn create<'life0, 'life1, 'async_trait>(
&'life0 mut self,
db: &'life1 (impl 'async_trait + Database),
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Create a new record
Sourcefn update<'life0, 'life1, 'async_trait>(
&'life0 mut self,
db: &'life1 (impl 'async_trait + Database),
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn update<'life0, 'life1, 'async_trait>(
&'life0 mut self,
db: &'life1 (impl 'async_trait + Database),
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Update an existing record
Sourcefn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
db: &'life1 (impl 'async_trait + Database),
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
db: &'life1 (impl 'async_trait + Database),
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Delete the record (soft delete if supported, otherwise hard delete)
Provided Methods§
Sourcefn has_soft_delete() -> bool
fn has_soft_delete() -> bool
Check if the model supports soft deletes
Sourcefn find<'life0, 'async_trait>(
db: &'life0 (impl 'async_trait + Database),
id: i64,
) -> Pin<Box<dyn Future<Output = Result<Option<Self>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn find<'life0, 'async_trait>(
db: &'life0 (impl 'async_trait + Database),
id: i64,
) -> Pin<Box<dyn Future<Output = Result<Option<Self>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Find a record by ID
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.