Fork me on GitHub

I want to search for entities that do NOT have a specific field. Is this possible?


I tried that. And it seems this is not working. This are my datums:

#datahike/Datom [452 :fulfillment/delivery-date #inst "2022-03-01T21:17:18.000-00:00" 536871802 true]
#datahike/Datom [452 :invoice/date #inst "2022-02-25T00:00:00.000-00:00" 536871378 true]
#datahike/Datom [452 :invoice/date-due #inst "2022-03-25T00:00:00.000-00:00" 536871378 true]
#datahike/Datom [452 :invoice/id "b44c84a1-d837-4dc2-bf2c-b13241981834" 536871378 true]
#datahike/Datom [452 :invoice/invoice-number "INV-8036" 536871378 true]
#datahike/Datom [452 :invoice/name "Jon Don / Seattle" 536871378 true]
#datahike/Datom [452 :invoice/paid 0.0 536871378 true]
#datahike/Datom [452 :invoice/reference "766557" 536871378 true]
#datahike/Datom [452 :invoice/status "AUTHORISED" 536871378 true]
#datahike/Datom [452 :invoice/total 232.16 536871378 true]
#datahike/Datom [452 :invoice/type "ACCREC" 536871378 true]


This works:

(def xero-orders-fulfillment-shipping
  '[:find [(pull ?id [* {:tracking/_invoice [:tracking/tag :tracking/number]}]) ...]
    :in $ 
    [?id :invoice/type "ACCREC"]
    [?id :invoice/status ?status]
    [(contains? #{"AUTHORISED" "PAID"} ?status)]
    (not [?id :fulfillment/delivery-date])])


But this does not work:


(def xero-orders-fulfillment-shipping
  '[:find [(pull ?id [* {:tracking/_invoice [:tracking/tag :tracking/number]}]) ...]
    :in $ 
    [?id :invoice/type "ACCREC"]
    [?id :invoice/status ?status]
    [(contains? #{"AUTHORISED" "PAID"} ?status)]
    [(not [?id :fulfillment/delivery-date])]])


It is weird, because this query works:


(def xero-orders-fulfillment-delivered
  '[:find [(pull ?id [* {:tracking/_invoice [:tracking/tag :tracking/number]}]) ...]
    :in $ 
    [?id :invoice/type "ACCREC"]
    [?id :invoice/status ?status]
    [(contains? #{"AUTHORISED" "PAID"} ?status)]
    [?id :fulfillment/delivery-date _]


The queries for the status work fine.


For the not existing tag, I may not put the not into brackets.

Joshua Suskalo21:03:31

isn't the difference that putting it into brackets makes it a predicate to run, and you're calling not on a vector, and vectors are truthy?

Joshua Suskalo21:03:39

so it just always returns false


This might be. I dont know. But I have this in brackets: [(contains? #{"AUTHORISED" "PAID"} ?status)] And this works. I dont quite get it @U5NCUG8NR

Joshua Suskalo01:03:42

That seems like it's an actual predicate, and it's not trying to make a tuple syntax inside an arbitrary piece of syntax. A not around a tuple definition is special syntax specified by datalog, not an expression.


Does datahike support a query where I can sort the items, and then return say a page with the first 20 items ?


No; Sorting and pagination are not supported. You'd have to run the query, and explicitly do this with regular ol clojure code.


Not good 🙂 Thanks for the info @U05100J3V


Yeah; To be fair, this is in following with datomic & datascript (etc), and to some extent makes sense from a relational perspective (you always get a set back, which is inherently unordered). But, it would be nice/convenient, and the team might be open to supporting if you raise an issue.


Right, currently it is not possible because how we query and unify the results from the indices. As for pagination you can do that already if you query with a hashmap. Have a look at the example in the .

🎉 1

Fantastic! I stand corrected then (regarding pagination).


For me unfortunately paging alone without sorting does not make too much sense. I want to display say recently arrived orders. Obviously I am interested the most in those who arrived latest. And in case my page-size is not big enoguht, and I want to go back more, then I go to the next page.


The paging in my view only makes sense, if there is no need for sorting.