PostgresRepository

Trait PostgresRepository 

Source
pub trait PostgresRepository {
    type Error;
    type Item;

    // Required methods
    fn find_by_id<'life0, 'async_trait>(
        &'life0 self,
        id: Uuid,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Self::Item>, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn find_by_name<'life0, 'async_trait>(
        &'life0 self,
        name: String,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Self::Item>, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn list<'life0, 'async_trait>(
        &'life0 self,
        filters: Option<HashMap<String, String>>,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<Self::Item>, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn create<'life0, 'life1, 'async_trait>(
        &'life0 self,
        item: &'life1 Self::Item,
    ) -> Pin<Box<dyn Future<Output = Result<Uuid, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn delete<'life0, 'async_trait>(
        &'life0 self,
        id: Uuid,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn delete_all<'life0, 'async_trait>(
        &'life0 self,
        filters: Option<HashMap<String, String>>,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn update<'life0, 'life1, 'async_trait>(
        &'life0 self,
        item: &'life1 Self::Item,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

Repository trait for PostgreSQL database operations

This trait defines a common interface for database repositories that handle CRUD operations and queries on PostgreSQL tables.

Required Associated Types§

Source

type Error

The error type returned by repository operations

Source

type Item

The database model type this repository handles

Required Methods§

Source

fn find_by_id<'life0, 'async_trait>( &'life0 self, id: Uuid, ) -> Pin<Box<dyn Future<Output = Result<Option<Self::Item>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Finds a single item by its UUID

§Arguments
  • id - The UUID to search for
§Returns

The found item wrapped in Some, or None if not found

Source

fn find_by_name<'life0, 'async_trait>( &'life0 self, name: String, ) -> Pin<Box<dyn Future<Output = Result<Option<Self::Item>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Finds a single item by its name/slug

§Arguments
  • name - The name or slug to search for
§Returns

The found item wrapped in Some, or None if not found

Source

fn list<'life0, 'async_trait>( &'life0 self, filters: Option<HashMap<String, String>>, ) -> Pin<Box<dyn Future<Output = Result<Vec<Self::Item>, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Lists items matching optional filters

§Arguments
  • filters - Optional HashMap of column names and values to filter by
§Returns

Vector of items matching the filters

Source

fn create<'life0, 'life1, 'async_trait>( &'life0 self, item: &'life1 Self::Item, ) -> Pin<Box<dyn Future<Output = Result<Uuid, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Creates a new item in the database

§Arguments
  • item - The item to create
§Returns

The UUID of the created item

Source

fn delete<'life0, 'async_trait>( &'life0 self, id: Uuid, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Deletes an item by its UUID

§Arguments
  • id - The UUID of the item to delete
Source

fn delete_all<'life0, 'async_trait>( &'life0 self, filters: Option<HashMap<String, String>>, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Deletes multiple items matching optional filters

§Arguments
  • filters - Optional HashMap of column names and values to filter deletions by
Source

fn update<'life0, 'life1, 'async_trait>( &'life0 self, item: &'life1 Self::Item, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Updates an existing item

§Arguments
  • item - The item with updated values

Implementors§

Source§

impl PostgresRepository for ArticleRepository

Implementation of PostgresRepository trait for ArticleRepository

Source§

impl PostgresRepository for ImageRepository

Implementation of PostgresRepository trait for ImageRepository