Trait FetchableEntity

Source
pub trait FetchableEntity {
    type SourceEntity;

    // Required method
    fn fetch<'a>(
        &self,
        executor: impl PgExecutor<'a>,
    ) -> impl Future<Output = Result<Option<Self::SourceEntity>, Error>>;
}
Expand description

Trait for types that can be fetched by primary key(s) from the database. A “Pk” struct is generated for each entity, containing only the primary key fields.

Required Associated Types§

Source

type SourceEntity

The entity type returned after fetching (typically the main entity struct).

Required Methods§

Source

fn fetch<'a>( &self, executor: impl PgExecutor<'a>, ) -> impl Future<Output = Result<Option<Self::SourceEntity>, Error>>

Fetch the entity from the database by its primary key(s).

§Arguments
  • pool - A reference to a PostgreSQL connection pool.
§Returns

A future resolving to either Some(entity) if found, None if not found, or a SQLx error.

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§