This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-27
Channels
- # aws (19)
- # babashka (47)
- # beginners (111)
- # boot (3)
- # bristol-clojurians (3)
- # chlorine-clover (2)
- # cider (13)
- # cljs-dev (8)
- # clojure (143)
- # clojure-europe (11)
- # clojure-germany (10)
- # clojure-italy (3)
- # clojure-losangeles (1)
- # clojure-nl (1)
- # clojure-spec (6)
- # clojure-survey (3)
- # clojure-uk (42)
- # clojurescript (229)
- # conjure (131)
- # cursive (21)
- # data-science (18)
- # datomic (4)
- # emacs (21)
- # events (2)
- # figwheel-main (12)
- # fulcro (18)
- # graalvm (1)
- # hoplon (40)
- # jobs (1)
- # joker (17)
- # kaocha (1)
- # lambdaisland (1)
- # off-topic (19)
- # rdf (7)
- # re-frame (31)
- # reagent (26)
- # reitit (20)
- # rum (4)
- # shadow-cljs (106)
- # sql (17)
- # testing (5)
- # vim (2)
Hi. I added postgres support via JDBC to babashka: https://github.com/borkdude/babashka/#jdbc I'm currently testing this with a Docker container locally. But I saw that next.jdbc itself tests with a library called "embedded postgres". How does this library work? Does it mock postgres, or does it really include it? Can it also be used to create something like sqlite, so beyond testing?
It's almost full-blown PostgreSQL just as an embedded server.
"The JAR file contains bundled version of Postgres. You can pass different Postgres version by implementing PgBinaryResolver
."
(I don't think it has any persistence options, but I didn't dig very deep)
thanks. they explicitly mention "for testing" so that kind of hints at "don't use for anything serious" like a replacement for sqlite
Hi. I'm looking for a way to automatically convert Clojure vector types to array of some type so that I can inject the data to pg database. I'm using next.jdbc and I cannot find the same parameters as in clojure.jdbc which would allow it. Any hints?
hi @karol.wojcik , in this documentation page https://github.com/seancorfield/next-jdbc/blob/master/doc/tips-and-tricks.md there is a snippet about converting clojure map to json/jsonb data types
it might be very similar with what you are trying to achieve if I understood correctly
@karol.wojcik I have this function in my codebase:
(defn pg-array
[conn v]
(.createArrayOf ^java.sql.Connection (:connection conn) "text" (into-array String v)))
@iagwanderson don't know. I found it a little weird that this function needs a connection, but maybe it needs to get some platform specific information via the connection to produce the array. Not sure if the protocols in next.jdbc support that
I looked into the code of the clj-postgresql and they have the conversion there through protocols. Would be like this following the examples in next.jdbc tips and tricks page:
(extend-protocol prepare/SettableParameter
clojure.lang.IPersistentVector
(set-parameter [v ^PreparedStatement s ^long i]
(let [conn (.getConnection s)
meta (.getParameterMetaData s)
type-name (.getParameterTypeName meta i)]
(if-let [elem-type (when type-name (second (re-find #"^_(.*)" type-name)))]
(.setObject s i (.createArrayOf conn elem-type (to-array v)))
(.setObject s i (vec->parameter v type-name))))))
@borkdude the conn is there yet 馃檪do any one you use embedded postgres for testing btw? (https://clojurians.slack.com/archives/C1Q164V29/p1587981027349200)
@iagwanderson @borkdude Thanks! Works like a charm!
@karol.wojcik It sounds like you didn't find the answer in the next.jdbc
docs? Here's the section in Getting Started that talks about working with additional data types https://cljdoc.org/d/seancorfield/next.jdbc/1.0.424/doc/getting-started#working-with-additional-data-types
That links to the docs for extending how parameters are set (data going into the database) and how data is read from the DB.