Skip to content

Instantly share code, notes, and snippets.

@mauricioszabo
Created July 8, 2020 19:34
Show Gist options
  • Select an option

  • Save mauricioszabo/eb6af91b0e65b25d3e5aab4e11498bf7 to your computer and use it in GitHub Desktop.

Select an option

Save mauricioszabo/eb6af91b0e65b25d3e5aab4e11498bf7 to your computer and use it in GitHub Desktop.
Crux by-temporality
(defn start-standalone-node ^crux.api.ICruxAPI []
(crux/start-node {:crux.node/topology '[crux.standalone/topology]
:crux.kv/db-dir "/tmp/crux"}))
(def conn (start-standalone-node))
(def day-1
(crux/submit-tx conn [[:crux.tx/put
{:crux.db/id :alice
:location :north
:name "Alice"}
#inst "2020-01-01"]
[:crux.tx/put
{:crux.db/id :bob
:location :south
:name "Bob"}
#inst "2020-01-01"]]))
(def day-2
(crux/submit-tx conn [[:crux.tx/put
{:crux.db/id :carlos
:location :north
:name "Carlos"}
#inst "2020-01-02"]]))
(def day-3
(crux/submit-tx conn [[:crux.tx/put
{:crux.db/id :daniel
:location :south
:name "Daniel"}
#inst "2020-01-02"]
[:crux.tx/put
{:crux.db/id :elias
:location :north
:name "Elias"}
#inst "2020-01-03"]]))
; TODAY
(crux/q (crux/db conn) '{:find [name entrance]
:where [[id :name name]
[id :location entrance]]})
; DAY 1
(crux/q (crux/db conn #inst "2020-01-01")
'{:find [name entrance]
:where [[id :name name]
[id :location entrance]]})
; DAY 2
(crux/q (crux/db conn #inst "2020-01-02")
'{:find [name entrance]
:where [[id :name name]
[id :location entrance]]})
; DAY 2, what DAY 2 knew
(crux/q (crux/db conn #inst "2020-01-02" (:crux.tx/tx-time day-2))
'{:find [name entrance]
:where [[id :name name]
[id :location entrance]]})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment