Skip to content

Commit 57f0bfe

Browse files
committed
chore: format fix
1 parent 045179c commit 57f0bfe

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

src/konserve_jdbc/core.clj

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
[hasch.core :as hasch]
1515
[clojure.string :as str])
1616
(:import [java.sql Blob]
17-
[com.mchange.v2.c3p0 ComboPooledDataSource PooledDataSource]
17+
[com.mchange.v2.c3p0 ComboPooledDataSource PooledDataSource]
1818
(java.io ByteArrayInputStream)
1919
(java.sql Connection)))
2020

@@ -30,19 +30,19 @@
3030
;; each unique spec will have its own pool
3131
(defn- pool-key [db-spec]
3232
(keyword
33-
(str (hasch/uuid (select-keys db-spec [:dbtype :jdbcUrl :host :port :user :password :dbname :sync?])))))
33+
(str (hasch/uuid (select-keys db-spec [:dbtype :jdbcUrl :host :port :user :password :dbname :sync?])))))
3434

3535
(defn get-connection [db-spec]
3636
(let [id (pool-key db-spec)
3737
conn (get @pool id)]
38-
(if-not (nil? conn)
38+
(if-not (nil? conn)
3939
conn
4040
(let [conns ^PooledDataSource (connection/->pool ComboPooledDataSource db-spec)
41-
shutdown (fn [] (.close ^PooledDataSource conns))]
41+
shutdown (fn [] (.close ^PooledDataSource conns))]
4242
(swap! pool assoc id conns)
4343
(.close (jdbc/get-connection conns))
44-
(.addShutdownHook (Runtime/getRuntime)
45-
(Thread. ^Runnable shutdown))
44+
(.addShutdownHook (Runtime/getRuntime)
45+
(Thread. ^Runnable shutdown))
4646
conns))))
4747

4848
(defn remove-from-pool [db-spec]
@@ -222,19 +222,19 @@
222222
(if (:sync? env) nil (go-try- nil)))
223223
(-create-store [_ env]
224224
(async+sync (:sync? env) *default-sync-translation*
225-
(go-try-
225+
(go-try-
226226
;; Using CREATE IF NOT EXISTS is regarded as a schema change. To allow the store to be used
227227
;; where schema changes are not allowed on production e.g. planetscale or the user does have schema permissions,
228228
;; we test for existence first. This triggers an exception if it doesn't exist which we catch.
229229
;; Testing for existence in other ways is not worth the effort as it is specific to the db setup
230230
;; not just the type
231-
(let [res (try
232-
(jdbc/execute! connection [(str "select 1 from " table " limit 1")])
233-
(catch Exception _e
234-
(debug (str "Table " table " does not exist. Attempting to create it."))
235-
nil))]
236-
(when (nil? res)
237-
(jdbc/execute! connection (create-statement (:dbtype db-spec) table)))))))
231+
(let [res (try
232+
(jdbc/execute! connection [(str "select 1 from " table " limit 1")])
233+
(catch Exception _e
234+
(debug (str "Table " table " does not exist. Attempting to create it."))
235+
nil))]
236+
(when (nil? res)
237+
(jdbc/execute! connection (create-statement (:dbtype db-spec) table)))))))
238238
(-sync-store [_ env]
239239
(if (:sync? env) nil (go-try- nil)))
240240
(-delete-store [_ env]
@@ -257,30 +257,30 @@
257257
(let [old-url (:jdbcUrl db)
258258
spec (connection/uri->db-spec old-url) ;; set port to -1 if none is in the url
259259
port (:port spec)
260-
new-spec (-> spec
260+
new-spec (-> spec
261261
(update :dbtype #(str/replace % #"postgres$" "postgresql")) ;the postgres driver does not support long blob
262-
(assoc :port (if (pos? port)
263-
port
264-
(-> connection/dbtypes
265-
(get (:dbtype spec))
266-
:port))))]
262+
(assoc :port (if (pos? port)
263+
port
264+
(-> connection/dbtypes
265+
(get (:dbtype spec))
266+
:port))))]
267267
new-spec)))
268268

269269
(defn connect-store [db-spec & {:keys [table opts]
270270
:or {table default-table}
271271
:as params}]
272-
(let [db-spec (prepare-spec db-spec)]
272+
(let [db-spec (prepare-spec db-spec)]
273273
(when-not (:dbtype db-spec)
274-
(throw (ex-info ":dbtype must be explicitly declared" {:options dbtypes})))
275-
274+
(throw (ex-info ":dbtype must be explicitly declared" {:options dbtypes})))
275+
276276
(when-not (supported-dbtypes (:dbtype db-spec))
277277
(warn "Unsupported database type " (:dbtype db-spec)
278278
" - full functionality of store is only guaranteed for following database types: " supported-dbtypes))
279279

280-
(System/setProperties
281-
(doto (java.util.Properties. (System/getProperties))
282-
(.put "com.mchange.v2.log.MLog" "com.mchange.v2.log.slf4j.Slf4jMLog"))) ;; using Slf4j allows timbre to control logs.
283-
280+
(System/setProperties
281+
(doto (java.util.Properties. (System/getProperties))
282+
(.put "com.mchange.v2.log.MLog" "com.mchange.v2.log.slf4j.Slf4jMLog"))) ;; using Slf4j allows timbre to control logs.
283+
284284
(let [complete-opts (merge {:sync? true} opts)
285285
db-spec (if (:dbtype db-spec)
286286
db-spec
@@ -289,23 +289,23 @@
289289
^PooledDataSource connection (get-connection db-spec)
290290
backing (JDBCTable. db-spec connection table)
291291
config (merge {:opts complete-opts
292-
:config {:sync-blob? true
292+
:config {:sync-blob? true
293293
:in-place? true
294294
:lock-blob? true}
295-
:default-serializer :FressianSerializer
296-
:compressor null-compressor
297-
:encryptor null-encryptor
298-
:buffer-size (* 1024 1024)}
295+
:default-serializer :FressianSerializer
296+
:compressor null-compressor
297+
:encryptor null-encryptor
298+
:buffer-size (* 1024 1024)}
299299
(dissoc params :opts :config))]
300300
(connect-default-store backing config))))
301301

302302
(defn release
303303
"Must be called after work on database has finished in order to close connection"
304304
[store env]
305305
(async+sync (:sync? env) *default-sync-translation*
306-
(go-try-
307-
(.close ^PooledDataSource (:connection ^JDBCTable (:backing store)))
308-
(remove-from-pool (:db-spec ^JDBCTable (:backing store))))))
306+
(go-try-
307+
(.close ^PooledDataSource (:connection ^JDBCTable (:backing store)))
308+
(remove-from-pool (:db-spec ^JDBCTable (:backing store))))))
309309

310310
(defn delete-store [db-spec & {:keys [table opts] :or {table default-table}}]
311311
(let [complete-opts (merge {:sync? true} opts)

0 commit comments

Comments
 (0)