// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ // ┃ 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::auth_site::models::entities::UserEntity; // --------- // // Structure // // --------- // pub struct UsersRepository { database: postgres::PostgresService, } // -------------- // // Implémentation // // -------------- // impl UsersRepository { pub async fn find_by_name( &self, username: impl AsRef, ) -> Result<::Entity, ModelError> { let record = sqlb::select() .table(Self::table()) .and_where_eq("name", username.as_ref()) .fetch_one(self.database.pool()) .await?; Ok(record) } } // -------------- // // Implémentation // -> Interface // -------------- // #[lexa_framework::async_trait] impl ModelPostgresInterface for UsersRepository { type Entity = UserEntity; fn new(database: &postgres::PostgresService) -> Self { Self { database: database.clone(), } } fn database(&self) -> &postgres::PostgresService { &self.database } fn table() -> &'static str { "users" } }