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

Object Safety§

This trait is not object safe.

Implementors§