pub trait Model: DeserializeOwned + Serialize + Sized + Send + Sync + Debug + Default {
type PrimaryKey: Display + DeserializeOwned + Serialize + PartialEq + Default + Clone + Send + Sync;
const NAME: &'static str;
const TABLE_NAME: &'static str;
const PRIMARY_KEY: &'static str;
// Required methods
fn primary_key(&self) -> &Self::PrimaryKey;
fn find(
key: Self::PrimaryKey
) -> impl Future<Output = Result<Self, Error>> + Send;
fn create(self) -> impl Future<Output = Result<Self, Error>> + Send;
fn save(&mut self) -> impl Future<Output = Result<(), Error>> + Send;
fn fresh(&self) -> impl Future<Output = Result<Self, Error>> + Send;
// Provided methods
fn all() -> impl Future<Output = Result<Vec<Self>, Error>> + Send { ... }
fn delete(self) -> impl Future<Output = Result<(), Error>> + Send { ... }
fn query() -> Builder { ... }
fn with<T: Into<EagerLoad>>(eager_load: T) -> Builder { ... }
fn load<T: Into<EagerLoad> + Send>(
&mut self,
relation: T
) -> impl Future<Output = Result<(), Error>> + Send { ... }
fn increment(
&mut self,
column: &str,
amount: u64
) -> impl Future<Output = Result<(), Error>> + Send { ... }
fn json(&self) -> Value { ... }
}
Required Associated Types§
sourcetype PrimaryKey: Display + DeserializeOwned + Serialize + PartialEq + Default + Clone + Send + Sync
type PrimaryKey: Display + DeserializeOwned + Serialize + PartialEq + Default + Clone + Send + Sync
The type of the primary key for the model.
Required Associated Constants§
sourceconst TABLE_NAME: &'static str
const TABLE_NAME: &'static str
The name of the table for the model
sourceconst PRIMARY_KEY: &'static str
const PRIMARY_KEY: &'static str
The name of the primary key field for the model.
Required Methods§
sourcefn primary_key(&self) -> &Self::PrimaryKey
fn primary_key(&self) -> &Self::PrimaryKey
Returns the value of the model’s primary key.
sourcefn find(
key: Self::PrimaryKey
) -> impl Future<Output = Result<Self, Error>> + Send
fn find( key: Self::PrimaryKey ) -> impl Future<Output = Result<Self, Error>> + Send
Find a model by its primary key.
Errors
Returns an error if the model cannot be found, or if a connection to the database cannot be established.
sourcefn create(self) -> impl Future<Output = Result<Self, Error>> + Send
fn create(self) -> impl Future<Output = Result<Self, Error>> + Send
Insert a new model into the database.
Errors
Returns an error if the model cannot be inserted, or if a connection to the database cannot be established.
Provided Methods§
sourcefn all() -> impl Future<Output = Result<Vec<Self>, Error>> + Send
fn all() -> impl Future<Output = Result<Vec<Self>, Error>> + Send
Get all of the models from the database.
Errors
Returns an error if the query fails, or if a connection to the database cannot be established.
sourcefn delete(self) -> impl Future<Output = Result<(), Error>> + Send
fn delete(self) -> impl Future<Output = Result<(), Error>> + Send
Delete the model from the database.
Errors
Returns an error if the model cannot be deleted, or if a connection to the database cannot be established.
sourcefn with<T: Into<EagerLoad>>(eager_load: T) -> Builder
fn with<T: Into<EagerLoad>>(eager_load: T) -> Builder
Begin querying a model with eager loading.
sourcefn load<T: Into<EagerLoad> + Send>(
&mut self,
relation: T
) -> impl Future<Output = Result<(), Error>> + Send
fn load<T: Into<EagerLoad> + Send>( &mut self, relation: T ) -> impl Future<Output = Result<(), Error>> + Send
Load a relationship for the model.