So I'm trying to use the entity id to retrieve items recently transacted to the datomic database.
However, when invoking (get-post-by-eid zzzzzzzzz) I get an error
IllegalArgumentExceptionInfo :db.error/too-few-inputs Query expected 2 inputs but received 1 datomic.error/arg (error.clj:57)
(defn get-post-by-eid [eid]
(d/q '[:find ?title ?content ?tags ?eid
:in $ ?eid
:where
[?eid post/title ?title]
[?eid post/content ?content]
[?eid post/tag ?tags]] (d/db conn)))
So I figure my query string must be malformed..
I've been looking at http://www.learndatalogtoday.org/chapter/3 but still not sure where I'm going astray.
Any help is appreciated (=
Your :in
clause specifies that you're expecting two data sources to be passed to the q
function. $ ?eid
means that you're saying you're going to pass in a database (bound to $
), and some other value, which will be bound to ?eid
.
Like this:
(defn get-post-by-eid [eid]
(d/q '[:find ?title ?content ?tags ?eid
:in $ ?eid
:where
[?eid post/title ?title]
[?eid post/content ?content]
[?eid post/tag ?tags]]
(d/db conn)
eid))
Otherwise, there's no way for your eid
parameter to actually get "into" the query. You have to pass it explicitly, there's no magic there.