Fork me on GitHub
#sql
<
2020-07-22
>
seancorfield20:07:49

@sofra https://github.com/seancorfield/next-jdbc/commit/734c4bfada3b9242496e88ca76eaf62298764b78 -- develop branch now supports :return-generated-keys true on execute-batch! to attempt to return all the generated keys for each batch.

sofra06:07:05

@seancorfield I have this a go, works well 🙂

sofra06:07:13

I notice you are creating a connection using the PreparedStatement, will that play nicely with using execute-batch! in a transaction?

sofra06:07:27

(jdbc/with-transaction 
      [tx datasource]                       
      (prepare/execute-batch! (jdbc/prepare tx [statement] {:return-keys true})
                              rows
                              {:batch-size            100
                               :return-generated-keys true
                               :builder-fn rs/as-unqualified-maps}))

seancorfield14:07:47

@sofra Remember that you need to close any PS you create, so use (with-open [ps (jdbc/prepare tx ...)] (prepare/execute-batch! ps ...))

seancorfield14:07:07

"creating a connection using the PreparedStatement" -- no, calling .getConnection on a PreparedStatement simply returns the Connection it was created from, i.e., tx in your example code.

sofra23:07:23

great thanks so much @seancorfield 🙏

sofra23:07:03

@seancorfield thanks, I will give it a spin later today :thumbsup:

seancorfield23:07:15

I've added a SQLite section to the Tips &amp; Tricks page now (in docs on develop -- will be on http://clj-doc.org with the next release) that talks about how SQLite is the only database that treats bool and bit as 0 or 1 values, instead of as Boolean like every other (sane) database. The tips show how to write a builder function that does the conversion for you, as well as suggesting how to handle it in a reducing function over plan (manually!). https://github.com/seancorfield/next-jdbc/blob/develop/doc/tips-and-tricks.md#sqlite