pub trait Model<DB>: Sized + TableMetawhere
DB: Database,{
type ModelBuilder<'a>: ModelBuilder<'a, DB>
where Self: 'a;
// Required methods
fn insert<'a, A>(self, conn: A) -> Insertion<'a, A, Self, DB>
where A: 'a + Send + Acquire<'a, Database = DB>,
Self: Send;
fn insert_many<'e, E>(
values: Vec<Self>,
db: E,
) -> Pin<Box<dyn Future<Output = Result<Vec<Self>, Error>> + Send + 'e>>
where E: 'e + Executor<'e, Database = DB>;
fn update_all_fields<'e, E>(
self,
db: E,
) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + Send + 'e>>
where E: 'e + Send + Executor<'e, Database = DB>;
fn delete<'e, E>(
self,
db: E,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'e>>
where E: 'e + Executor<'e, Database = DB>;
fn fetch_one<'e, 'a, Arg, E>(
id: Arg,
db: E,
) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + Send + 'e>>
where 'a: 'e,
E: 'e + Executor<'e, Database = DB>,
Arg: 'a + Send + Encode<'a, DB> + Type<DB>;
fn query(
query: &str,
) -> QueryAs<'_, DB, Self, <DB as Database>::Arguments<'_>>;
fn select<'args>() -> SelectQueryBuilder<'args, DB, Self>;
fn update_partial(&self) -> Self::ModelBuilder<'_>;
fn builder() -> Self::ModelBuilder<'static>;
}
Expand description
The core trait. a struct that implements Model
can also implement HasModelBuilder
, (and is required to implement Insertable
)
Required Associated Types§
type ModelBuilder<'a>: ModelBuilder<'a, DB> where Self: 'a
Required Methods§
Sourcefn insert<'a, A>(self, conn: A) -> Insertion<'a, A, Self, DB>
fn insert<'a, A>(self, conn: A) -> Insertion<'a, A, Self, DB>
Insert the model into the database.
fn insert_many<'e, E>(
values: Vec<Self>,
db: E,
) -> Pin<Box<dyn Future<Output = Result<Vec<Self>, Error>> + Send + 'e>>where
E: 'e + Executor<'e, Database = DB>,
Sourcefn update_all_fields<'e, E>(
self,
db: E,
) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + Send + 'e>>
fn update_all_fields<'e, E>( self, db: E, ) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + Send + 'e>>
Model
objects can’t track what fields are updated, so this method will update all fields.
If you want to update only some fields, use update_partial
instead.
fn delete<'e, E>(
self,
db: E,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'e>>where
E: 'e + Executor<'e, Database = DB>,
Sourcefn fetch_one<'e, 'a, Arg, E>(
id: Arg,
db: E,
) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + Send + 'e>>
fn fetch_one<'e, 'a, Arg, E>( id: Arg, db: E, ) -> Pin<Box<dyn Future<Output = Result<Self, Error>> + Send + 'e>>
Get by primary key.
Sourcefn query(query: &str) -> QueryAs<'_, DB, Self, <DB as Database>::Arguments<'_>>
fn query(query: &str) -> QueryAs<'_, DB, Self, <DB as Database>::Arguments<'_>>
If query building isn’t meeting your needs, use this method to query the table using raw SQL.
Sourcefn select<'args>() -> SelectQueryBuilder<'args, DB, Self>
fn select<'args>() -> SelectQueryBuilder<'args, DB, Self>
Create a SelectQueryBuilder
to build a query.
Sourcefn update_partial(&self) -> Self::ModelBuilder<'_>
fn update_partial(&self) -> Self::ModelBuilder<'_>
Create a builder-pattern object to update one or more columns.
You can also use update_all_fields
to update all columns.
fn builder() -> Self::ModelBuilder<'static>
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.