Skip to content

Instantly share code, notes, and snippets.

@c-garcia
Created December 12, 2015 06:48
Show Gist options
  • Save c-garcia/82a7b99807eb8fe7c2ed to your computer and use it in GitHub Desktop.
Save c-garcia/82a7b99807eb8fe7c2ed to your computer and use it in GitHub Desktop.
Datascript sample
(ns clj-wb.ds
(:require [datascript.core :as d]))
(let [schema {:tags {:db/cardinality :db.cardinality/many}}
conn (d/create-conn schema)]
(d/transact! conn [{:db/id 1
:name "John Doe"
:status :ok
:tags ["cplusplus" "java"]}
{:db/id 2
:name "Mark Doe"
:status :ko
:tags ["clojure" "python" "ruby"]}
{:db/id 97
:address "Baker Street, 14"
:who 1}
{:db/id 98
:address "Pedroneras, 24"
:who 2}])
;; db/id is the datom entity. person -> db/id
(d/q '[:find ?person ?name ?address
:where
[?person :name ?name]
[?data :who ?person]
[?data :address ?address]]
@conn))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment