Fork me on GitHub
#honeysql
<
2022-01-27
>
Jakub Holý (HolyJak)14:01:38

Hi! Is there a way to force (values [{:id 1, :valid true}]) to generate "... values(?,?)" instead of "... values(?,TRUE)" ? I have been reading the docs and code but could not figure it out 🙏

seancorfield19:01:46

That's what :lift is for:

dev=> (sql/format (h/values [{:id 1 :value true}]))
["(id, value) VALUES (?, TRUE)" 1]
dev=> (sql/format (h/values [{:id 1 :value [:lift true]}]))
["(id, value) VALUES (?, ?)" 1 true]
dev=> 
https://cljdoc.org/d/com.github.seancorfield/honeysql/2.2.858/doc/getting-started/sql-special-syntax-#lift

🙏 1
Jakub Holý (HolyJak)19:01:10

Thanks a lot! I believed I saw something like that in the docs when I first read them but when I was searching them I obviously failed to find the right search terms / look at the right place 😔

rafaeldelboni20:01:08

Hey hello, does anybody knows if is possible to reproduce this in honeysql?

ALTER TABLE distributors ADD CONSTRAINT distfk FOREIGN KEY (address) REFERENCES addresses (address);

seancorfield22:01:10

DDL is often very database-specific and hard to design a DSL for that works predictably so I'm open to adding support where there is ANSI-standard syntax but for a lot of DDL, it's just not worth going through HoneySQL, IMO.

rafaeldelboni11:01:03

Makes sense, thanks

Max22:01:59

I’m having a little trouble getting sql functions working with honeysql. Taking this example directly out of the readme:

(-> {:select [[[:max :id]]], :from [:foo]} sql/format)
I’m supposed to get ["SELECT MAX(id) FROM foo"] but instead I get an exception:
Execution error (AssertionError) at honeysql.format/seq->sql (format.cljc:385).
Assert failed: Alias should have two parts[[:max :id]]
Are the docs out of date; is there a newer way to call functions? EDIT: facepalm I’m using an older version of honeysql from before that syntax was introduced. Ignore me!