Trait 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§

Source

type Database: SGBD

Base de donnée.

Source

type Entity: Unpin + Send + Sync + Serialize + DeserializeOwned

Entité du modèle.

Required Methods§

Source

fn new(database: &Self::Database) -> Self
where Self: Sized,

Crée une instance du model.

Source

fn database(&self) -> &Self::Database

Source

fn table() -> &'static str

Nom de la table du model, correspondant à un nom de table d’une base de données.

Source

fn fields() -> &'static [&'static str]

Tous les champs d’une entité.

Source

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().

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

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.

Implementors§