Would it be a bad idea to install these settings:
(import '[java.sql Array])
(require '[next.jdbc.result-set :as rs])
(extend-protocol rs/ReadableColumn
Array
(read-column-by-label [^Array v _] (vec (.getArray v)))
(read-column-by-index [^Array v _ _] (vec (.getArray v))))
in babashka-sql-pods?
This would always return a vector if you select an array from a database. I think this is what you want 99% or maybe 100% of the time, but are there any situations where you would rather preserve the array?Note: this doesn't affect any other libraries because pods live in their own process
I could make it so that you would get a (non sql, just normal java) array, but why the heck would anyone want that
This isn't breaking because arrays did not work at all before
Thanks. :duckie:
(testing "inserting an array"
(is (db/execute! db ["create table bar ( bar integer[] );"]))
(is (db/execute! db ["insert into bar values (?);" (into-array [1 2 3])]))
(is (= [#:bar{:bar [1 2 3]}] (db/execute! db ["select * from bar"]))))
@borkdude if you extend the protocols to support json it wouldn't round trip right
like, often what I will do is make it so vectors and maps will write as json
idk if thats relevant
this is about Java arrays, but your point about JSON is something I considering too. So for inserting you would always use a Java array, but in the query result you would get back a vector so round-tripping doesn't work, but does that have to work? For JSON: I think just use Clojure data structures for inserting? And for the result, what to do, also deserialize as Clojure?
For JSON there are more things to consider though: keywordize or not?
This should probably be an option (defaulting to true?)
@borkdude Here are my opinionated translations between Postgres and Clojure. I'm pretty happy with this, with the exception of the enum, which is a horrific kludge... https://github.com/dcj/coerce/blob/develop/src/coerce/jdbc/pg.clj
Nice, thank you
FWIW, YMMV 🙂, your goals are broader than mine were when I wrote this.... but perhaps fodder for thought
Nice work @dcj!
Thanks!, but please note that I stand on the shoulders of others, please refer to the README in that repo for credit to original sources
Is anyone using this https://github.com/impossibl/pgjdbc-ng with next-jdbc
? If so did you encounter any issues? We're going to try it for ourselves just wanted to know if there were any known issues.
@danielglauser I used to test clojure.java.jdbc
with a version of that: https://github.com/clojure/java.jdbc/blob/master/deps.edn#L16 -- I haven't tested it recently (with next.jdbc
).
I don't remember encountering any specific issues but it's been a while.
Thanks Sean! We're about to test it with our system, I'll post back here if we encounter any issues.