Fork me on GitHub
#datahike
<
2022-03-02
>
awb9905:03:10

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

awb9914:03:42

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]

awb9914:03:05

This works:

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

awb9914:03:09

But this does not work:

awb9914:03:23

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

awb9914:03:32

It is weird, because this query works:

awb9914:03:54

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

awb9914:03:03

The queries for the status work fine.

awb9914:03:15

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

awb9901:03:57

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.

awb9916:03:51

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

metasoarous18:03:34

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

awb9922:03:14

Not good 🙂 Thanks for the info @U05100J3V

metasoarous23:03:42

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.

kkuehne15:03:26

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 https://cljdoc.org/d/io.replikativ/datahike/0.4.1484/api/datahike.api#q .

🎉 1
metasoarous18:03:45

Fantastic! I stand corrected then (regarding pagination).

awb9903:03:39

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.

awb9903:03:16

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