Fork me on GitHub
#sql
<
2019-12-26
>
fabrao03:12:19

Hello all, how do I use :timeout in execute! ?

fabrao03:12:56

from next.jdbc?

fabrao03:12:11

(execute! connection ["query"] {:timeout 10}) ?

fabrao03:12:56

sorry asking this, but it´s no clear how to use it and I only use execute!

seancorfield04:12:43

@fabrao Yes, :timeout is an option and execute! takes a hash map of options as the third argument.

seancorfield04:12:40

execute! will create a PreparedStatement from the Connection object using the prepare function and will pass the options hash map into prepare -- which will call .setQueryTimeout on the newly-created PreparedStatement.

seancorfield04:12:31

Per https://cljdoc.org/d/seancorfield/next.jdbc/1.0.12/doc/all-the-options#prepared-statements "Any function that creates a PreparedStatement will accept the following options:" (goes on to describe :timeout).

seancorfield04:12:51

I assume the part that wasn't clear to you was that execute! will create a PreparedStatement?

seancorfield05:12:58

That's mentioned at the top of https://cljdoc.org/d/seancorfield/next.jdbc/1.0.12/doc/getting-started/prepared-statements "Under the hood, whenever you ask next.jdbc to execute some SQL it creates a java.sql.PreparedStatement, adds in the parameters you provide, and then calls .execute on it."

seancorfield05:12:44

If you have suggestions for improving the documentation to make that sort of thing clearer, I'd be happy to hear them -- feel free to create an issue https://github.com/seancorfield/next-jdbc/issues or if you want to propose specific changes to the docs via a pull request https://github.com/seancorfield/next-jdbc/pulls that would be great too.

seancorfield05:12:21

@fabrao I've just made these changes to the documentation: https://github.com/seancorfield/next-jdbc/commit/79d2772e14e341fbb85fecee21ea61809d715e90 -- hopefully that clarifies things?

❤️ 4
fabrao13:12:53

@seancorfield that was not clear to me if I have to use option as direct map in execute! or do something with jdbc/prepare and use .setQueryTimeout . But now it´s clean. Many thanks

4