fn sync_db(
        conn: &PgConnection,
        asset_group_id: i32,
        reprs: &mut Vec<Self>,
    ) -> Result<(), Error> {
        let existing = Config::get_group_map(conn, asset_group_id)?;

        let (mut to_insert, to_update, to_delete) = Self::partition_diff(existing, reprs)?;

        let new_configs: Vec<NewConfig> = to_insert
            .iter_mut()
            .map(|asset| asset.as_insertable(asset_group_id))
            .collect();
        println!("Insert configs: {:#?}", new_configs);
        new_configs.insert_all(conn)?;
        println!("Inserted all configs.");

        for (_, config) in to_update {
            println!("Updating config {:#?}", config);
            config.update(conn)?;
        }
        println!("Updated all configs.");

        let delete_ids: Vec<i32> = to_delete.iter().map(|asset| asset.config_id).collect();
        Config::delete_all(conn, &delete_ids)?;

        Ok(())
    }
/// Given a list of representations, syncs the tables in the database with this list.
/// This sync includes inserting new entries, updating existing entries, and deleting removed
/// entries.
Given a list of representations, syncs the tables in the database with this list.
This sync includes inserting new entries, updating existing entries, and deleting removed
entries.
Given a list of representations syncs the tables in the database with this list . This sync includes inserting new entries updating existing entries and deleting removed entries .
fn sync_db(
        conn: &PgConnection,
        asset_group_id: i32,
        reprs: &mut Vec<Self>,
    ) -> Result<(), Error> {
        let existing = Config::get_group_map(conn, asset_group_id)?;
        let (mut to_insert, to_update, to_delete) = Self::partition_diff(existing, reprs)?;
        let new_configs: Vec<NewConfig> = to_insert
            .iter_mut()
            .map(|asset| asset.as_insertable(asset_group_id))
            .collect();
        println!("Insert configs: {:#?}", new_configs);
        new_configs.insert_all(conn)?;
        println!("Inserted all configs.");
        for (_, config) in to_update {
            println!("Updating config {:#?}", config);
            config.update(conn)?;
        }
        println!("Updated all configs.");
        let delete_ids: Vec<i32> = to_delete.iter().map(|asset| asset.config_id).collect();
        Config::delete_all(conn, &delete_ids)?;
        Ok(())
    }
fn sync_db ( conn : & PgConnection , asset_group_id : i32 , reprs : & mut Vec < Self > , ) -> Result < ( ) , Error > { let existing = Config :: get_group_map ( conn , asset_group_id ) ? ; let ( mut to_insert , to_update , to_delete ) = Self :: partition_diff ( existing , reprs ) ? ; let new_configs : Vec < NewConfig > = to_insert . iter_mut ( ) . map ( | asset | asset . as_insertable ( asset_group_id ) ) . collect ( ) ; println ! ( " " new_configs ) ; new_configs . insert_all ( conn ) ? ; println ! ( " " ) ; for ( _ , config ) in to_update { println ! ( " " config ) ; config . update ( conn ) ? ; } println ! ( " " ) ; let delete_ids : Vec < i32 > = to_delete . iter ( ) . map ( | asset | asset . config_id ) . collect ( ) ; Config :: delete_all ( conn , & delete_ids ) ? ; Ok ( ( ) ) }
Given a list of representations, syncs the tables in the database with this list.
Given a list of representations syncs the tables in the database with this list .
conn
&PgConnection
asset_group_id
i32
reprs
&mut Vec<Self>
conn
&PgConnection
asset_group_id
i32
reprs
&mut Vec<Self>