XT2 (possibly noob) question: I have a XTQL query like so:
'(-> (from :log-lines [{:time time :run-id $id} line time])
(order-by {:val time :dir :asc})
(limit $lines)
(offset $offset))
where all the $symbols are supplied via user input and I'm passing them as {:args {:foo bar ...}} to the (xt/q ...) call. I'm easily able to supply all the runtime data in the bindings via args but things like limit and offset seem to explicitly require an integer constant; making it rather inconvenient to write the quoted query. Hopefully there is a better way to write this?Since im doing a massive port of a big thing to XT2 and have just started, will give HoneySQL a shot too!
With xt/template one can pass in symbols from outside of the XTQL query and unquote them to use them in the query:
https://docs.xtdb.com/drivers/clojure/codox/xtdb.api.html#var-template
I'd be inclined to do it as SQL and use HoneySQL to build it:
(-> (from :log-lines)
(where (map= {:time time :run-id id}))
(select :line :time)
(order-by :time)
(limit lines)
(offset offset))
(where id, time, lines, and offset are all local bindings or function args or defs)
I'll be honest that I don't see a lot of benefit to XTQL. I find it a lot harder to read than SQL and the whole passing values as symbols things seems harder to me too.Thanks a lot both for the brilliant suggestions! re XTQL vs SQL, Iβm hoping to use more of the aggregates and joins and some plain Clojure code in the query and was finding XTQL more expressive. I guess Iβve gotten used to reading it from v1 π
Given that v1 and v2 data languages are so different, I'm surprised that you find XTQL similar enough to Datalog...? I'm super-excited that XT2 is fully embracing SQL and I plan to enhance HoneySQL to support their SQL extensions etc.
Yeah I guess I tinkered much more with datalog than SQL via both v1 and Datomic. Itβs datalog like things and using Clojure in the query Iβm more used to than v1 in specific
I like staying in Clojure (or as close to it as possible). Nothing against SQL, but so far I've also mostly used XTQL with XTDB v2.
Well, that's why I use HoneySQL π With XT2 and XTQL, you don't really have the Clojure functions in queries stuff that was available in Datalog / XT1 -- and right now work on XT2 seems very much SQL-first, and that's almost certainly how all the non-Clojure clients for XT2 are going to work because XTQL just isn't natural outside Clojure... esp. with the work being done on PGwire support...
I'll have to take a look π