Fork me on GitHub
#xtdb
<
2023-02-23
>
jmerrifield00:02:30

Is there any way to control the order of a relation within a pull query? e.g. given the following:

(xt/pull 
  (xt/db node)
  '[:xt/id 
    {(:order/_user {:limit 2}) [:xt/id :created]}]
  {:user/id ""})
I can limit the number of customer orders returned, but could I achieve something like (:order/_user {:limit 2 :order-by [:created :desc]})?

phill01:02:53

I have very much wished to paste a Datalog filter in there, too.

dvingo01:02:33

I have a version of pull queries implemented here using subscriptions: https://github.com/matterandvoid-space/subscriptions/blob/mainline/docs/eql_queries.md which has support for XTDB queries. The implementation already supports using callbacks to dynamically determine a recursion limit and has :xform support but only for leaf attributes currently. The ability to add filtering, ordering, and limiting of collection-valued attributes should be straight forward. If you're interested in that feel free to create an issue :)

nice 2
refset11:02:33

> is there any way to control the order of a relation within a pull query? As per the other replies you can't do anything quite that sophisticated as things stand today. There might be a way to extend/fork https://github.com/xtdb/xtdb/blob/master/core/src/xtdb/pull.clj with a little bit more functionality like this without too much trouble :thinking_face:

Michael W22:02:10

I'm having an issue using xtdb-http-client. I have setup a scratch enviroment:

(ns xtdb-remote.xtdb-remote
  "Testing xtdb remote"
  (:require [xtdb.api :as xt]))

(def db (xt/new-api-client ""))

(xt/q (xt/db db)
         `{:find [e]
           :where [[e :xt/id]]})
; => #{[]}
The query I get that returns an empty set:
{:query-id "633b1a80-6d74-497d-b4e4-c402723d585e",
  :started-at #inst "2023-02-23T21:52:40.541-00:00",
  :finished-at #inst "2023-02-23T21:52:40.543-00:00",
  :status :completed,
  :query {:find [xtdb-remote.xtdb-remote/e], :where [[xtdb-remote.xtdb-remote/e :xt/id]]},
  :error nil}
But the same query run from the xtdb web console which works:
{:query-id "153cbad2-b753-4e25-bd0a-bec86a69d6aa",
  :started-at #inst "2023-02-23T21:26:29.325-00:00",
  :finished-at #inst "2023-02-23T21:26:29.326-00:00",
  :status :completed,
  :query {:find [e], :where [[e :xt/id]]},
  :error nil}
How can I avoid the namespacing of the query variables using a remote node? Is there an example of using xt/q for http remote access? Every example of xt/q I can find assumes you have the app and the db co-located.

refset22:02:28

Hey @UAB2NMK25 we generally https://docs.xtdb.com/language-reference/1.23.0/datalog-queries/#_quoting against using syntax quoting with ` as it introduces namespaces to the symbols. See also https://github.com/brandonbloom/backtick (I haven't tried it) and this previous discussion https://app.slack.com/client/T03RZGPFR/CG3AM2F7V

refset22:02:09

I'd normally stick to using regular ' quoting

Michael W22:02:25

I knew I was missing something simple, I manually typed it out and thought it was the backtick, not the '. Thanks for the help.

refset22:02:57

Ahh, no worries, glad I could help 🙂