// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ // ┃ Copyright: (c) 2023, Mike 'PhiSyX' S. (https://github.com/PhiSyX) ┃ // ┃ SPDX-License-Identifier: MPL-2.0 ┃ // ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃ // ┃ ┃ // ┃ This Source Code Form is subject to the terms of the Mozilla Public ┃ // ┃ License, v. 2.0. If a copy of the MPL was not distributed with this ┃ // ┃ file, You can obtain one at https://mozilla.org/MPL/2.0/. ┃ // ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ use lexa_database::SGBD; use lexa_framework::database::services::postgres; use lexa_framework::database::{ModelError, ModelPostgresInterface}; use crate::crud_site::models::entities::ArticleEntity; // --------- // // Structure // // --------- // pub struct ArticlesRepository { database: postgres::PostgresService, } // -------------- // // Implémentation // // -------------- // impl ArticlesRepository { /// Supprime toutes les entités en base de données d'une table. pub async fn delete_all(&self) -> Result<(), ModelError> { sqlb::delete_all() .table(Self::table()) .exec(self.database().pool()) .await?; Ok(()) } } // -------------- // // Implémentation // -> Interface // -------------- // #[async_trait::async_trait] impl ModelPostgresInterface for ArticlesRepository { type Entity = ArticleEntity; fn new(database: &postgres::PostgresService) -> Self { Self { database: database.clone(), } } fn database(&self) -> &postgres::PostgresService { &self.database } fn table() -> &'static str { "articles" } }