honeysql

Discussion of https://github.com/seancorfield/honeysql :slightly_smiling_face:
viesti 2020-11-20T17:20:18.208300Z

humdum, wonder how I can output " around a table name, e.g.

select * from "user"; 

seancorfield 2020-11-20T17:40:06.208700Z

That's :quoting :ansi in the format call.

seancorfield 2020-11-20T17:41:41.209Z

@viesti

user=> (require '[honeysql.core :as h])
nil
user=> (h/format {:select [:*] :from [:user]})
["SELECT * FROM user"]
user=> (h/format {:select [:*] :from [:user]} :quoting :ansi)
["SELECT * FROM \"user\""]
user=> 

viesti 2020-11-20T17:43:11.209600Z

nice, thank you! 🙂

seancorfield 2020-11-20T17:44:44.210400Z

Note: this changes in v2 since ANSI dialect is the default and format requires an options hash map instead of named arguments:

user=> (require '[honey.sql :as h])
nil
user=> (h/format {:select [:*] :from [:user]})
["SELECT * FROM user"]
user=> (h/format {:select [:*] :from [:user]} {:quoted true})
["SELECT * FROM \"user\""]
user=> 

viesti 2020-11-20T17:56:55.210900Z

opts maps sounds like a nice thing

viesti 2020-11-20T18:02:19.214Z

actually, the codebase that I'm working with now uses a schema qualified name, e.g. backend.user , but I was wondering on how to avoid this (would allow moving to another schema etc.), so specifying :quoting in the format calls hasn't been in use in this codebase

seancorfield 2020-11-20T18:04:35.214200Z

user=> (h/format {:select [:*] :from [:backend.user]} :quoting :ansi)
["SELECT * FROM \"backend\".\"user\""]
user=> 

👍 1