Fork me on GitHub
#sql
<
2022-09-12
>
bhaim12308:09:05

Hi Starting to understand how to use clojure.java.jdbc I’m not sure and would like to get some help. If I only use jdbc/query, does it close the connection once done? or do I need to close it by using with-db-connection` ?

seancorfield08:09:44

It depends what you pass it as an argument. If you pass it a db-spec that contains an open connection, it will use it and not close it. If you pass it some other db-spec, it will create a connection from it, use it, and then close it.

bhaim12309:09:07

Thanks @U04V70XH6 I’m/we are passing clj-postgresql.core/pool so it means it closes it, right?

seancorfield09:09:29

If you are passing a connection pooled data source, each operation will get a connection from the pool and then "close" it, returning it to the pool.

seancorfield09:09:05

The pool manages the actual open/close of the connections.

Jérémie Salvucci15:09:40

Hi, when I read this https://corfield.org/blog/2020/10/25/next-jdbc/, I understand that if I install the library camel-snake-kebab, result-set keys should be automatically converted to kebab case if csk is in the classpath. I'm using next.jdbc version 1.2.659 and this does seem to be the case. I just perform an execute-one! with a select (as simple as possible) and I keep getting snake case keys. Did I miss something?

dpsutton15:09:33

I think the answer is in this https://github.com/seancorfield/next-jdbc/blob/v1.1.610/doc/result-set-builders.md . > If you have https://clj-commons.org/camel-snake-kebab/ on your classpath, two additional builders will be available: as-kebab-maps and as-unqualified-kebab-maps which use the ->kebab-case function from that library with as-modified-maps and as-unqualified-modified-maps respectively. This talks about builders being available, not that they are used automatically. And consider your situation. If you upgraded a library and it added camel-snake-kebab to the classpath then the results of database operations would change with no code change on your behalf. This would make it treacherous to use next.jdbc since you could not reliably predict what the column names of your own data would be

Jérémie Salvucci15:09:42

🙂 definitely true, thank you!

seancorfield17:09:47

The blog post talks about the builders becoming "available" if CSK is on the class path -- sounds like I should make the docs clearer about how to use them, if CSK is on the class path?

dpsutton17:09:51

An example usage would probably go a long way in this instance

seancorfield18:09:47

Hah, I'd forgotten that next.jdbc depends on CSK itself, so those builders are always available now -- you just have to use the appropriate options and/or builders! Still, definitely needs a docs update -- and that blog post needs to be updated too I think.