carbon-dflow-aggregator-v4-decoder 2.0.0

Dflow Aggregator V4 Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
pub mod order_row;

pub use self::order_row::*;
use super::DflowAggregatorV4Account;

pub struct DflowAggregatorV4AccountsMigration;

impl sqlx_migrator::Migration<sqlx::Postgres> for DflowAggregatorV4AccountsMigration {
    fn app(&self) -> &str {
        "dflow-aggregator-v4"
    }

    fn name(&self) -> &str {
        "dflow_aggregator_v4_accounts"
    }

    fn operations(&self) -> Vec<Box<dyn sqlx_migrator::Operation<sqlx::Postgres>>> {
        vec![Box::new(OrderMigrationOperation)]
    }

    fn parents(&self) -> Vec<Box<dyn sqlx_migrator::Migration<sqlx::Postgres>>> {
        vec![]
    }
}

pub struct DflowAggregatorV4AccountWithMetadata(
    pub DflowAggregatorV4Account,
    pub carbon_core::account::AccountMetadata,
);

impl
    From<(
        DflowAggregatorV4Account,
        carbon_core::account::AccountMetadata,
    )> for DflowAggregatorV4AccountWithMetadata
{
    fn from(
        value: (
            DflowAggregatorV4Account,
            carbon_core::account::AccountMetadata,
        ),
    ) -> Self {
        DflowAggregatorV4AccountWithMetadata(value.0, value.1)
    }
}

#[async_trait::async_trait]
impl carbon_core::postgres::operations::Insert for DflowAggregatorV4AccountWithMetadata {
    async fn insert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> {
        let DflowAggregatorV4AccountWithMetadata(account, metadata) = self;

        match account {
            DflowAggregatorV4Account::Order(account) => {
                let row = order_row::OrderRow::from_parts(*account.clone(), metadata.clone());
                row.insert(pool).await?;
                Ok(())
            }
        }
    }
}

#[async_trait::async_trait]
impl carbon_core::postgres::operations::Upsert for DflowAggregatorV4AccountWithMetadata {
    async fn upsert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> {
        let DflowAggregatorV4AccountWithMetadata(account, metadata) = self;
        match account {
            DflowAggregatorV4Account::Order(account) => {
                let row = order_row::OrderRow::from_parts(*account.clone(), metadata.clone());
                row.upsert(pool).await?;
                Ok(())
            }
        }
    }
}