This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-01-25
Channels
- # announcements (3)
- # asami (63)
- # babashka (5)
- # babashka-sci-dev (32)
- # beginners (56)
- # calva (2)
- # cider (28)
- # clj-commons (9)
- # clj-kondo (16)
- # cljdoc (41)
- # cljs-dev (19)
- # clojure (67)
- # clojure-europe (15)
- # clojure-nl (1)
- # clojure-poland (1)
- # clojure-uk (2)
- # clojurescript (27)
- # community-development (10)
- # data-science (2)
- # datascript (8)
- # datomic (21)
- # events (3)
- # fulcro (54)
- # graalvm (18)
- # introduce-yourself (2)
- # juxt (3)
- # lsp (6)
- # music (1)
- # nextjournal (8)
- # off-topic (44)
- # omni-trace (1)
- # reitit (13)
- # releases (3)
- # rewrite-clj (4)
- # shadow-cljs (10)
- # spacemacs (6)
- # sql (12)
- # tools-build (17)
- # tools-deps (3)
- # web-security (1)
Seems like I can set it a java.sql.conneciton level, but how to achieve that per execute-one!
call? Ideally, if the opts parameter supports it then it would be perfect.
(defn plan-and-stream
"Plan And Stream takes control of the entire connection in order to fetch a large amount
of data as a streaming result that is reduced by the callee - it doesn't use a connection
pool as it needs to customise the connection to support streaming."
([sql app-config] (plan-and-stream sql app-config {:builder-fn rs/as-unqualified-kebab-maps}))
([sql app-config opts]
(log/tracef "Executing JDBC '%s'." sql)
(try
(let [{{:keys [txi-db]} :secrets} app-config
{:keys [username]} txi-db
datasource (jdbc/get-datasource (merge txi-db {:user username :auto-commit false :read-only true}))]
(jdbc/plan datasource sql (merge opts {:fetch-size 5000 :concurrency :read-only :cursors :close :result-type :forward-only})))
(catch Exception e
(log/error e)
(throw e)))))
FYI: whether that really sets a connection to read-only is database-specific -- so don't rely on it for security. You're better off setting up credentials on the database that restrict the operations you can do, e.g., only SELECT
statements.
👍 2