Fork me on GitHub
#xtdb
<
2023-05-28
>
jussi15:05:13

Is it possible to define a pull query that returns two documents if both exists and either one if only other exists? I might have both documents readily available or not, ie. result missing. I could query them separately of course, but having them in a single query would be nice.

(xt/q (xt/db db) ;; returns nil IF r does not exist
        '{:find [(pull r [*])
                 (pull e [*])]
          :where [[e :xt/id id]
                  [e :expense/type type]
                  [r :result/e e]]
          :in [[type ...] id]}
        valid-types id)

jussi15:05:57

Docs do state that > The :where section of a query limits the combinations of possible results by satisfying all clauses and rules in the supplied vector against the database (and any :in relations). If it satisfies all clauses, I guess my wish won't happen

jussi07:05:19

Hmm, maybe drop the clause from where and try reverse pull in find :thinking_face:

jussi08:05:27

Yes, that does work as I wanted. Problem solved 🙂

🙌 2
phill21:05:33

A product of many delights, sure... but free only "as in beer". To use closed-source, in an ecosystem where a lot of stuff is open-source, is a decision that should be taken, with great care, by the end-user and not by an easy "starter" app.

👍 8
hifumi12320:05:40

I've personally found XTDB way easier to set up than Datomic. Even if we focus on in-memory (which is his use case), XTDB is as simple as adding 1 dependency then getting a node with (xt/start-node {})

☝️ 5