This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-01-05
Channels
- # announcements (1)
- # babashka (61)
- # babashka-sci-dev (1)
- # beginners (54)
- # biff (17)
- # cider (4)
- # circleci (1)
- # clj-commons (39)
- # clj-kondo (26)
- # cljdoc (40)
- # clojure (41)
- # clojure-europe (32)
- # clojure-norway (4)
- # clojure-portugal (1)
- # clojure-uk (2)
- # clojurescript (59)
- # clr (69)
- # conjure (7)
- # cursive (22)
- # data-science (16)
- # datalevin (1)
- # datomic (19)
- # docker (31)
- # funcool (1)
- # honeysql (6)
- # hoplon (1)
- # hyperfiddle (41)
- # introduce-yourself (1)
- # juxt (2)
- # leiningen (5)
- # nbb (14)
- # nextjournal (38)
- # off-topic (47)
- # polylith (2)
- # rdf (5)
- # re-frame (4)
- # reitit (27)
- # releases (6)
- # scittle (10)
- # shadow-cljs (24)
- # sql (11)
- # squint (1)
- # tools-build (33)
- # tree-sitter (4)
- # vim (39)
java.jdbc usage/design question: we have a function db/query
which calls jdbc/query
in a try-catch that passes caught exceptions to this function
(defn- handle-exception
[exc]
(throw+
{:type (cond (re-find #"canceling.*statement timeout" (str exc)) ::timeout
(re-find #"duplicate key value violates unique constraint"
(str exc))
::unique-constraint
:else ::unknown)}
exc
(str "Query error: " exc)))
This seems like a bad idea to me, but I'm struggling to articulate exactly why. Do any of y'all use such wrapping functions? Do you manually write the regex logic every time you need it?I had to write a macro that does something like that for PSQL and unique constraints, but I use it rarely and instead fall back to using upserts
We try to use our own wrapper function for executing queries (we pass in a honeysql map) and add extra args etc. we don’t do custom exception handling but it would be a natural place.
I'm just trying out hugsql. I initialize a hikari datasource and can do (jdbc/execute-one! datasource ["select * from table"])
, but hugsql doesn't like my reference a datasource and instead seems to want a db-spec.
we have a Component wrapper that makes it work with both: https://github.com/nomnom-insights/nomnom.utility-belt.sql/blob/master/src/utility_belt/sql/component/connection_pool.clj#L17