This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-02-01
Channels
- # announcements (11)
- # babashka (71)
- # beginners (34)
- # calva (25)
- # chlorine-clover (38)
- # cider (13)
- # clj-kondo (1)
- # cljsrn (2)
- # clojure (40)
- # clojure-australia (4)
- # clojure-europe (16)
- # clojure-france (3)
- # clojure-nl (4)
- # clojure-uk (16)
- # clojurescript (27)
- # conjure (2)
- # core-async (41)
- # core-logic (3)
- # cursive (1)
- # data-science (1)
- # datomic (16)
- # depstar (19)
- # emacs (7)
- # fulcro (33)
- # graalvm (4)
- # honeysql (20)
- # hugsql (4)
- # jobs (1)
- # juxt (4)
- # off-topic (48)
- # pathom (41)
- # reagent (9)
- # reitit (19)
- # remote-jobs (1)
- # shadow-cljs (20)
- # startup-in-a-month (2)
- # tools-deps (29)
- # vim (3)
- # xtdb (30)
I ended up with this monstrosity...I am still wondering if I am missing a better way here:
(defn append-files
[db-spec-or-tx files]
(doseq [file files]
(let [{:keys [name mime-type byte-size content]} file
generate-sqlvec (-> sqlvecs :append-file-blob-sqlvec :fn)
;; For BYTEA, we need to use PreparedStatement.setBinaryStream.
;; Note that you *must* pass the (possibly pre-computed) correct stream size. See:
;;
;;
;; Additionally, it would be too invasive too extend all InputStreams, next.jdbc might
;; have a better solution to this problem.
query (->> file (generate-sqlvec) first)
prepared-statement (jdbc/prepare-statement (jdbc/get-connection db-spec-or-tx) query)]
(jdbc/query db-spec-or-tx
;; the order needs to match query VALUES
(doto ^PreparedStatement prepared-statement
(.setString (int 1) ^String name)
(.setString (int 2) ^String mime-type)
(.setInt (int 3) ^int byte-size)
(.setBinaryStream (int 4) ^InputStream content ^int byte-size))))))
@richiardiandrea That's with clojure.java.jdbc
?
I would expect this to be a lot easier with next.jdbc
which has a whole namespace of coercion functions to influence how parameters are set (`next.jdbc.types`).
👍 3
yeah I was thinking about the move, but I am inheriting a code base and I am not yet ready for a port...I definitely am planning to do that though