From 3cf4a3facc7ee2217ab7dd39db14cf9ae95ce581 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 6 Feb 2023 12:23:39 +0100 Subject: [PATCH] :sparkles: Improve db/pool initialization and reusability --- backend/src/app/db.clj | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/backend/src/app/db.clj b/backend/src/app/db.clj index d6f35f7f2..457bad1f5 100644 --- a/backend/src/app/db.clj +++ b/backend/src/app/db.clj @@ -59,8 +59,8 @@ (s/def ::read-only? ::us/boolean) (s/def ::pool-options - (s/keys :req [::uri] - :opt [::name + (s/keys :opt [::uri + ::name ::min-size ::max-size ::connection-timeout @@ -89,15 +89,16 @@ (defmethod ig/init-key ::pool [_ {:keys [::uri ::read-only?] :as cfg}] - (l/info :hint "initialize connection pool" - :name (d/name (::name cfg)) - :uri uri - :read-only read-only? - :with-credentials (and (contains? cfg ::username) - (contains? cfg ::password)) - :min-size (::min-size cfg) + (when uri + (l/info :hint "initialize connection pool" + :name (d/name (::name cfg)) + :uri uri + :read-only read-only? + :with-credentials (and (contains? cfg ::username) + (contains? cfg ::password)) + :min-size (::min-size cfg) :max-size (::max-size cfg)) - (create-pool cfg)) + (create-pool cfg))) (defmethod ig/halt-key! ::pool [_ pool] @@ -144,6 +145,7 @@ [v] (instance? javax.sql.DataSource v)) +(s/def ::conn some?) (s/def ::pool pool?) (s/def ::nilable-pool (s/nilable ::pool)) (s/def ::conn-or-pool some?) @@ -430,6 +432,11 @@ (.setType "jsonb") (.setValue (json/encode-str data))))) +(defn get-update-count + [result] + (:next.jdbc/update-count result)) + + ;; --- Locks (def ^:private siphash-state