                                (:tx %))))]
     (evdb/select-lazy query xf)))
 
+(defn project-facts [facts]
+  "Projects given facts to a given timestamp."
+  (let [facts* (volatile! {})
+        xf (fn [xf]
+             (fn
+               ([] (xf))
+               ([result] (xf result))
+               ([result [e a v t action :as input]]
+                (case action
+                  :add (case (get-in @facts* [e a])
+                         true result
+                         ::retracted (do (vswap! facts* #(update-in % [e] dissoc a))
+                                         result)
+                         nil (do (vswap! facts* #(assoc-in % [e a] true))
+                                 (xf result (take 4 input))))
+                  :retract (do (vswap! facts* #(assoc-in % [e a] ::retracted))
+                               result)))))]
+    (into [] xf facts)))
+
 (defn get-entity [eid]
-  (let [facts (get-facts :where-criteria {:eid eid})]
+  "Retrieves entire entity."
+  (let [facts (-> (get-facts :where-criteria {:eid eid})
+                  project-facts)]
     (reduce (fn [s {:keys [a v]}]
               (if-not (contains? s a)
                 (assoc s a v)


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



  (: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]))

