Fork me on GitHub
#datomic
<
2021-04-07
>
ayushka05:04:42

I'm having trouble with datomic client q api, where the aggregate function count returns an empty list instead of 0 if no items were found. What am I doing wrong here? Thanks in advance

(d/q '[:find (count ?e)
       :where [?e :migration/name "non_existing_name"]]
     db) ;; => [] instead of [[0]]

ayushka12:04:25

ended up doing count outside the query

(count (flatten (d/q ...etc)))

favila13:04:36

Aggregation functions are not called on empty resultsets

favila13:04:11

The flatten shouldn’t be necessary.

favila13:04:15

if you want to save the bandwidth of returning all items, you can use 0 as a fallback e.g. (or (ffirst result) 0)

ayushka14:04:01

noted, thanks for the tip @U09R86PA4