This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-01
Channels
- # beginners (71)
- # boot (148)
- # cider (21)
- # cljs-dev (2)
- # cljsjs (35)
- # clojure (212)
- # clojure-russia (42)
- # clojure-spec (36)
- # clojure-uk (28)
- # clojurescript (18)
- # cursive (2)
- # datascript (20)
- # datomic (2)
- # hoplon (2)
- # off-topic (355)
- # om (2)
- # onyx (1)
- # protorepl (1)
- # reagent (34)
- # ring-swagger (6)
- # rum (8)
- # sql (4)
- # untangled (64)
- # vim (22)
- # yada (1)
@mrg why not:
(def db (ds/create-conn {:supervisors {:db/cardinality :db.cardinality/many}}))
(ds/transact db [{:name "max" :supervisors [1 2 3]}
{:name "dilbert" :supervisors [1 2]}])
(defn supervised-by [supervisors]
(ds/q '[:find [?e ...]
:in $ [?supervisor ...]
:where
[?e :supervisors ?supervisor]]
@db supervisors))
(supervised-by [3])
=> [1]
(supervised-by [2 3])
=> [1 2]
(supervised-by [1])
=> [1 2]
(supervised-by [2])
=> [1 2]
or just:
(ds/q '[:find [?e ...]
:in $ ?supervisor
:where [?e :supervisors ?supervisor]]
@db 3)
=> [1]
?@mrg you'd probably need to have
{:supervisors {:db/cardinality :db.cardinality/many :db/valueType :db.type/ref}}
if you want to look up by references, not by integer attributes, like e.g. price
, etc.I haven't really come across datascript schemas yet. Setting the value type to ref would mean that this is a reference to another entity, right?
I think you need to invest few hours in these: http://www.datomic.com/training.html
and look up stuff here too: http://docs.datomic.com/schema.html
it might not behave exactly as in datomic, but it'll get you 95% (or even 100% for many use cases) there
It's a very big topic; too big to dive in without a project to guide the reading, but then you come across things like my problem that you don't understand without having seen the right approach at some points