This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-22
Channels
- # beginners (10)
- # boot (134)
- # cider (29)
- # clara (2)
- # cljs-dev (10)
- # cljsjs (2)
- # cljsrn (13)
- # clojure (76)
- # clojure-india (4)
- # clojure-ireland (1)
- # clojure-russia (20)
- # clojure-spec (11)
- # clojure-uk (7)
- # clojurescript (88)
- # core-async (5)
- # core-logic (3)
- # cursive (17)
- # datascript (5)
- # datomic (123)
- # hoplon (8)
- # klipse (6)
- # lambdaisland (2)
- # leiningen (4)
- # luminus (2)
- # off-topic (23)
- # om (23)
- # om-next (1)
- # onyx (20)
- # pedestal (2)
- # perun (2)
- # re-frame (11)
- # ring-swagger (3)
- # untangled (12)
I want to be able to check if an entity I'm adding is already in the collection, but using a ref won't work because there are multiple keys that make the entity unique, and making multiple keys unique makes a new addition upsert. So I thought I'd just query first, but the problem now arises that I don't know how many key/values the entity will have beforehand. I tried something like this:
(def contains?-conn (d/create-conn {}))
(d/transact! contains?-conn [{:db/id -1 :thing/name "bla" :thing/other "blabla"}])
(d/q `[:find ?id .
:in $
:where
~(for [[key val]
{:thing/name "bla"
:thing/other "blabla"}]
['?id key val])]
@contains?-conn
)
But that gives:
Cannot parse binding, expected (bind-scalar | bind-tuple |
bind-coll | bind-rel)
{:error :parser/binding, :form :thing/other}
Any idea how to give a variadic amount of where clauses? I thought maybe passing a list of key-values as an argument and then using the ...
in datascript query. But not sure how I would do that.
I guess there is a clue to it in the readme with this example:
(d/q '[ :find ?k ?x
:in [[?k [?min ?max]] ...] ?range
:where [(?range ?min ?max) [?x ...]]
[(even? ?x)] ]
{ :a [1 7], :b [2 4] }
range)
But the [?x ...]
clause is hard to understand, let's see if I can understand better after reading relevant test files.