pub fn fetch(&self, clause: &query::Clause) -> Result<Relation> {
        let mut vars = vec![];
        let mut selectors: Vec<Box<dyn Fn(&Record) -> Value>> = vec![];

        match clause.entity {
            query::Term::Bound(_) => {},
            query::Term::Unbound(ref var) => {
                vars.push(query::Var::new(var.name.clone()));
                selectors.push(Box::new(|record: &Record| Value::Ref(record.entity)));
            }
        };

        match clause.attribute {
            query::Term::Bound(_) => {},
            query::Term::Unbound(ref var) => {
                vars.push(query::Var::new(var.name.clone()));
                selectors.push(Box::new(|record: &Record| Value::Ref(record.attribute)));
            }
        };
        match clause.value {
            query::Term::Bound(_) => {},
            query::Term::Unbound(ref var) => {
                vars.push(query::Var::new(var.name.clone()));
                selectors.push(Box::new(|record: &Record| record.value.clone()));
            }
        };

        let mut values: Vec<Vec<Value>> = vec![];
        // FIXME: will need to remove retracted records from the relation
        // (and eventually deal with cardinality:one)

        for record in self.records_matching(&clause, &HashMap::new())? {
            let mut tuple: Vec<Value> = vec![];
            if record.retracted {
                // If the matching record is a retraction, the fact it
                // retracts will be the fact matched immediately
                // beforehand.
                values.pop();
            } else {
                for selector in selectors.iter() {
                    tuple.push(selector(&record));
                }
                values.push(tuple);
            }
        }

        Ok(Relation(vars, values))
    }
/// Given a clause, fetch the relation of matching records.
Given a clause, fetch the relation of matching records.
Given a clause fetch the relation of matching records .
pub fn fetch(&self, clause: &query::Clause) -> Result<Relation> {
        let mut vars = vec![];
        let mut selectors: Vec<Box<dyn Fn(&Record) -> Value>> = vec![];
        match clause.entity {
            query::Term::Bound(_) => {},
            query::Term::Unbound(ref var) => {
                vars.push(query::Var::new(var.name.clone()));
                selectors.push(Box::new(|record: &Record| Value::Ref(record.entity)));
            }
        };
        match clause.attribute {
            query::Term::Bound(_) => {},
            query::Term::Unbound(ref var) => {
                vars.push(query::Var::new(var.name.clone()));
                selectors.push(Box::new(|record: &Record| Value::Ref(record.attribute)));
            }
        };
        match clause.value {
            query::Term::Bound(_) => {},
            query::Term::Unbound(ref var) => {
                vars.push(query::Var::new(var.name.clone()));
                selectors.push(Box::new(|record: &Record| record.value.clone()));
            }
        };
        let mut values: Vec<Vec<Value>> = vec![];
        // FIXME: will need to remove retracted records from the relation
        // (and eventually deal with cardinality:one)
        for record in self.records_matching(&clause, &HashMap::new())? {
            let mut tuple: Vec<Value> = vec![];
            if record.retracted {
                // If the matching record is a retraction, the fact it
                // retracts will be the fact matched immediately
                // beforehand.
                values.pop();
            } else {
                for selector in selectors.iter() {
                    tuple.push(selector(&record));
                }
                values.push(tuple);
            }
        }
        Ok(Relation(vars, values))
    }
pub fn fetch ( & self , clause : & query :: Clause ) -> Result < Relation > { let mut vars = vec ! [ ] ; let mut selectors : Vec < Box < dyn Fn ( & Record ) -> Value > > = vec ! [ ] ; match clause . entity { query :: Term :: Bound ( _ ) => { } , query :: Term :: Unbound ( ref var ) => { vars . push ( query :: Var :: new ( var . name . clone ( ) ) ) ; selectors . push ( Box :: new ( | record : & Record | Value :: Ref ( record . entity ) ) ) ; } } ; match clause . attribute { query :: Term :: Bound ( _ ) => { } , query :: Term :: Unbound ( ref var ) => { vars . push ( query :: Var :: new ( var . name . clone ( ) ) ) ; selectors . push ( Box :: new ( | record : & Record | Value :: Ref ( record . attribute ) ) ) ; } } ; match clause . value { query :: Term :: Bound ( _ ) => { } , query :: Term :: Unbound ( ref var ) => { vars . push ( query :: Var :: new ( var . name . clone ( ) ) ) ; selectors . push ( Box :: new ( | record : & Record | record . value . clone ( ) ) ) ; } } ; let mut values : Vec < Vec < Value > > = vec ! [ ] ; // FIXME: will need to remove retracted records from the relation // (and eventually deal with cardinality:one) for record in self . records_matching ( & clause , & HashMap :: new ( ) ) ? { let mut tuple : Vec < Value > = vec ! [ ] ; if record . retracted { // If the matching record is a retraction, the fact it // retracts will be the fact matched immediately // beforehand. values . pop ( ) ; } else { for selector in selectors . iter ( ) { tuple . push ( selector ( & record ) ) ; } values . push ( tuple ) ; } } Ok ( Relation ( vars , values ) ) }
Given a clause, fetch the relation of matching records.
Given a clause fetch the relation of matching records .
&self
clause
&query::Clause
&self
clause
&query::Clause