Ah well. If you're set on using honeysql for ddl, you could probably adapt the definitions from postgres.
I’ll take a look. Thank you!
@aviflax Outside of the tests in clojure.java.jdbc
, I've never used the DDL helpers -- they just don't add enough.
I don't use them, either. I tend to put ddl in raw sql migration files.
@codonnell Yeah, that's the route we've gone at work, so it's easier to roll a database up for testing to a specific "version".
That makes sense. Thanks!
FWIW, I was just hoping to find some kind of “standardized” way to represent a create table
statement as a data structure rather than as a string, because I am working on a function that will eventually return something that has generated create table
statement in its metadata, and I want to be able to write equality checks in my tests without worrying about string formatting.
I whipped this up on the fly, thinking this might work:
[:create-table
"technologies"
"name varchar(255) not null primary key"
"links-main text"]
But my SQL is so rusty I don’t have much confidence in something so simple being actually viable. 😅I would probably use a hash map: {:create-table :technologies :columns ["name varchar(255) not null primary key", "links_main text"]}
then you can (clojure.string/join ", " ...)
on the columns and then it's just (str "CREATE TABLE" (:create-table data) "(" column-string ")")
I like that. More forwards-compatible. Thanks!
Hello. I'm trying to create a new row, and return the generated primary key (or complete row).
(-> (insert-into :person)
(values [{:name "foo"}])
(sql/format)
(->> (jdbc/execute! *database*)))
This inserts the row as expected, but returns (1)
instead of the new row. Is there any way I can get the primary key? I also saw that there was a jdbc/insert!
, but this takes a map instead of an SQL string. Meaning I can't use honeysql with this. Any tips?you can use 'returning id' clause at the end of the insert if your db implements it
Ah ok, I also need to use jdbc/query
instead of jdbc/execute!
if I want it to return data
Use :return-keys true
(As an option passed to execute!