   (:require [clojure.edn :as edn]
             [clojure.core.logic :as l]
             [clojure.core.logic.pldb :as lp]
+            [clojure.core.logic.fd :as lfd]
             [korma.core :as db]
             [eventsourcing.db :as evdb]))
 



(defn get-facts [& {:keys [where-criteria]}]
  (let [query (-> (db/select* es_events)
                  (#(if where-criteria
                      (db/where % where-criteria)
                      %))
                  (db/order :tx :desc))
        facts (volatile! {}) ;; need to define it outside xf, as select-lazy transduces multiple times
        xf (comp (fn [xf]
                   (fn
                     ([] (xf))
                     ([result] (xf result))


(defn get-logic-db []
  (->> (get-facts)
       project-facts
       #_(into [] (map (fn [{:keys [e a v t]}]
                         [fact e a v t])))
       (into [] (map #(vec (cons fact %))))
       (apply lp/db)))


