pub trait CrudRepository:
Sized
+ Send
+ Unpin
+ for<'r> FromRow<'r, DbRow> {
const TABLE: &'static str;
const ENTITY_NAME: &'static str;
const HAS_SLUG: bool = false;
const SOFT_DELETE: bool = false;
Show 13 methods
// Provided methods
fn soft_filter() -> &'static str { ... }
fn soft_where() -> &'static str { ... }
fn find_by_id(
pool: &DbPool,
id: i64,
) -> impl Future<Output = AppResult<Option<Self>>> + Send { ... }
fn find_by_slug(
pool: &DbPool,
slug: &str,
) -> impl Future<Output = AppResult<Option<Self>>> + Send { ... }
fn count(pool: &DbPool) -> impl Future<Output = AppResult<i64>> + Send { ... }
fn exists(
pool: &DbPool,
id: i64,
) -> impl Future<Output = AppResult<bool>> + Send { ... }
fn delete(
pool: &DbPool,
id: i64,
) -> impl Future<Output = AppResult<u64>> + Send { ... }
fn force_delete(
pool: &DbPool,
id: i64,
) -> impl Future<Output = AppResult<u64>> + Send { ... }
fn restore(
pool: &DbPool,
id: i64,
) -> impl Future<Output = AppResult<u64>> + Send { ... }
fn find_all(
pool: &DbPool,
order: Option<(&str, &str)>,
) -> impl Future<Output = AppResult<Vec<Self>>> + Send { ... }
fn find_all_with_trashed(
pool: &DbPool,
order: Option<(&str, &str)>,
) -> impl Future<Output = AppResult<Vec<Self>>> + Send { ... }
fn find_where(
pool: &DbPool,
conditions: &[(&str, WhereValue)],
) -> impl Future<Output = AppResult<Option<Self>>> + Send { ... }
fn find_all_where(
pool: &DbPool,
conditions: &[(&str, WhereValue)],
order: Option<(&str, &str)>,
) -> impl Future<Output = AppResult<Vec<Self>>> + Send { ... }
}Expand description
Trait générique pour les opérations CRUD de base.
Fournit automatiquement find_by_id, count, delete, exists,
find_all et optionnellement find_by_slug à tout type qui l’implémente.
Supporte le soft delete via SOFT_DELETE = true : les entités ne sont pas
supprimées mais marquées avec deleted_at. Les requêtes filtrent
automatiquement les entités supprimées.
impl CrudRepository for Post {
const TABLE: &'static str = "posts";
const ENTITY_NAME: &'static str = "Article";
const HAS_SLUG: bool = true;
const SOFT_DELETE: bool = true;
}Required Associated Constants§
Provided Associated Constants§
const HAS_SLUG: bool = false
Sourceconst SOFT_DELETE: bool = false
const SOFT_DELETE: bool = false
Active le soft delete. Si true, delete() fait un UPDATE SET deleted_at = NOW()
au lieu d’un DELETE, et toutes les requêtes ajoutent WHERE deleted_at IS NULL.
Provided Methods§
Sourcefn soft_filter() -> &'static str
fn soft_filter() -> &'static str
Retourne le filtre soft delete si activé
fn soft_where() -> &'static str
fn find_by_id( pool: &DbPool, id: i64, ) -> impl Future<Output = AppResult<Option<Self>>> + Send
fn find_by_slug( pool: &DbPool, slug: &str, ) -> impl Future<Output = AppResult<Option<Self>>> + Send
fn count(pool: &DbPool) -> impl Future<Output = AppResult<i64>> + Send
fn exists( pool: &DbPool, id: i64, ) -> impl Future<Output = AppResult<bool>> + Send
Sourcefn delete(pool: &DbPool, id: i64) -> impl Future<Output = AppResult<u64>> + Send
fn delete(pool: &DbPool, id: i64) -> impl Future<Output = AppResult<u64>> + Send
Supprime une entité (soft delete si SOFT_DELETE = true, sinon DELETE réel).
Sourcefn force_delete(
pool: &DbPool,
id: i64,
) -> impl Future<Output = AppResult<u64>> + Send
fn force_delete( pool: &DbPool, id: i64, ) -> impl Future<Output = AppResult<u64>> + Send
Suppression définitive (ignore SOFT_DELETE).
Sourcefn restore(
pool: &DbPool,
id: i64,
) -> impl Future<Output = AppResult<u64>> + Send
fn restore( pool: &DbPool, id: i64, ) -> impl Future<Output = AppResult<u64>> + Send
Restaure une entité soft-deleted.
Sourcefn find_all(
pool: &DbPool,
order: Option<(&str, &str)>,
) -> impl Future<Output = AppResult<Vec<Self>>> + Send
fn find_all( pool: &DbPool, order: Option<(&str, &str)>, ) -> impl Future<Output = AppResult<Vec<Self>>> + Send
let users = User::find_all(pool, None).await?;
let categories = Category::find_all(pool, Some(("name", "ASC"))).await?;Sourcefn find_all_with_trashed(
pool: &DbPool,
order: Option<(&str, &str)>,
) -> impl Future<Output = AppResult<Vec<Self>>> + Send
fn find_all_with_trashed( pool: &DbPool, order: Option<(&str, &str)>, ) -> impl Future<Output = AppResult<Vec<Self>>> + Send
Récupère toutes les entités y compris les soft-deleted.
Sourcefn find_where(
pool: &DbPool,
conditions: &[(&str, WhereValue)],
) -> impl Future<Output = AppResult<Option<Self>>> + Send
fn find_where( pool: &DbPool, conditions: &[(&str, WhereValue)], ) -> impl Future<Output = AppResult<Option<Self>>> + Send
let user = User::find_where(pool, &[("email", "foo@bar.com".into())]).await?;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.