From 90d48c1d30bc133394263b10b35b46dde04e2f0f Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 31 Mar 2023 12:35:16 +0200 Subject: [PATCH] :sparkles: Add the ability to check read-only state of connection on the db ns helper; previously it only worked with datasource instances --- backend/src/app/db.clj | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/backend/src/app/db.clj b/backend/src/app/db.clj index 8871764b1..8bda9e1d0 100644 --- a/backend/src/app/db.clj +++ b/backend/src/app/db.clj @@ -155,8 +155,18 @@ (.isClosed ^HikariDataSource pool)) (defn read-only? - [pool] - (.isReadOnly ^HikariDataSource pool)) + [pool-or-conn] + (cond + (instance? HikariDataSource pool-or-conn) + (.isReadOnly ^HikariDataSource pool-or-conn) + + (instance? Connection pool-or-conn) + (.isReadOnly ^Connection pool-or-conn) + + :else + (ex/raise :type :internal + :code :invalid-connection + :hint "invalid connection provided"))) (defn create-pool [cfg]