Fork me on GitHub

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


Thanks for your advice! Let me try to implement what you explained


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)


so set (x,y,z) = (foo,bar,baz)?


I'm trying to convert a hugsql query


@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]}


oh that's equally good


(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


yeah, I can always do a :raw for that as well


The docs have an example of :do-update-set with a hash map BTW