(query-all session)

(query-all session rule-name)

When called with just a session, returns a vector of all inserted facts. Otherwise, returns a vector of maps containing all the matches for the given rule.

Examples

Query all the facts from the session
(query-all session)
Query the matches for a rule
(query-all session :odoyle.examples/get-todo)

Source

(defn query-all "When called with just a session, returns a vector of all inserted facts.\n Otherwise, returns a vector of maps containing all the matches for the given rule." ([session] (mapv (fn [[[id attr] nodes]] (-> (get-in session (first nodes)) (get-in [:facts id attr]) ((juxt :id :attr :value)))) (:id-attr-nodes session))) ([session rule-name] (let [rule-id (or (get-in session [:rule-name->node-id rule-name]) (throw (ex-info (str rule-name " not in session") {}))) rule (get-in session [:beta-nodes rule-id])] (reduce-kv (fn [v _ {:keys [vars enabled]}] (if enabled (conj v vars) v)) [] (:matches rule)))))