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]]
ended up doing count outside the query
(count (flatten (d/q ...etc)))
Aggregation functions are not called on empty resultsets
The flatten shouldn’t be necessary.
if you want to save the bandwidth of returning all items, you can use 0 as a fallback e.g. (or (ffirst result) 0)
noted, thanks for the tip @favila