Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing a database function in a datomic query
    primarykey
    data
    text
    <p>I'm trying to do an 'outer join' in Datomic via the REST API. From <a href="https://github.com/Datomic/day-of-datomic/blob/master/tutorial/social_news.clj" rel="noreferrer">https://github.com/Datomic/day-of-datomic/blob/master/tutorial/social_news.clj</a> I have taken the final example:</p> <pre class="lang-clj prettyprint-override"><code>(defn maybe "Returns the set of attr for e, or nil if e does not possess any values for attr." [db e attr] (seq (map :a (d/datoms db :eavt e attr)))) ;; find all users (q '[:find ?e ?upvote :where [?e :user/email] [(user/maybe $ ?e :user/upVotes) ?upvote]] (db conn)) </code></pre> <p>I inserted the maybe function into my database, and it can be queried thus:</p> <pre><code>[:find ?n ?v :in $ :where [?e ?a ?v] [?a :db/ident :db/fn] [?e :db/ident ?n]] </code></pre> <p>returns</p> <pre><code>:maybe #db/fn{:code "(seq (map :a (d/datoms db :eavt e attr)))", :params [db e attr], :requires [], :imports [], :lang :clojure} </code></pre> <p>However, I am unable to work out how to call the function in a query. I have an <code>:data/user</code> attribute on some transactions, which I want to get the value for where it exists. Here's the query I'm trying to run; I would like <code>:maybe</code> to be the database function defined above.</p> <pre><code>[:find ?attr ?v ?when ?who :where [17592186045423 ?a ?v ?tx true] [?a :db/ident ?attr] [(:maybe $ ?tx :data/user) ?who] [?tx :db/txInstant ?when]] </code></pre> <p>I'm pretty sure I'm missing something pretty obvious, but I've been stuck on this for a day now. Thanks for any help!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload