This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-12-07
Channels
- # adventofcode (94)
- # babashka (29)
- # babashka-sci-dev (2)
- # beginners (103)
- # calva (15)
- # cider (17)
- # clj-kondo (62)
- # cljsrn (24)
- # clojars (13)
- # clojure (97)
- # clojure-belgium (3)
- # clojure-berlin (3)
- # clojure-czech (1)
- # clojure-europe (68)
- # clojure-nl (1)
- # clojure-norway (3)
- # clojure-seattle (3)
- # clojure-uk (1)
- # clojurescript (7)
- # community-development (29)
- # conjure (2)
- # cursive (14)
- # data-science (15)
- # emacs (3)
- # graphql (10)
- # gratitude (1)
- # holy-lambda (32)
- # hoplon (21)
- # hyperfiddle (2)
- # jobs (2)
- # joyride (36)
- # lsp (4)
- # meander (13)
- # off-topic (203)
- # pathom (3)
- # polylith (6)
- # re-frame (4)
- # reagent (1)
- # reitit (28)
- # releases (1)
- # shadow-cljs (16)
- # slack-help (2)
- # sql (27)
- # vim (2)
Hi guys, attempting to do a batch delete by keys with jdbc.next to avoid a lot of round tripping to the DB?
Did you look at next.jdbc/execute-batch!
? Do you have a specific question about how to use it?
(jdbc/execute-batch! db "delete from table where key1 = ? and key2 = ?"
data
{:rewriteBatchInserts true})
And db
is...?
Can't infer the SQL type to use for an instance of clojure.lang.PersistentVector. Use setObject() with an explicit Types value to specify the type to use.
@U04V70XH6 IGNORE Me! I got it working. I forgot to source the code that I changed into the batch statement, lol
One thing to watch out for: `rewriteBatchInserts` reWriteBatchedInserts
needs to be on the JDBC connection string (URL) so if you are using a pooled datasource, you need to specify it when that is created, not on operations that use those connections.
And I think it's actually reWriteBatchedInserts
for PostgreSQL, looking at some search results (I do not use PG so the docs are based on what people have told me)
Ah, yes, the docs are correct: :rewriteBatchedStatements
for MySQL and :reWriteBatchedInserts
for PostgreSQL... so it may not matter for PG since you're not doing inserts -- but execute-batch!
should still help for those delete
statements.
@U04V70XH6 would the rewriteBatchInserts go under
:datasourceProperties
for the connection pool ? Using the Hikari poolHow exactly are you creating the connection pool? Are you using the next.jdbc.connection/->pool
or component
calls?
(defrecord Database [db-spec ; configuration
init-fn ; callback to initialize the database
datasource] ; state
component/Lifecycle
(start [this]
(log/info "Starting Database of type " (:dbtype db-spec))
(if datasource
this ; already initialized
(let [database (assoc this :datasource (connection/->pool HikariDataSource db-spec))]
;; set up database if necessary
(log/info "testing db connection")
(.close (jdbc/get-connection (:datasource database))) ;;ensure connection and datasource setup correctly
(log/info "Connection pool established")
(when init-fn
(log/info "Initializing DB")
(init-fn database))
(log/info "Database started")
database)))
(stop [this]
(assoc this :datasource nil))
Yup, that would be the place. You know that next.jdbc.connection/component
will build that for you? https://cljdoc.org/d/com.github.seancorfield/next.jdbc/1.3.847/api/next.jdbc.connection#component
It doesn't have the init-fn
tho'... that's an interesting idea... I could add that as an option to n.j.c/component
🙂