fn load_aggregate_from_snapshot(
        &mut self,
        aggregate_id: &str,
    ) -> Result<AggregateContext<C, E, A>, Error> {
        self.create_snapshot_table()?;

        let aggregate_type = A::aggregate_type();

        trace!(
            "loading snapshot for aggregate id '{}'",
            aggregate_id
        );

        let mut sql = match self.conn.prepare(SELECT_SNAPSHOT) {
            Ok(x) => x,
            Err(e) => {
                return Err(Error::new(
                    format!(
                        "unable to prepare snapshots table for \
                         aggregate id '{}', error: {}",
                        &aggregate_id, e,
                    )
                    .as_str(),
                ));
            },
        };

        let res = match sql.query_map(
            params![aggregate_type, aggregate_id],
            |row| Ok((row.get(0)?, row.get(1)?)),
        ) {
            Ok(x) => x,
            Err(e) => {
                return Err(Error::new(
                    format!(
                        "unable to load snapshots table for \
                         aggregate id '{}', error: {}",
                        &aggregate_id, e,
                    )
                    .as_str(),
                ));
            },
        };

        let mut rows: Vec<(i64, String)> = Vec::new();

        for x in res {
            rows.push(x.unwrap());
        }

        if rows.len() == 0 {
            trace!(
                "returning default aggregate for aggregate id
        '{}'",
                aggregate_id
            );

            return Ok(AggregateContext::new(
                aggregate_id.to_string(),
                0,
                A::default(),
            ));
        };

        let row = rows[0].clone();

        let payload = match serde_json::from_str(row.1.as_str()) {
            Ok(x) => x,
            Err(e) => {
                return Err(Error::new(
                    format!(
                        "bad payload found in snapshots table for \
                         aggregate id '{}' with error: {}",
                        &aggregate_id, e
                    )
                    .as_str(),
                ));
            },
        };

        Ok(AggregateContext::new(
            aggregate_id.to_string(),
            row.0,
            payload,
        ))
    }
/// Load aggregate at current state from snapshots
Load aggregate at current state from snapshots
Load aggregate at current state from snapshots
fn load_aggregate_from_snapshot(
        &mut self,
        aggregate_id: &str,
    ) -> Result<AggregateContext<C, E, A>, Error> {
        self.create_snapshot_table()?;
        let aggregate_type = A::aggregate_type();
        trace!(
            "loading snapshot for aggregate id '{}'",
            aggregate_id
        );
        let mut sql = match self.conn.prepare(SELECT_SNAPSHOT) {
            Ok(x) => x,
            Err(e) => {
                return Err(Error::new(
                    format!(
                        "unable to prepare snapshots table for \
                         aggregate id '{}', error: {}",
                        &aggregate_id, e,
                    )
                    .as_str(),
                ));
            },
        };
        let res = match sql.query_map(
            params![aggregate_type, aggregate_id],
            |row| Ok((row.get(0)?, row.get(1)?)),
        ) {
            Ok(x) => x,
            Err(e) => {
                return Err(Error::new(
                    format!(
                        "unable to load snapshots table for \
                         aggregate id '{}', error: {}",
                        &aggregate_id, e,
                    )
                    .as_str(),
                ));
            },
        };
        let mut rows: Vec<(i64, String)> = Vec::new();
        for x in res {
            rows.push(x.unwrap());
        }
        if rows.len() == 0 {
            trace!(
                "returning default aggregate for aggregate id
        '{}'",
                aggregate_id
            );
            return Ok(AggregateContext::new(
                aggregate_id.to_string(),
                0,
                A::default(),
            ));
        };
        let row = rows[0].clone();
        let payload = match serde_json::from_str(row.1.as_str()) {
            Ok(x) => x,
            Err(e) => {
                return Err(Error::new(
                    format!(
                        "bad payload found in snapshots table for \
                         aggregate id '{}' with error: {}",
                        &aggregate_id, e
                    )
                    .as_str(),
                ));
            },
        };
        Ok(AggregateContext::new(
            aggregate_id.to_string(),
            row.0,
            payload,
        ))
    }
fn load_aggregate_from_snapshot ( & mut self , aggregate_id : & str , ) -> Result < AggregateContext < C , E , A > , Error > { self . create_snapshot_table ( ) ? ; let aggregate_type = A :: aggregate_type ( ) ; trace ! ( " " aggregate_id ) ; let mut sql = match self . conn . prepare ( SELECT_SNAPSHOT ) { Ok ( x ) => x , Err ( e ) => { return Err ( Error :: new ( format ! ( " \
 " aggregate_id e ) . as_str ( ) , ) ) ; } , } ; let res = match sql . query_map ( params ! [ aggregate_type aggregate_id ] , | row | Ok ( ( row . get ( 0 ) ? , row . get ( 1 ) ? ) ) , ) { Ok ( x ) => x , Err ( e ) => { return Err ( Error :: new ( format ! ( " \
 " aggregate_id e ) . as_str ( ) , ) ) ; } , } ; let mut rows : Vec < ( i64 , String ) > = Vec :: new ( ) ; for x in res { rows . push ( x . unwrap ( ) ) ; } if rows . len ( ) == 0 { trace ! ( " " aggregate_id ) ; return Ok ( AggregateContext :: new ( aggregate_id . to_string ( ) , 0 , A :: default ( ) , ) ) ; } ; let row = rows [ 0 ] . clone ( ) ; let payload = match serde_json :: from_str ( row . 1 . as_str ( ) ) { Ok ( x ) => x , Err ( e ) => { return Err ( Error :: new ( format ! ( " \
 " aggregate_id e ) . as_str ( ) , ) ) ; } , } ; Ok ( AggregateContext :: new ( aggregate_id . to_string ( ) , row . 0 , payload , ) ) }
Load aggregate at current state from snapshots
Load aggregate at current state from snapshots
&mut self
aggregate_id
&str
&mut self
aggregate_id
&str