This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-10-11
Channels
- # announcements (4)
- # babashka (50)
- # beginners (45)
- # cider (12)
- # clara (1)
- # clj-commons (6)
- # clj-kondo (3)
- # cljdoc (3)
- # cljs-dev (44)
- # clojure (19)
- # clojure-europe (15)
- # clojure-france (1)
- # clojure-nl (13)
- # clojure-portugal (4)
- # clojure-uk (6)
- # clojurescript (3)
- # conjure (3)
- # cryogen (10)
- # datomic (23)
- # emacs (9)
- # fulcro (12)
- # graalvm (1)
- # graphql (2)
- # introduce-yourself (2)
- # jobs (4)
- # jobs-discuss (9)
- # lsp (2)
- # pathom (3)
- # polylith (23)
- # portal (1)
- # reagent (14)
- # releases (4)
- # remote-jobs (3)
- # shadow-cljs (1)
- # sql (8)
- # tools-build (7)
- # tools-deps (10)
- # xtdb (7)
Hello! Do you have any tips for ensuring that an extra statement is executed whenever I check a connection from a Conn. Pool and when I return it back? I am thinking about making a wrapper/proxy for the DataSource and Connection objects (and I have asked about that in https://clojurians.slack.com/archives/C03S1KBA2/p1633952449070600) but perhaps I am missing some other, simpler way?
The statements in question are Postgres' set role <some name>
and reset role
(since we are using schemas for multi-tenancy and want to ensure that a user only has access to her data).
Do you use next.jdbc? Perhaps it could be done on that level, so you wrap only get-connection
I do. Wrapping get-connection is easy, I can implement next-jdbc/Connectable
, so executing st. when I check out a connection is trivial. What is messy is executing something when I return it, which happens via the Connection/Closeable's .close
The problem is that Connectable/get-connection
must return a java.sql.Connection
and to override its .close I would need through a whole mess to wrap it somehow... 😭
This is something that connection pool libraries do automatically -- are you using a connection pool?
Both c3p0 and HikariCP have hooks to automatically run queries to validate connections at different points. Ah, you'd need it to be dynamic for the role
stuff wouldn't you...
I use Hikari. Though if it can run a query on connection returned, that would help that one can be static