This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-03-20
Channels
- # announcements (1)
- # asami (2)
- # babashka (9)
- # babashka-sci-dev (33)
- # beginners (6)
- # calva (5)
- # cider (1)
- # clj-kondo (2)
- # clojure (79)
- # clojure-dev (8)
- # clojure-europe (1)
- # clojurescript (56)
- # core-logic (1)
- # datalevin (1)
- # emacs (20)
- # funcool (3)
- # holy-lambda (3)
- # honeysql (28)
- # improve-getting-started (11)
- # introduce-yourself (4)
- # lsp (21)
- # off-topic (9)
- # other-languages (5)
- # polylith (3)
- # quil (3)
- # releases (1)
- # rewrite-clj (9)
- # sql (5)
- # tools-deps (29)
- # xtdb (9)
Hi there. I have a question regarding keyword->column conversion in honeysql. I have a Tab
table that has a column called is_protected?
. Naturally, when using honeysql Clojure's keywords are converted into snake case upon formatting, but in this case that won't work because is_protected?
needs to be quoted properly (i.e. "is_protected?"
) otherwise the database will get upset. I've tried :quoted true
but that will ignore conversion all together, which is not what I want. Is there any nice way to be able to quote after conversion has been done? Thanks in advance.
user=> (-> (select :foo) (from :bar) (where [[:raw "is_protected? = true"]]) sql/format)
["SELECT foo FROM bar WHERE (is_protected? = true)"]
user=> (-> (select :foo) (from :bar) (where [[:raw "'is_protected?' = true"]]) sql/format)
["SELECT foo FROM bar WHERE ('is_protected?' = true)"]
@dharrigan Ah I see. Would that also work with insertion?
Yeah it's not a common way to name your column, I just decided to make it for seamless transition between the db and Clojure land
Maybe, I don't know, but maybe, Sean might consider something - a switch perhaps? that if the user so-chooses to enable, that on the column translation on the way in/out, if the data type is boolean to convert the clojure to/from ?
i.e,. if a column name is enabled
and type boolean
, then on the data map on the way out, it might be :table_name/enabled?
as the key.
I think a more general approach would be to have some sort of conversion layer where you can provide a map of from/to keys?
So if you feed it is-protected?
it can be converted into is_protected
and vice versa.
I think you're looking at a more low level solution here, for example, I use next.jdbc which is the one that actually does the querying etc., of the db