// By default, we append rows
// To in-place update rows, create a tableformat and define what columns are your primary keys
// Then new_data is compared against all the table data
// The comparison is for a row where the values at the primary keys match the new_data values
// If found, that row is replaced with new_data values
By default, we append rows
To in-place update rows, create a tableformat and define what columns are your primary keys
Then new_data is compared against all the table data
The comparison is for a row where the values at the primary keys match the new_data values
If found, that row is replaced with new_data values
By default we append rows To in - place update rows create a tableformat and define what columns are your primary keys Then new_data is compared against all the table data The comparison is for a row where the values at the primary keys match the new_data values If found that row is replaced with new_data values
pub fn update_row(&mut self, new_data: BTreeMap<String, String>) -> Result<()> {
        // For the first row, we know we can just insert data
        if self.data.is_empty() {
            self.data.push(new_data);
            return Ok(());
        }
        // Get a list of the primary keys
        // If we don't have a primary key set, the default behavior is to append the row
        let all_primary_keys = self.get_primary_keys();
        //println!("Primary key: {:?}", primary_keys);
        if let Some(primary_keys) = all_primary_keys {
            let mut append_row = true;
            // use the primary keys when evaluating a row update
            for (index, row) in self.data.iter().enumerate() {
                // Look over the primary keys to determine if we update the row
                // Reset flag for next row processing
                append_row = false;
                for (index, key) in primary_keys.iter().enumerate() {
                    match row.get(key.as_str()) {
                        Some(value) => {
                            if let Some(new_data_value) = new_data.get(key.as_str()) {
                                // primary key value, and new_data values don't match
                                if value != new_data_value {
                                    append_row = true;
                                    continue;
                                } else {
                                    // If this is the last primary key we're checking
                                    // Break out of the primary key loop
                                    if (index + 1) == self.data.len() {
                                        append_row = false;
                                        break;
                                    }
                                }
                            } else {
                                // key doesn't exist in new_data
                                append_row = true;
                            }
                        }
                        None => {
                            // key doesn't exist in row
                            append_row = true;
                        }
                    }
                }
                // If the values for the primary keys match, then update the row
                if !append_row {
                    self.data[index] = new_data.clone();
                    break;
                }
            }
            // Otherwise append the data to the end after we look at all the rows
            if append_row {
                self.data.push(new_data);
            }
        } else {
            // Append data
            self.data.push(new_data);
        }
        Ok(())
    }
pub fn update_row ( & mut self , new_data : BTreeMap < String , String > ) -> Result < ( ) > { // For the first row, we know we can just insert data if self . data . is_empty ( ) { self . data . push ( new_data ) ; return Ok ( ( ) ) ; } // Get a list of the primary keys // If we don't have a primary key set, the default behavior is to append the row let all_primary_keys = self . get_primary_keys ( ) ; //println!("Primary key: {:?}", primary_keys); if let Some ( primary_keys ) = all_primary_keys { let mut append_row = true ; // use the primary keys when evaluating a row update for ( index , row ) in self . data . iter ( ) . enumerate ( ) { // Look over the primary keys to determine if we update the row // Reset flag for next row processing append_row = false ; for ( index , key ) in primary_keys . iter ( ) . enumerate ( ) { match row . get ( key . as_str ( ) ) { Some ( value ) => { if let Some ( new_data_value ) = new_data . get ( key . as_str ( ) ) { // primary key value, and new_data values don't match if value != new_data_value { append_row = true ; continue ; } else { // If this is the last primary key we're checking // Break out of the primary key loop if ( index + 1 ) == self . data . len ( ) { append_row = false ; break ; } } } else { // key doesn't exist in new_data append_row = true ; } } None => { // key doesn't exist in row append_row = true ; } } } // If the values for the primary keys match, then update the row if ! append_row { self . data [ index ] = new_data . clone ( ) ; break ; } } // Otherwise append the data to the end after we look at all the rows if append_row { self . data . push ( new_data ) ; } } else { // Append data self . data . push ( new_data ) ; } Ok ( ( ) ) }
By default, we append rows
To in-place update rows, create a tableformat and define what columns are your primary keys
Then new_data is compared against all the table data
The comparison is for a row where the values at the primary keys match the new_data values
If found, that row is replaced with new_data values
By default we append rows To in - place update rows create a tableformat and define what columns are your primary keys Then new_data is compared against all the table data The comparison is for a row where the values at the primary keys match the new_data values If found that row is replaced with new_data values
&mut self
new_data
BTreeMap<String, String>