Repository

Trait Repository 

Source
pub trait Repository: Send + Sync {
    type Error: Error + Send + Sync;
    type Pool;

    // Required method
    fn pool(&self) -> &Self::Pool;
}
Expand description

Base repository trait.

All generated {Entity}Repository traits include these associated types and methods. This trait is not directly extended but serves as documentation for the common interface.

§Associated Types

  • Error — Error type for repository operations
  • Pool — Underlying database pool type

§Example

Generated traits follow this pattern:

#[async_trait]
pub trait UserRepository: Send + Sync {
    type Error: std::error::Error + Send + Sync;
    type Pool;

    fn pool(&self) -> &Self::Pool;
    async fn create(&self, dto: CreateUserRequest) -> Result<User, Self::Error>;
    async fn find_by_id(&self, id: Uuid) -> Result<Option<User>, Self::Error>;
    // ...
}

Required Associated Types§

Source

type Error: Error + Send + Sync

Error type for repository operations.

Must implement std::error::Error + Send + Sync for async compatibility.

Source

type Pool

Underlying database pool type.

Enables access to the pool for transactions and custom queries.

Required Methods§

Source

fn pool(&self) -> &Self::Pool

Get reference to the underlying database pool.

§Example
let pool = repo.pool();
let mut tx = pool.begin().await?;
// Custom operations...
tx.commit().await?;

Implementors§