This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-07-12
Channels
- # announcements (1)
- # aws (1)
- # babashka (63)
- # beginners (108)
- # calva (12)
- # cider (6)
- # cljdoc (2)
- # cljsrn (33)
- # clojure (150)
- # clojure-europe (28)
- # clojure-nl (13)
- # clojure-spain (1)
- # clojure-spec (8)
- # clojure-uk (25)
- # clojurescript (16)
- # conjure (7)
- # cursive (7)
- # datomic (15)
- # duct (2)
- # eastwood (2)
- # figwheel (1)
- # figwheel-main (1)
- # fulcro (6)
- # graalvm (1)
- # graalvm-mobile (1)
- # helix (6)
- # honeysql (23)
- # integrant (6)
- # introduce-yourself (4)
- # jobs (10)
- # lsp (132)
- # malli (4)
- # meander (1)
- # membrane (1)
- # off-topic (223)
- # pathom (23)
- # pedestal (3)
- # re-frame (18)
- # reagent (13)
- # releases (1)
- # remote-jobs (2)
- # shadow-cljs (68)
- # tools-deps (217)
- # vim (19)
- # xtdb (79)
Hello, may I know if there is a good way to changed the namespaced keywords (based on the table) to normal keywords in honeysql? Am thinking it is removing the namespace part is better when I pass the resulting sql result to my frontend. I know I can do something like ...
(zipmap (map (comp keyword name)
(keys sql-result)) (vals sql-result))
do i just do that?There might be a better way; but aliases don’t get a namespace. So if you {:select [[[:user/id] :my_id]]}
; it returns :user/id as :my_id
@UUSQHP535 I don't understand the context of this question. What perceived problem are you trying to solve? I've never needed to do anything like this.
@U04V70XH6 I was thinking of renaming/removing the namespace from the keywords. So that my frontend doesn't need to know in which database table the column of data comes from
I'm not sure what that has to do with HoneySQL? You use HoneySQL to generate SQL that you then pass to a JDBC library (by which point namespaced keywords have been processed/removed).
The JDBC library might give you back namespace-qualified keywords but that has nothing to do with HoneySQL.
You can tell the JDBC library to not qualify column names -- but my recommendation would be to allow that and to have a transformation at the boundary where you pass data back to the frontend: I would argue that in general the over-the-wire data you send from the backend to the frontend should be a specific API (that suits the client) and should not just be an exact copy of the data model used inside your backend.
In my handler function, which returns data to the API, I would probably either destructure the data to extract just the fields the API needs (and give them appropriate "API" names) or use a combination of select-keys
and clojure.set/rename-keys
to produce an appropriately named data structure for the client.
This isolates your frontend code from any changes in your data model -- and also allows for your frontend/API to change independently of your data model.
The data structures going back and forth between your API and your client are a good candidate for validation with Spec (using :req-un
/`:opt-un` keys).
oops, yeah you are right, this is a next.JDBC. Was getting things mixed up because was concurrently thinking if i should be renaming it with :as
in sql
does honeysql support this syntax in do-update-set?
;; do update set (docdata_user_id, docdata_client_id, profile, last_login, _updated, login_count) =
;; (:docdata_user_id, :docdata_client_id, excluded.profile, now()::timestamp, now()::timestamp, users.login_count + 1)
@borkdude I don't think you can do a composite set
like that, but you can specify a hash map of columns/values that it will set: :do-update-set {:docdata_user_id :docdata_user_id, :docdata_client_id :docdata_client_id, :profile :excluded.profile, :last_login ..., :_updated ..., :login_count [:+ :users.login_count 1]}
(I'm not quite sure what the best way to write the cast syntax is [:cast [:now] :timestamp]
would probably work)
I don't care about the SQL it generates, as long as it's the thing that's semantically the same
The docs have an example of :do-update-set
with a hash map BTW