Skip to main content

Database

Trait Database 

Source
pub trait Database: Send + Sync {
    type Input;
    type Output;
    type Config: Config;
    type TransformRequest: TransformRequest<Input = Self::Input, Output = Self::Output>;
    type TransformAttempt: TransformAttempt<CallArgsType = Self::Input, ReturnType = Self::Output>;
    type ConsumeAttempt: ConsumeAttempt<ConsumeVal = Self::Output>;
    type DatabaseError: Send + Sync + Error;

    // Required methods
    fn new<'async_trait>(
        ctx: Arc<Mutex<Self::Config>>,
    ) -> Pin<Box<dyn Future<Output = Result<Self, Self::DatabaseError>> + Send + 'async_trait>>
       where Self: Sized + 'async_trait;
    fn get_dyn_configs<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<(<Self::Config as Config>::KeyType, <Self::Config as Config>::ValueType)>, Self::DatabaseError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn register_transform_request<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        request: &'life1 Self::TransformRequest,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::DatabaseError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn register_transform_attempt<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        attempt: &'life1 Self::TransformAttempt,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::DatabaseError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn update_transform_attempt<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        attempt: &'life1 WorkerManagerResult<Self::TransformAttempt>,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::DatabaseError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn register_consume_attempt<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        attempt: &'life1 Self::ConsumeAttempt,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::DatabaseError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn update_consume_attempt<'life0, 'async_trait>(
        &'life0 mut self,
        attempt: ConsumeAttemptResult<Self::ConsumeAttempt>,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::DatabaseError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn archive_request_with_id<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        request: &'life1 <Self::TransformRequest as TransformRequest>::Identifier,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::DatabaseError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}

Required Associated Types§

Source

type Input

Source

type Output

Source

type Config: Config

Source

type TransformRequest: TransformRequest<Input = Self::Input, Output = Self::Output>

Source

type TransformAttempt: TransformAttempt<CallArgsType = Self::Input, ReturnType = Self::Output>

Source

type ConsumeAttempt: ConsumeAttempt<ConsumeVal = Self::Output>

Source

type DatabaseError: Send + Sync + Error

Required Methods§

Source

fn new<'async_trait>( ctx: Arc<Mutex<Self::Config>>, ) -> Pin<Box<dyn Future<Output = Result<Self, Self::DatabaseError>> + Send + 'async_trait>>
where Self: Sized + 'async_trait,

Source

fn get_dyn_configs<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<Vec<(<Self::Config as Config>::KeyType, <Self::Config as Config>::ValueType)>, Self::DatabaseError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn register_transform_request<'life0, 'life1, 'async_trait>( &'life0 mut self, request: &'life1 Self::TransformRequest, ) -> Pin<Box<dyn Future<Output = Result<(), Self::DatabaseError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source

fn register_transform_attempt<'life0, 'life1, 'async_trait>( &'life0 mut self, attempt: &'life1 Self::TransformAttempt, ) -> Pin<Box<dyn Future<Output = Result<(), Self::DatabaseError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source

fn update_transform_attempt<'life0, 'life1, 'async_trait>( &'life0 mut self, attempt: &'life1 WorkerManagerResult<Self::TransformAttempt>, ) -> Pin<Box<dyn Future<Output = Result<(), Self::DatabaseError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source

fn register_consume_attempt<'life0, 'life1, 'async_trait>( &'life0 mut self, attempt: &'life1 Self::ConsumeAttempt, ) -> Pin<Box<dyn Future<Output = Result<(), Self::DatabaseError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source

fn update_consume_attempt<'life0, 'async_trait>( &'life0 mut self, attempt: ConsumeAttemptResult<Self::ConsumeAttempt>, ) -> Pin<Box<dyn Future<Output = Result<(), Self::DatabaseError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn archive_request_with_id<'life0, 'life1, 'async_trait>( &'life0 mut self, request: &'life1 <Self::TransformRequest as TransformRequest>::Identifier, ) -> Pin<Box<dyn Future<Output = Result<(), Self::DatabaseError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Implementors§

Source§

impl<TR, TA, CA, C> Database for InMemoryDatabase<TR, TA, CA, C>
where TR: TransformRequest + Send + Sync, TA: TransformAttempt<TransformRequestIdentifier = TR::Identifier, CallArgsType = TR::Input, ReturnType = TR::Output> + Send + Sync, CA: ConsumeAttempt<TransformRequestIdentifier = TR::Identifier, TransformAttemptIdentifier = TA::Identifier, ConsumeVal = TR::Output> + Send + Sync, C: Config<KeyType = String, ValueType = Vec<u8>>, TR::Identifier: Hash,

Source§

impl<TR, TA, CA, C> Database for PostgresDatabase<TR, TA, CA, C>
where TR: TransformRequest + Send + Sync + for<'a> Deserialize<'a> + Serialize, TA: TransformAttempt<TransformRequestIdentifier = TR::Identifier, CallArgsType = TR::Input, ReturnType = TR::Output> + Send + Sync + DeserializeOwned + Serialize, CA: ConsumeAttempt<TransformRequestIdentifier = TR::Identifier, TransformAttemptIdentifier = TA::Identifier, ConsumeVal = TR::Output> + Send + Sync + DeserializeOwned + Serialize, C: Config<KeyType = String, ValueType = Vec<u8>>, TR::Input: Serialize + DeserializeOwned, TR::Output: Serialize + DeserializeOwned, CA::Identifier: Serialize + DeserializeOwned, CA::ReturnCtx: Serialize + DeserializeOwned, TR::Identifier: Serialize + DeserializeOwned, TA::Identifier: Serialize + DeserializeOwned, TA::ReturnPackage: Serialize + DeserializeOwned,

To create a custom table based on your requirements For example: The input struct is

struct Person {
    name: String,
    address: String,
    phone: String,
}

pub trait PersonTrait {
    fn get_name(&self) -> String;
    fn get_address(&self) -> String;
    fn get_phone(&self) -> String;
}

impl Database for PostgresDatabase
where
    TR::Input: PersonTrait
    ...
{
     
}

You can do the sane to output, transform attempt, transform request and consume attempt
And, store the relevant things to the database.