This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-11-07
Channels
- # announcements (37)
- # babashka (28)
- # beginners (104)
- # calva (28)
- # cider (32)
- # clj-kondo (35)
- # cljs-dev (4)
- # cljsrn (3)
- # clojure (35)
- # clojure-conj (4)
- # clojure-dev (57)
- # clojure-europe (4)
- # clojure-france (6)
- # clojure-gamedev (1)
- # clojure-germany (1)
- # clojure-hamburg (2)
- # clojure-italy (7)
- # clojure-nl (4)
- # clojure-spec (9)
- # clojure-uk (11)
- # clojuredesign-podcast (2)
- # clojurescript (36)
- # clojurex (48)
- # core-async (6)
- # cursive (12)
- # data-science (1)
- # datomic (21)
- # defnpodcast (7)
- # duct (1)
- # events (1)
- # fulcro (56)
- # graalvm (30)
- # graphql (5)
- # jobs (1)
- # joker (21)
- # keechma (1)
- # leiningen (4)
- # off-topic (109)
- # parinfer (20)
- # pathom (27)
- # re-frame (4)
- # shadow-cljs (80)
- # spacemacs (18)
- # sql (32)
- # testing (2)
- # tools-deps (32)
- # vim (20)
@seancorfield is there a decent way to share connection configuration between stuff that relies on clj.j.jdbc and next?
typical example: we have a migration lib relying on ragtime, which uses the former and app that might use the later, with various flavors of db specs (depending on test suites, various prod/staging setups and so on)
@mpenet yes and it is hinted at in the migration guide : use {:datasource my-ds}
as your db-spec -- for c.j.j. use that as-is, for next.jdbc
use (:datasource db-spec)
That's what we're using at work. With a c3p0 pooled datasource.
{:insert-into :taxonomy, :columns [:style :category :department :personas], :values [["a" "b" "c" "{\"a\",\"b\"}"]]}
This fails with
1. Unhandled org.postgresql.util.PSQLException ERROR: column "personas" is of type text[] but expression is of type character varying Hint: You will need to rewrite or cast the expression. Position: 82 QueryExecutorImpl.java: 2284 org.postgresql.core.v3.QueryExecutorImpl/receiveErrorResponse QueryExecutorImpl.java: 2003 org.postgresql.core.v3.QueryExecutorImpl/processResults QueryExecutorImpl.java: 200 org.postgresql.core.v3.QueryExecutorImpl/execute PgStatement.java: 424 org.postgresql.jdbc.PgStatement/execute
This seems like a bug. next.jdbc should be smart enough to know :personas is of type text[] and not a varchar. Its probably calling setString on the prepareStatement but should be calling something like setObject. Is there a way around this?next.jdbc
calls .setObject
Both clojure.java.jdbc
and next.jdbc
leave it entirely up to the database driver to figure out types and coercions.
You might want to check what honeysql
produces for that data structure and see what is actually being passed into next.jdbc
thanks for responding. It generates this vector
["INSERT INTO taxonomy (style, category, department, personas) VALUES (?, ?, ?, ?)" "ha4" "b" "c" "{\"a\",\"b\"}"]
So next.jdbc
is just going to call .setObject
and pass in those strings, per this code
(extend-protocol SettableParameter
Object
(set-parameter [v ^PreparedStatement s ^long i]
(.setObject s i v))
nil
(set-parameter [_ ^PreparedStatement s ^long i]
(.setObject s i nil)))
set-parameter
is called for each of those in turn.
hmm... so why is the type not matching? it seems to be treating personas as a varchar
is there a way to force honeySQL to not generate prepare statement but generate raw SQL string instead?
HoneySQL produces data structures.
clojure.java.jdbc and next.jdbc create prepared statements.
I think you mean: is there a way to force HoneySQL to inline parameter values?
honeysql.types/inline
will do that -- but be warned that it knows nothing about SQL datatypes so it will perform a purely textual substitution which is almost certainly not what you want in most cases.
(def st-point-sql->lat-lng
(sql/raw (str "ST_Y(location::geometry) lat, ST_X(location::geometry) lng")))
(note: honeysql.core/raw
is an alias for honeysql.types/raw
)