pub trait ModelExt: Model {
// Provided methods
fn query() -> QueryBuilder { ... }
fn hydrate(rows: &[Row]) -> Result<Vec<Self>> { ... }
fn all(db: &Database) -> impl Future<Output = Result<Vec<Self>>> + Send
where Self: Send { ... }
fn find(
db: &Database,
key: Self::Key,
) -> impl Future<Output = Result<Option<Self>>> + Send
where Self: Send { ... }
fn find_or_fail(
db: &Database,
key: Self::Key,
) -> impl Future<Output = Result<Self>> + Send
where Self: Send { ... }
fn get(
db: &Database,
query: QueryBuilder,
) -> impl Future<Output = Result<Vec<Self>>> + Send
where Self: Send { ... }
fn first(
db: &Database,
query: QueryBuilder,
) -> impl Future<Output = Result<Option<Self>>> + Send
where Self: Send { ... }
fn count(db: &Database) -> impl Future<Output = Result<i64>> + Send
where Self: Send { ... }
fn insert(
&mut self,
db: &Database,
) -> impl Future<Output = Result<()>> + Send
where Self: Send { ... }
fn update(&self, db: &Database) -> impl Future<Output = Result<u64>> + Send
where Self: Send + Sync { ... }
fn delete(&self, db: &Database) -> impl Future<Output = Result<u64>> + Send
where Self: Send + Sync { ... }
fn to_json(&self) -> Json
where Self: Sync { ... }
}Expand description
The query and persistence methods every model gets.
A blanket implementation, so a model author writes no code for any of this.
Provided Methods§
Sourcefn query() -> QueryBuilder
fn query() -> QueryBuilder
Start a query against this model’s table.
fn all(db: &Database) -> impl Future<Output = Result<Vec<Self>>> + Sendwhere
Self: Send,
Sourcefn find(
db: &Database,
key: Self::Key,
) -> impl Future<Output = Result<Option<Self>>> + Sendwhere
Self: Send,
fn find(
db: &Database,
key: Self::Key,
) -> impl Future<Output = Result<Option<Self>>> + Sendwhere
Self: Send,
Find by primary key.
Sourcefn find_or_fail(
db: &Database,
key: Self::Key,
) -> impl Future<Output = Result<Self>> + Sendwhere
Self: Send,
fn find_or_fail(
db: &Database,
key: Self::Key,
) -> impl Future<Output = Result<Self>> + Sendwhere
Self: Send,
Find by primary key, or fail with a message naming the model.
Sourcefn get(
db: &Database,
query: QueryBuilder,
) -> impl Future<Output = Result<Vec<Self>>> + Sendwhere
Self: Send,
fn get(
db: &Database,
query: QueryBuilder,
) -> impl Future<Output = Result<Vec<Self>>> + Sendwhere
Self: Send,
Run a prepared builder and hydrate the results.
fn first(
db: &Database,
query: QueryBuilder,
) -> impl Future<Output = Result<Option<Self>>> + Sendwhere
Self: Send,
fn count(db: &Database) -> impl Future<Output = Result<i64>> + Sendwhere
Self: Send,
Sourcefn insert(&mut self, db: &Database) -> impl Future<Output = Result<()>> + Sendwhere
Self: Send,
fn insert(&mut self, db: &Database) -> impl Future<Output = Result<()>> + Sendwhere
Self: Send,
Insert this record and adopt the key the database generated.
Sourcefn update(&self, db: &Database) -> impl Future<Output = Result<u64>> + Send
fn update(&self, db: &Database) -> impl Future<Output = Result<u64>> + Send
Update the row this record’s key points at.
fn delete(&self, db: &Database) -> impl Future<Output = Result<u64>> + Send
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".