I believe it was on the clojure-docs page (linked from the
clojure.java.jdbc readme) where they talk about managing your own
connection.
The more idiomatic way may be to wrap the whole thing in some transaction
fn or macro. Sorry I'm not familiar with the API. A lot of vars are
deprecated, but the
Actually, re-reading the jdbc/query doc
http://clojure.github.io/java.jdbc/#clojure.java.jdbc/query
I can't find any reference to this ":connection" keyword param.. may I ask
where you got it from?
On Wednesday, October 2, 2013 9:50:13 AM UTC-4, Christian Jauvin wrote:
>
> Ah finally, thanks
Ah finally, thanks John, the "with-open" pattern was indeed the missing
piece: it works!
Just to summarize, here's what works for me:
(extend-type org.postgresql.jdbc4.Jdbc4Array
json/JSONWriter
(-write [o out]
(json/-write (.getArray o) out)))
; plus any other additional required custo
I don't use clojure.java.jdbc, so this may be non-idiomatic or just wrong,
but have you tried something like
(with-open [connection (jdbc/db-connection *db*)]
(json/write-str
(jdbc/query {:connection connection}
["SELECT * FROM..."])))
On Tue, Oct 1, 2013 at 8:13 PM, Christian Jauvi
Hi Philippe,
The Jdbc4Array that's causing me trouble is not the "outer" one, returned
from jdbc/query: that one seems to be properly handled by json/write-str.
The problem happens with a Postgres table containing a text[] column:
create table something (
something_id serial primary key,
Hi,
You probably need to realize your query using (doall (jdbc/query ...))
Also, I was wondering, depending on your needs, you could convert
Jdbc4Arrayinto a native type (vector ?) as a post-processing function
of your query
and forget about registering JSON writers.
On Tue, Oct 1, 2013 at 9:0
Hi Roman,
This approach works for java.sql.Timestamp, which was another type for
which a JSON writer wasn't defined in my case.
For org.postgresql.jdbc4.Jdbc4Array however, there's something missing,
because I get:
*org.postgresql.util.PSQLException: This connection has been closed.*
As t
I think you need to implement the JSONWriter protocol for the
Jdbc4Array class, and possibly for the datatypes that are in the
array. This for example makes the json library aware of
java.util.Date classes.
(extend-type java.util.Date
JSONWriter
(-write [date out]
(-write (str date) out))