Fork me on GitHub
#sql
<
2018-05-25
>
jahson04:05:09

@seancorfield Thanks! I was thinking about execute! but it was night and my head was working badly. Will try it soon,

seancorfield04:05:19

@jahson If you run into any problems, let me know.

seancorfield04:05:38

Support for :return-keys in execute! is a fairly recent addition...

jahson05:05:09

I’m using latest version of clojure.java.jdbc and everything is working perfectly.

dev=> (jdbc/execute! db ["insert into tbl(a, b, c, d, e, f) values (?, ?, ?, '', 0, now()) on duplicate key update id=last_insert_id(id);" 1 123 "#123"] {:return-keys true})
{:generated_key 7} ;; row was created

dev=> (jdbc/execute! db ["insert into tbl(a, b, c, d, e, f) values (?, ?, ?, '', 0, now()) on duplicate key update id=last_insert_id(id);" 1 123 "#123"] {:return-keys true})
{:generated_key 7} ;; duplicate key => last_insert_id

tianshu13:05:08

Hi folks, I'm curious about should I use namespaced keyword with java.jdbc or other sql libraries like hugsql, honeysql. I know there's a way to transform the result and input, I wonder if this is a good idea. It's likely there's no library have built-in support for this.

myguidingstar14:05:13

@doglooksgood Walkable supports namespaced keywords out of the box https://github.com/walkable-server/walkable

myguidingstar14:05:16

behind the scene, Walkable makes queries like this select "column" as "table/column" from "table"

seancorfield15:05:01

@doglooksgood clojure.java.jdbc explicitly supports creation of namespaced keywords via :qualifier and sending in qualified keywords to insert! etc should work out of the box, so I'm not sure I understand your question.

jumar07:05:10

Wow, that's great to know. Do you use them (often)?

seancorfield15:05:40

There aren't any examples of using qualified keywords with insert! in the test suite but there are several examples using :qualifier like this https://github.com/clojure/java.jdbc/blob/master/src/test/clojure/clojure/java/jdbc_test.clj#L998

seancorfield16:05:46

Updated one of the tests to use qualified keywords for table and column names for create-table-ddl and insert-multi! (as well as :qualifier in a query): https://github.com/clojure/java.jdbc/blob/master/src/test/clojure/clojure/java/jdbc_test.clj#L1061