pub fn add_record(&self, record: Record) -> Result<Db> {
        let new_eav = self.eav.insert(record.clone());
        let new_aev = self.aev.insert(record.clone());

        let mut new_vae = self.vae.clone();
        // TODO: only add to AVET if db:indexed is true
        let new_ave = self.ave.insert(record.clone());

        if let Record { value: Value::Ref(_), .. } = record {
            new_vae = new_vae.insert(record.clone());
        }

        // If the record modifies a schema attribute, we need to update the schema.
        let mut new_schema = self.schema.clone();
        if record.attribute == *self.schema.idents.get("db:ident").expect("`db:ident` not in ident map") {
            match record.value {
                Value::Ident(ref s) => new_schema = new_schema.add_ident(record.entity, s.clone()),
                _ => return Err("db:ident value must be an ident".into()),
            };
        };

        if record.attribute == *self.schema.idents.get("db:valueType").expect("db:valueType not in ident map") {
            let value_type = match record.value {
                Value::Ident(ref s) => {
                    match s.as_str() {
                        "db:type:string" => ValueType::String,
                        "db:type:ident" => ValueType::Ident,
                        "db:type:timestamp" => ValueType::Timestamp,
                        "db:type:ref" => ValueType::Ref,
                        "db:type:boolean" => ValueType::Boolean,
                        _ => return Err(format!("{} is not a valid primitive type", s).into()),
                    }
                },
                _ => return Err("db:valueType must be an identifier".into()),
            };

            new_schema = new_schema.add_value_type(record.entity, value_type);
        };

        if record.attribute == *self.schema.idents.get("db:indexed").unwrap() {
            let indexed = match record.value {
                Value::Boolean(b) => b,
                v => return Err(format!("invalid value type {:?} passed with db:indexed", v).into())
            };

            if indexed {
                new_schema = new_schema.add_indexed(record.attribute);
            } else {
                new_schema = new_schema.remove_indexed(&record.attribute);
            }
        }

        Ok(Db {
            eav: new_eav,
            ave: new_ave,
            aev: new_aev,
            vae: new_vae,
            schema: new_schema,
            store: self.store.clone(),
        })
    }
/// Add a record to the database. Does not validate that the fact
/// fits the schema, in order to allow bootstrapping.
Add a record to the database. Does not validate that the fact
fits the schema, in order to allow bootstrapping.
Add a record to the database . Does not validate that the fact fits the schema in order to allow bootstrapping .
pub fn add_record(&self, record: Record) -> Result<Db> {
        let new_eav = self.eav.insert(record.clone());
        let new_aev = self.aev.insert(record.clone());
        let mut new_vae = self.vae.clone();
        // TODO: only add to AVET if db:indexed is true
        let new_ave = self.ave.insert(record.clone());
        if let Record { value: Value::Ref(_), .. } = record {
            new_vae = new_vae.insert(record.clone());
        }
        // If the record modifies a schema attribute, we need to update the schema.
        let mut new_schema = self.schema.clone();
        if record.attribute == *self.schema.idents.get("db:ident").expect("`db:ident` not in ident map") {
            match record.value {
                Value::Ident(ref s) => new_schema = new_schema.add_ident(record.entity, s.clone()),
                _ => return Err("db:ident value must be an ident".into()),
            };
        };
        if record.attribute == *self.schema.idents.get("db:valueType").expect("db:valueType not in ident map") {
            let value_type = match record.value {
                Value::Ident(ref s) => {
                    match s.as_str() {
                        "db:type:string" => ValueType::String,
                        "db:type:ident" => ValueType::Ident,
                        "db:type:timestamp" => ValueType::Timestamp,
                        "db:type:ref" => ValueType::Ref,
                        "db:type:boolean" => ValueType::Boolean,
                        _ => return Err(format!("{} is not a valid primitive type", s).into()),
                    }
                },
                _ => return Err("db:valueType must be an identifier".into()),
            };
            new_schema = new_schema.add_value_type(record.entity, value_type);
        };
        if record.attribute == *self.schema.idents.get("db:indexed").unwrap() {
            let indexed = match record.value {
                Value::Boolean(b) => b,
                v => return Err(format!("invalid value type {:?} passed with db:indexed", v).into())
            };
            if indexed {
                new_schema = new_schema.add_indexed(record.attribute);
            } else {
                new_schema = new_schema.remove_indexed(&record.attribute);
            }
        }
        Ok(Db {
            eav: new_eav,
            ave: new_ave,
            aev: new_aev,
            vae: new_vae,
            schema: new_schema,
            store: self.store.clone(),
        })
    }
pub fn add_record ( & self , record : Record ) -> Result < Db > { let new_eav = self . eav . insert ( record . clone ( ) ) ; let new_aev = self . aev . insert ( record . clone ( ) ) ; let mut new_vae = self . vae . clone ( ) ; // TODO: only add to AVET if db:indexed is true let new_ave = self . ave . insert ( record . clone ( ) ) ; if let Record { value : Value :: Ref ( _ ) , .. } = record { new_vae = new_vae . insert ( record . clone ( ) ) ; } // If the record modifies a schema attribute, we need to update the schema. let mut new_schema = self . schema . clone ( ) ; if record . attribute == * self . schema . idents . get ( " " ) . expect ( " " ) { match record . value { Value :: Ident ( ref s ) => new_schema = new_schema . add_ident ( record . entity , s . clone ( ) ) , _ => return Err ( " " . into ( ) ) , } ; } ; if record . attribute == * self . schema . idents . get ( " " ) . expect ( " " ) { let value_type = match record . value { Value :: Ident ( ref s ) => { match s . as_str ( ) { " " => ValueType :: String , " " => ValueType :: Ident , " " => ValueType :: Timestamp , " " => ValueType :: Ref , " " => ValueType :: Boolean , _ => return Err ( format ! ( " " s ) . into ( ) ) , } } , _ => return Err ( " " . into ( ) ) , } ; new_schema = new_schema . add_value_type ( record . entity , value_type ) ; } ; if record . attribute == * self . schema . idents . get ( " " ) . unwrap ( ) { let indexed = match record . value { Value :: Boolean ( b ) => b , v => return Err ( format ! ( " " v ) . into ( ) ) } ; if indexed { new_schema = new_schema . add_indexed ( record . attribute ) ; } else { new_schema = new_schema . remove_indexed ( & record . attribute ) ; } } Ok ( Db { eav : new_eav , ave : new_ave , aev : new_aev , vae : new_vae , schema : new_schema , store : self . store . clone ( ) , } ) }
Add a record to the database.
Add a record to the database .
&self
record
Record
&self
record
Record