Fork me on GitHub
#honeysql
<
2021-07-02
>
Krishan V09:07:07

What would the DSL look like if my raw SQL were to look like this?

INSERT INTO profiles_to_countries (profile_id, country_id)
SELECT '04d6b414-2163-476d-8d20-91f918f63045', c.id 
FROM countries c 
WHERE c.region = 'Africa'
My select statement returns a list of values which are them inserted in a join table. My incomplete statement is somewhat like this. I am unsure how the c.id bit would translate to the DSL
(->
  (sqlh/insert-into :profiles_to_countries)
  (sqlh/select [(:profiles_id m) ()])
  (sql/format))

Krishan V04:07:13

Thanks! @U04V70XH6. Is it possible to interpolate variables directly into the SQL statement rather than using bindings with HoneySQL? e.g: INSERT INTO profile (name, age) VALUES ("John Doe", "30") instead of INSERT INTO profile (name, age) VALUES (?, ?) My intention is to generate an SQL file which I can use for an up.sql migration script.

Krishan V04:07:45

Nevermind, I just found out about the :inline true option in format Loving this library, thank you so much for making this possible! @U04V70XH6

3