pub fn add(&self, fact: Fact, tx_entity: Entity) -> Result<(Db, Record)> {
        let attr = match self.schema.idents.get(&fact.attribute) {
            Some(a) => a,
            None => return Err(format!("invalid attribute: ident '{:?}' does not exist", &fact.attribute).into())
        };

        let fact_value_type = match fact.value {
            Value::String(_) => ValueType::String,
            Value::Ref(_) => ValueType::Ref,
            Value::Timestamp(_) => ValueType::Timestamp,
            Value::Ident(_) => ValueType::Ident,
            Value::Boolean(_) => ValueType::Boolean,
            Value::Long(_) => ValueType::Long,
        };

        match self.schema.value_types.get(&attr) {
            Some(schema_type) => {
                if *schema_type == fact_value_type {
                    let record = Record::addition(fact.entity, *attr, fact.value, tx_entity);
                    return self.add_record(record.clone()).map(|new_db| (new_db, record));
                } else {
                    return Err(format!(
                        "type error: attribute {:?} does not match expected value type {:?}",
                        fact.attribute,
                        fact_value_type
                    ).into())
                }
            },
            None => return Err(format!("ident {:?} is not a valid attribute", fact.attribute).into())
        }
    }
/// Add a record to the DB, validating that it matches the schema.
Add a record to the DB, validating that it matches the schema.
Add a record to the DB validating that it matches the schema .
pub fn add(&self, fact: Fact, tx_entity: Entity) -> Result<(Db, Record)> {
        let attr = match self.schema.idents.get(&fact.attribute) {
            Some(a) => a,
            None => return Err(format!("invalid attribute: ident '{:?}' does not exist", &fact.attribute).into())
        };
        let fact_value_type = match fact.value {
            Value::String(_) => ValueType::String,
            Value::Ref(_) => ValueType::Ref,
            Value::Timestamp(_) => ValueType::Timestamp,
            Value::Ident(_) => ValueType::Ident,
            Value::Boolean(_) => ValueType::Boolean,
            Value::Long(_) => ValueType::Long,
        };
        match self.schema.value_types.get(&attr) {
            Some(schema_type) => {
                if *schema_type == fact_value_type {
                    let record = Record::addition(fact.entity, *attr, fact.value, tx_entity);
                    return self.add_record(record.clone()).map(|new_db| (new_db, record));
                } else {
                    return Err(format!(
                        "type error: attribute {:?} does not match expected value type {:?}",
                        fact.attribute,
                        fact_value_type
                    ).into())
                }
            },
            None => return Err(format!("ident {:?} is not a valid attribute", fact.attribute).into())
        }
    }
pub fn add ( & self , fact : Fact , tx_entity : Entity ) -> Result < ( Db , Record ) > { let attr = match self . schema . idents . get ( & fact . attribute ) { Some ( a ) => a , None => return Err ( format ! ( " " fact attribute ) . into ( ) ) } ; let fact_value_type = match fact . value { Value :: String ( _ ) => ValueType :: String , Value :: Ref ( _ ) => ValueType :: Ref , Value :: Timestamp ( _ ) => ValueType :: Timestamp , Value :: Ident ( _ ) => ValueType :: Ident , Value :: Boolean ( _ ) => ValueType :: Boolean , Value :: Long ( _ ) => ValueType :: Long , } ; match self . schema . value_types . get ( & attr ) { Some ( schema_type ) => { if * schema_type == fact_value_type { let record = Record :: addition ( fact . entity , * attr , fact . value , tx_entity ) ; return self . add_record ( record . clone ( ) ) . map ( | new_db | ( new_db , record ) ) ; } else { return Err ( format ! ( " " fact attribute fact_value_type ) . into ( ) ) } } , None => return Err ( format ! ( " " fact attribute ) . into ( ) ) } }
Add a record to the DB, validating that it matches the schema.
Add a record to the DB validating that it matches the schema .
&self
fact
Fact
tx_entity
Entity
&self
fact
Fact
tx_entity
Entity