Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(ns user.stage
(:require
[datomic.api :as d]))
(defn with [$ tx]
(:db-after (d/with $ tx)))
(comment
(datomic.api/create-database "datomic:mem://app-db")
(def conn (datomic.api/connect "datomic:mem://app-db"))
(let [$ (-> (d/db conn)
(with [{:db/ident :dustingetz/email :db/valueType :db.type/string :db/cardinality :db.cardinality/one :db/unique :db.unique/identity}
{:db/ident :dustingetz/gender :db/valueType :db.type/ref :db/cardinality :db.cardinality/one}
{:db/ident :dustingetz/shirt-size :db/valueType :db.type/ref :db/cardinality :db.cardinality/one}
{:db/ident :dustingetz/type :db/valueType :db.type/keyword :db/cardinality :db.cardinality/one}])
(with [{:dustingetz/type :dustingetz/gender :db/ident :dustingetz/male}
{:dustingetz/type :dustingetz/gender :db/ident :dustingetz/female}])
(with [{:dustingetz/type :dustingetz/shirt-size :db/ident :dustingetz/mens-small :dustingetz/gender :dustingetz/male}
{:dustingetz/type :dustingetz/shirt-size :db/ident :dustingetz/mens-medium :dustingetz/gender :dustingetz/male}
{:dustingetz/type :dustingetz/shirt-size :db/ident :dustingetz/mens-large :dustingetz/gender :dustingetz/male}
{:dustingetz/type :dustingetz/shirt-size :db/ident :dustingetz/womens-small :dustingetz/gender :dustingetz/female}
{:dustingetz/type :dustingetz/shirt-size :db/ident :dustingetz/womens-medium :dustingetz/gender :dustingetz/female}
{:dustingetz/type :dustingetz/shirt-size :db/ident :dustingetz/womens-large :dustingetz/gender :dustingetz/female}])
(with [{:dustingetz/email "alice@example.com" :dustingetz/gender :dustingetz/female :dustingetz/shirt-size :dustingetz/womens-large}
{:dustingetz/email "bob@example.com" :dustingetz/gender :dustingetz/male :dustingetz/shirt-size :dustingetz/mens-large}
{:dustingetz/email "charlie@example.com" :dustingetz/gender :dustingetz/male :dustingetz/shirt-size :dustingetz/mens-medium}]))]
(d/q '[:find [(pull ?e [*]) ...]
:where
[?e :dustingetz/email]] $))
=>
[{:db/id 17592186045428,
:dustingetz/email "alice@example.com",
:dustingetz/gender #:db{:id 17592186045419},
:dustingetz/shirt-size #:db{:id 17592186045426}}
{:db/id 17592186045429,
:dustingetz/email "bob@example.com",
:dustingetz/gender #:db{:id 17592186045418},
:dustingetz/shirt-size #:db{:id 17592186045423}}
{:db/id 17592186045430,
:dustingetz/email "charlie@example.com",
:dustingetz/gender #:db{:id 17592186045418},
:dustingetz/shirt-size #:db{:id 17592186045422}}]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.