pub trait BaseRepository {
type Entity: for<'r> FromRow<'r, PgRow> + DeserializeOwned + Serialize;
type PkType: for<'r> Type<Postgres>;
// Required methods
fn get_entities(
&self,
page: i32,
page_size: i32,
order_by: &'static str,
direction: PaginationOrder,
) -> impl Future<Output = Result<Vec<Self::Entity>>> + Send;
fn get_entity(
&self,
pk: Self::PkType,
) -> impl Future<Output = Result<Self::Entity>> + Send;
fn update_entity(
&self,
entity: Self::Entity,
) -> impl Future<Output = Result<u64>> + Send;
fn create_entity(
&self,
entity: Self::Entity,
) -> impl Future<Output = Result<Self::Entity>> + Send;
fn delete_entity(
&self,
pk: Self::PkType,
) -> impl Future<Output = Result<u64>> + Send;
}Expand description
This trait will be used for everything that wants to play around with your entity on a very basic level.
To get access to filtering the PaginatedSearch should be used as this trait already handles the entity itself most of the time.
Required Associated Types§
Required Methods§
Sourcefn get_entities(
&self,
page: i32,
page_size: i32,
order_by: &'static str,
direction: PaginationOrder,
) -> impl Future<Output = Result<Vec<Self::Entity>>> + Send
fn get_entities( &self, page: i32, page_size: i32, order_by: &'static str, direction: PaginationOrder, ) -> impl Future<Output = Result<Vec<Self::Entity>>> + Send
Gets a list of entities respecting the PaginationQuery
To do a filtered list use the PaginatedSearch helper
§Important Note
The order_by is supposed to be only a column name. Whoever implements this trait can rely on that. That said whoever calls this
method has to make sure, no SQL data is inserted here.
Sourcefn get_entity(
&self,
pk: Self::PkType,
) -> impl Future<Output = Result<Self::Entity>> + Send
fn get_entity( &self, pk: Self::PkType, ) -> impl Future<Output = Result<Self::Entity>> + Send
Gets a single entity by it’s primary key(s)
Sourcefn update_entity(
&self,
entity: Self::Entity,
) -> impl Future<Output = Result<u64>> + Send
fn update_entity( &self, entity: Self::Entity, ) -> impl Future<Output = Result<u64>> + Send
Updates an entity. Reads the primary key(s) from the input
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.