Skip to main content

EsRepo

Trait EsRepo 

Source
pub trait EsRepo: Send {
    type Entity: EsEntity;
    type CreateError;
    type ModifyError;
    type FindError: From<Error> + From<EntityHydrationError> + Send;
    type QueryError: From<Error> + From<EntityHydrationError> + Send;
    type EsQueryFlavor;

    // Required method
    fn load_all_nested_in_op<OP, E>(
        op: &mut OP,
        entities: &mut [Self::Entity],
    ) -> impl Future<Output = Result<(), E>> + Send
       where OP: AtomicOperation,
             E: From<Error> + From<EntityHydrationError> + Send;

    // Provided method
    fn load_all_nested_in_op_include_deleted<OP, E>(
        op: &mut OP,
        entities: &mut [Self::Entity],
    ) -> impl Future<Output = Result<(), E>> + Send
       where OP: AtomicOperation,
             E: From<Error> + From<EntityHydrationError> + Send { ... }
}
Expand description

Required trait for all repositories to be compatible with es-entity and generate functions.

All repositories implement this trait to satisfy the basic requirements for type-safe database operations with the associated entity. The trait ensures validation that required fields (like entity) are present with compile-time errors. Implemented by the EsRepo derive macro with #[es_repo] attributes.

§Example


// Would show error for missing entity field if not provided in the `es_repo` attribute
#[derive(EsRepo, Debug)]
#[es_repo(entity = "User", columns(name(ty = "String")))]
pub struct Users {
    pool: PgPool,  // Required field for database operations
}

impl Users {
    pub fn new(pool: PgPool) -> Self {
        Self { pool }
   }
}

Required Associated Types§

Required Methods§

Source

fn load_all_nested_in_op<OP, E>( op: &mut OP, entities: &mut [Self::Entity], ) -> impl Future<Output = Result<(), E>> + Send

Loads all nested entities for a given set of parent entities within an atomic operation.

Provided Methods§

Source

fn load_all_nested_in_op_include_deleted<OP, E>( op: &mut OP, entities: &mut [Self::Entity], ) -> impl Future<Output = Result<(), E>> + Send

Like load_all_nested_in_op but includes soft-deleted children.

Default implementation delegates to load_all_nested_in_op.

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.

Implementors§