Skip to content

Instantly share code, notes, and snippets.

@wavejumper
Created October 3, 2020 03:25
Show Gist options
  • Save wavejumper/fd1fa56ac2f4ec2d516fb07b49641097 to your computer and use it in GitHub Desktop.
Save wavejumper/fd1fa56ac2f4ec2d516fb07b49641097 to your computer and use it in GitHub Desktop.
cljspad + datascript
(require '[datascript.core :as d])
;; Example from datascript README
;; https://github.com/tonsky/datascript
(def schema {:aka {:db/cardinality :db.cardinality/many}})
(def conn (d/create-conn schema))
(d/transact! conn [ { :db/id -1
:name "Maksim"
:age 45
:aka ["Max Otto von Stierlitz", "Jack Ryan"] } ])
;; Implicit join, multi-valued attribute
(def query-result
(d/q '[ :find ?n ?a
:where [?e :aka "Max Otto von Stierlitz"]
[?e :name ?n]
[?e :age ?a] ]
@conn))
(prn query-result)
(write-output (str "Result is: " (pr-str query-result)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment