mairie360_api_lib 0.3.4

Lib for mairie360 APIs
Documentation
use crate::database::errors::DatabaseError;
use crate::database::queries_result_views::utils::QueryResult;
use async_trait::async_trait;
use tokio_postgres::Client;

/**
 * QueryResultView Trait
 * This trait defines the behavior of a query result view.
 * It provides a method to get the result of a query.
 */
pub trait QueryResultView {
    /// Returns the result of the query as a QueryResult.
    /// This method should be implemented by any struct that implements this trait.
    fn get_result(&self) -> QueryResult;
}

/**
 * DatabaseQueryView Trait
 * This trait defines the behavior of a database query view.
 * It provides methods to get the request string and the type of query.
 */
pub trait DatabaseQueryView: Send {
    /**
     * Returns the request string of the query.
     * This method should be implemented by any struct that implements this trait.
     * It is expected to return a string representation of the query request.
     */
    fn get_request(&self) -> String;
    fn get_raw_request(&self) -> String;
}

#[async_trait]
pub trait Query {
    type Output: QueryResultView;
    type View: DatabaseQueryView;

    async fn execute(&self, client: &Client) -> Result<Self::Output, DatabaseError>;

    fn view(&self) -> &Self::View;
}