This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-08-23
Channels
- # babashka (22)
- # beginners (8)
- # calva (7)
- # clj-kondo (65)
- # cljdoc (9)
- # cljsrn (1)
- # clojure (53)
- # clojure-australia (4)
- # clojure-europe (49)
- # clojure-gamedev (2)
- # clojure-italy (13)
- # clojure-nl (1)
- # clojure-spec (19)
- # clojure-uk (4)
- # clojurescript (48)
- # clojureverse-ops (1)
- # core-async (3)
- # css (2)
- # cursive (15)
- # datomic (6)
- # degree9 (2)
- # depstar (4)
- # emacs (2)
- # find-my-lib (1)
- # fulcro (16)
- # graalvm (11)
- # gratitude (1)
- # honeysql (9)
- # introduce-yourself (2)
- # jobs (1)
- # joker (2)
- # livestream (2)
- # malli (16)
- # nbb (4)
- # news-and-articles (2)
- # off-topic (1)
- # pathom (7)
- # polylith (10)
- # practicalli (1)
- # re-frame (7)
- # reitit (1)
- # releases (3)
- # remote-jobs (1)
- # rewrite-clj (19)
- # shadow-cljs (10)
- # tools-build (1)
- # tools-deps (9)
- # uncomplicate (1)
- # vim (3)
- # xtdb (44)
thanks for the help @seancorfield I have another variation of this problem. If :?path
is a vector and I want to unpack the vector inside my formatter e.g.
;; better syntax for path:
(sql/format {:select [:*]
:from [:honey]
:where [:-> :data :?path]}
{:params {:path ["key1" "key2"]}})
;; => ["SELECT * FROM honey WHERE DATA->?" ["key1" "key2"]] <<<-- wrong
;; desired
;; => ["SELECT * FROM honey WHERE DATA->?->?" "key1" "key2"] <<<-- desired
I have the code for this here https://github.com/wandersoncferreira/honey-ext/blob/07257daffad1b56fb6923b1d420385f1108c3ce7/src/honey_ext/json.clj#L40
does this make sense or I would need necessary to pass the vector elements separated as params? [:-> :data ?:key1 :?key2]
(as this is a path, I thought sending a vector would be better imo)@iagwanderson Bear in mind that, in general, the argument to a formatter can be a completely arbitrary DSL expression and could render to just SQL or to some SQL and an arbitrary number of parameters (because the expression could be arbitrarily complex). I don't think your mental model of how formatters work lines up with reality at the moment 🙂
In the second example here https://github.com/seancorfield/honeysql#extensibility the :a
value could be an arbitrary SQL expression and the only thing that :betwixt
operator guarantees is the "order" that these arbitrary SQL will be placed related to the other 2 parameter values.
Yes, that's why there are three format-expr
calls and then the SQL and the params are assembled into the result:
(let [[sql-a & params-a] (sql/format-expr a)
[sql-b & params-b] (sql/format-expr b)
[sql-c & params-c] (sql/format-expr c)]
got it! leaving the named parameters aside, I am thinking if the approach of the :->
operator is useful or not. I am working a lot with jsonb columns and was exploring some ways to make it more honeyql-like 😃 instead of using raw
calls
I'm not familiar with that operator but it doesn't seem like you need anything custom for it:
dev=> (sql/register-op! :-> :variadic true)
nil
dev=> (sql/format-expr [:-> :data :a :b :c])
["data -> a -> b -> c"]
Is that what you're trying to produce?
Formatters do not have access to named parameters. By design. And that's because any expression in the DSL can expand to SQL with zero or more parameters -- and the parameters vector is only fully known once the entire DSL "statement" has been processed, and the top-level formatter then processes the :params
hash map (to unwrap the placeholders that are put into the parameter slots by the formatters).