Trait lexa_framework::database::ModelInterface
source · pub trait ModelInterface {
type Database: SGBD;
type Entity: Unpin + Send + Sync + Serialize + DeserializeOwned;
// Required methods
fn new(database: &Self::Database) -> Self
where Self: Sized;
fn database(&self) -> &Self::Database;
fn table() -> &'static str;
fn fields() -> &'static [&'static str];
fn fetch_all<'c, 'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<Vec<Self::Entity>, Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'c: 'async_trait,
'life0: 'async_trait;
fn fetch_all_by_id<'life0, 'async_trait>(
&'life0 self,
id: impl 'async_trait + ToString + Send + Sync
) -> Pin<Box<dyn Future<Output = Result<Vec<Self::Entity>, Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn find_by_id<'life0, 'async_trait>(
&'life0 self,
id: impl 'async_trait + ToString + Send + Sync
) -> Pin<Box<dyn Future<Output = Result<Self::Entity, Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn create<'life0, 'async_trait>(
&'life0 self,
data: impl 'async_trait + Serialize + Send + Sync
) -> Pin<Box<dyn Future<Output = Result<Self::Entity, Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn delete_by_id<'life0, 'async_trait>(
&'life0 self,
id: impl 'async_trait + ToString + Send + Sync
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn update_by_id<'life0, 'async_trait>(
&'life0 self,
id: impl 'async_trait + ToString + Send + Sync,
data: impl 'async_trait + Serialize + Send + Sync
) -> Pin<Box<dyn Future<Output = Result<Self::Entity, Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Required Associated Types§
Required Methods§
fn database(&self) -> &Self::Database
sourcefn table() -> &'static str
fn table() -> &'static str
Nom de la table du model, correspondant à un nom de table d’une base de données.
sourcefn fetch_all<'c, 'life0, 'async_trait>(
&'life0 self
) -> Pin<Box<dyn Future<Output = Result<Vec<Self::Entity>, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'c: 'async_trait,
'life0: 'async_trait,
fn fetch_all<'c, 'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = Result<Vec<Self::Entity>, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'c: 'async_trait, 'life0: 'async_trait,
Récupère tous les résultats de la table Self::table().
sourcefn fetch_all_by_id<'life0, 'async_trait>(
&'life0 self,
id: impl 'async_trait + ToString + Send + Sync
) -> Pin<Box<dyn Future<Output = Result<Vec<Self::Entity>, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn fetch_all_by_id<'life0, 'async_trait>( &'life0 self, id: impl 'async_trait + ToString + Send + Sync ) -> Pin<Box<dyn Future<Output = Result<Vec<Self::Entity>, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,
Récupère tous les résultats de la table Self::table() en fonction d’un ID.
sourcefn find_by_id<'life0, 'async_trait>(
&'life0 self,
id: impl 'async_trait + ToString + Send + Sync
) -> Pin<Box<dyn Future<Output = Result<Self::Entity, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn find_by_id<'life0, 'async_trait>( &'life0 self, id: impl 'async_trait + ToString + Send + Sync ) -> Pin<Box<dyn Future<Output = Result<Self::Entity, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,
Cherche dans la table de la base de donnée s’il existe l’ID passé en
argument. En supposant qu’il existe un champ id dans la table.
sourcefn create<'life0, 'async_trait>(
&'life0 self,
data: impl 'async_trait + Serialize + Send + Sync
) -> Pin<Box<dyn Future<Output = Result<Self::Entity, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn create<'life0, 'async_trait>( &'life0 self, data: impl 'async_trait + Serialize + Send + Sync ) -> Pin<Box<dyn Future<Output = Result<Self::Entity, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,
Ajoute une entité en base de données.
sourcefn delete_by_id<'life0, 'async_trait>(
&'life0 self,
id: impl 'async_trait + ToString + Send + Sync
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn delete_by_id<'life0, 'async_trait>( &'life0 self, id: impl 'async_trait + ToString + Send + Sync ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,
Supprime une entité en base de données en fonction d’un ID.
sourcefn update_by_id<'life0, 'async_trait>(
&'life0 self,
id: impl 'async_trait + ToString + Send + Sync,
data: impl 'async_trait + Serialize + Send + Sync
) -> Pin<Box<dyn Future<Output = Result<Self::Entity, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn update_by_id<'life0, 'async_trait>( &'life0 self, id: impl 'async_trait + ToString + Send + Sync, data: impl 'async_trait + Serialize + Send + Sync ) -> Pin<Box<dyn Future<Output = Result<Self::Entity, Error>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,
Modifie les champs d’une table en base de données.
Object Safety§
This trait is not object safe.