Skip to main content

DatabaseOperations

Trait DatabaseOperations 

Source
pub trait DatabaseOperations<T>
where T: for<'a> FromRow<'a, PgRow> + Send + Unpin,
{ // Required methods fn create<'life0, 'life1, 'async_trait>( &'life0 self, entity: &'life1 T, ) -> Pin<Box<dyn Future<Output = Result<T, Error>> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait; fn find_by_id<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<T>, Error>> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait; fn find_all<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<T>, Error>> + Send + 'async_trait>> where 'life0: 'async_trait, Self: 'async_trait; fn update<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, id: &'life1 str, entity: &'life2 T, ) -> Pin<Box<dyn Future<Output = Result<Option<T>, Error>> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait; fn delete<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait; fn count<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>> where 'life0: 'async_trait, Self: 'async_trait; fn exists<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait; fn execute_query<'life0, 'life1, 'async_trait>( &'life0 self, query: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>> where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait; }
Expand description

Database operations trait - requires Serialize for write operations

Required Methods§

Source

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

Create a new entity

Source

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

Find entity by ID

Source

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

Find all entities

Source

fn update<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, id: &'life1 str, entity: &'life2 T, ) -> Pin<Box<dyn Future<Output = Result<Option<T>, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait,

Update an existing entity

Source

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

Delete an entity

Source

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

Count all entities

Source

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

Check if entity exists

Source

fn execute_query<'life0, 'life1, 'async_trait>( &'life0 self, query: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Execute custom query

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T> DatabaseOperations<T> for PostgresRepository<T>
where T: for<'a> FromRow<'a, PgRow> + Send + Sync + Unpin + Serialize,