This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-02-21
Channels
- # announcements (7)
- # babashka (16)
- # beginners (174)
- # biff (7)
- # calva (20)
- # cider (3)
- # clerk (6)
- # cljsrn (4)
- # clojure (98)
- # clojure-europe (57)
- # clojure-italy (3)
- # clojure-nl (1)
- # clojure-portugal (1)
- # clojure-spec (15)
- # clojure-uk (7)
- # code-reviews (3)
- # cursive (23)
- # data-science (1)
- # datomic (26)
- # dev-tooling (2)
- # emacs (5)
- # figwheel-main (4)
- # fulcro (3)
- # honeysql (20)
- # hyperfiddle (20)
- # malli (8)
- # membrane (31)
- # nextjournal (5)
- # pathom (1)
- # polylith (20)
- # re-frame (14)
- # reitit (8)
- # releases (2)
- # shadow-cljs (50)
- # specter (2)
- # sql (22)
- # xtdb (5)
Is there are way to quote a field or column only in special edge cases? Say I have a quote-for-safety?
fn that returns a bool if a word contains certain special characters.
I suppose I could register a new dialect and create a new :quote
fn that only quotes conditionally.
Alternatively, is there any way to map onto the just the keywords and columns of a honeysql expression?
@U0ZCYC77T Can you explain what problem you are trying to solve? Or is this just a preference in terms of the generated SQL?
@U04V70XH6 Here's the specific problem I'm running into:
; I want this quoting behavior, but with :sqlserver quotes
(sql/format {:select [:some##field :another-field]})
;; => ["SELECT \"some##field\", another_field"]
;;
;; passing a dialect quotes everything
(sql/format {:select [:some##field :another-field]} {:dialect :sqlserver})
;; => ["SELECT [some##field], [another-field]"]
;;
;; turning quoting off passes the first field unquoted
(sql/format {:select [:some##field :another-field]} {:dialect :sqlserver :quoted false})
;; => ["SELECT some##field, another_field"]
using com.github.seancorfield/honeysql {:mvn/version "2.4.969"}
Right, but what problem are you trying to solve? Quoting all the fields is not a problem in itself.
That's why I asked if this is just preference on your part?
You can set the (default) dialect globally -- is that what you're asking about?
https://cljdoc.org/d/com.github.seancorfield/honeysql/2.4.980/api/honey.sql#set-dialect!
Was that the answer? You wanted the default dialect to be SQL Server, rather than ANSI?
Oh, sorry. I'm migrating a codebase from HoneySQL 1 -> 2, was just trying to match the existing behavior. I'm actually not sure if quoting everything will cause a problem in our case, I'll try that.
And, I just figured out what I needed:
(sql/format {:select [:some##field :another-field]} {:dialect :sqlserver})
;; => ["SELECT [some##field], [another-field]"]
;;
(sql/format {:select [:some##field :another-field]} {:dialect :sqlserver :quoted nil})
;; => ["SELECT [some##field], another_field"]
:quoted nil
restores the default quoting strategy (only quoting unusual entity names)
Many thanks @U04V70XH6
You have multiple DB dialects in play? Else you could just set one as the global default:
user=> (require '[honey.sql :as h])
nil
user=> (h/set-dialect! :sqlserver)
nil
user=> (h/format {:select [:some##field :another-field]})
["SELECT [some##field], another_field"]
user=>
I'll create an issue to review the docs around the :dialect
option and make sure it's clear that you can explicitly use the "default quoting" via :quoted nil
If you want to send a PR for it, that would be great since I may not get to it for a few weeks.