From a5be7d00cb9c7cdea55a4952f455d49fd50b9fad Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Sun, 14 Jan 2024 17:08:47 -0800 Subject: [PATCH] linting Signed-off-by: Sean Corfield --- CHANGELOG.md | 1 + src/next/jdbc/connection.clj | 11 ++--- src/next/jdbc/optional.clj | 36 ++++++++-------- src/next/jdbc/result_set.clj | 84 ++++++++++++++++++------------------ src/next/jdbc/types.clj | 4 +- 5 files changed, 69 insertions(+), 67 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c3715f..18d3cc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Only accretive/fixative changes will be made from now on. * 1.3.next in progress * Address [#268](https://github.com/seancorfield/next-jdbc/issues/268) by expanding the documentation around `insert-multi!` and `insert!`. + * Code cleanup per `clj-kondo`. * 1.3.909 -- 2023-12-16 * Address [#267](https://github.com/seancorfield/next-jdbc/issues/267) by adding the `:schema-opts` option to override the default conventions for identifying foreign keys in columns. diff --git a/src/next/jdbc/connection.clj b/src/next/jdbc/connection.clj index d02f648..0223b1a 100644 --- a/src/next/jdbc/connection.clj +++ b/src/next/jdbc/connection.clj @@ -1,4 +1,4 @@ -;; copyright (c) 2018-2023 Sean Corfield, all rights reserved +;; copyright (c) 2018-2024 Sean Corfield, all rights reserved (ns next.jdbc.connection "Standard implementations of `get-datasource` and `get-connection`. @@ -330,7 +330,8 @@ (component clazz db-spec close-fn))})))}))) (comment - (require '[com.stuartsierra.component :as component]) + (require '[com.stuartsierra.component :as component] + '[next.jdbc.sql :as sql]) (import '(com.mchange.v2.c3p0 ComboPooledDataSource PooledDataSource) '(com.zaxxer.hikari HikariDataSource)) (isa? PooledDataSource java.io.Closeable) ;=> false @@ -358,7 +359,7 @@ ;; start the chosen datasource component: (def ds (component/start dbc)) ;; invoke datasource component to get the underlying javax.sql.DataSource: - (next.jdbc.sql/get-by-id (ds) :fruit 1) + (sql/get-by-id (ds) :fruit 1) ;; stop the component and close the pooled datasource: (component/stop ds) ) @@ -368,9 +369,9 @@ [s] [s {}]) -(defn- ^Properties as-properties +(defn- as-properties "Convert any seq of pairs to a `java.util.Properties` instance." - [m] + ^Properties [m] (let [p (Properties.)] (doseq [[k v] m] (.setProperty p (name k) (str v))) diff --git a/src/next/jdbc/optional.clj b/src/next/jdbc/optional.clj index 522a1a8..298bd61 100644 --- a/src/next/jdbc/optional.clj +++ b/src/next/jdbc/optional.clj @@ -1,4 +1,4 @@ -;; copyright (c) 2019-2021 Sean Corfield, all rights reserved +;; copyright (c) 2019-2024 Sean Corfield, all rights reserved (ns next.jdbc.optional "Builders that treat NULL SQL values as 'optional' and omit the @@ -11,8 +11,8 @@ (defrecord MapResultSetOptionalBuilder [^ResultSet rs rsmeta cols] rs/RowBuilder - (->row [this] (transient {})) - (column-count [this] (count cols)) + (->row [_this] (transient {})) + (column-count [_this] (count cols)) (with-column [this row i] ;; short-circuit on null to avoid column reading logic (let [v (.getObject rs ^Integer i)] @@ -20,17 +20,17 @@ row (rs/with-column-value this row (nth cols (dec i)) (rs/read-column-by-index v rsmeta i))))) - (with-column-value [this row col v] + (with-column-value [_this row col v] ;; ensure that even if this is adapted, we omit null columns (if (nil? v) row (assoc! row col v))) - (row! [this row] (persistent! row)) + (row! [_this row] (persistent! row)) rs/ResultSetBuilder - (->rs [this] (transient [])) - (with-row [this mrs row] + (->rs [_this] (transient [])) + (with-row [_this mrs row] (conj! mrs row)) - (rs! [this mrs] (persistent! mrs))) + (rs! [_this mrs] (persistent! mrs))) (defn as-maps "Given a `ResultSet` and options, return a `RowBuilder` / `ResultSetBuilder` @@ -117,25 +117,25 @@ (let [mrsb (builder-fn rs opts)] (reify rs/RowBuilder - (->row [this] (rs/->row mrsb)) - (column-count [this] (rs/column-count mrsb)) - (with-column [this row i] + (->row [_this] (rs/->row mrsb)) + (column-count [_this] (rs/column-count mrsb)) + (with-column [_this row i] ;; short-circuit on null to avoid column reading logic (let [v (column-reader rs (:rsmeta mrsb) i)] (if (nil? v) row (rs/with-column-value mrsb row (nth (:cols mrsb) (dec i)) (rs/read-column-by-index v (:rsmeta mrsb) i))))) - (with-column-value [this row col v] + (with-column-value [_this row col v] ;; ensure that even if this is adapted, we omit null columns (if (nil? v) row (rs/with-column-value mrsb row col v))) - (row! [this row] (rs/row! mrsb row)) + (row! [_this row] (rs/row! mrsb row)) rs/ResultSetBuilder - (->rs [this] (rs/->rs mrsb)) - (with-row [this mrs row] (rs/with-row mrsb mrs row)) - (rs! [this mrs] (rs/rs! mrsb mrs)) + (->rs [_this] (rs/->rs mrsb)) + (with-row [_this mrs row] (rs/with-row mrsb mrs row)) + (rs! [_this mrs] (rs/rs! mrsb mrs)) clojure.lang.ILookup - (valAt [this k] (get mrsb k)) - (valAt [this k not-found] (get mrsb k not-found)))))) + (valAt [_this k] (get mrsb k)) + (valAt [_this k not-found] (get mrsb k not-found)))))) diff --git a/src/next/jdbc/result_set.clj b/src/next/jdbc/result_set.clj index 0c83d9e..b9125a7 100644 --- a/src/next/jdbc/result_set.clj +++ b/src/next/jdbc/result_set.clj @@ -183,37 +183,37 @@ (let [builder (builder-fn rs opts)] (reify RowBuilder - (->row [this] (->row builder)) - (column-count [this] (column-count builder)) + (->row [_this] (->row builder)) + (column-count [_this] (column-count builder)) (with-column [this row i] (with-column-value this row (nth (:cols builder) (dec i)) (column-by-index-fn builder rs i))) - (with-column-value [this row col v] + (with-column-value [_this row col v] (with-column-value builder row col v)) - (row! [this row] (row! builder row)) + (row! [_this row] (row! builder row)) ResultSetBuilder - (->rs [this] (->rs builder)) - (with-row [this mrs row] (with-row builder mrs row)) - (rs! [this mrs] (rs! builder mrs)) + (->rs [_this] (->rs builder)) + (with-row [_this mrs row] (with-row builder mrs row)) + (rs! [_this mrs] (rs! builder mrs)) clojure.lang.ILookup - (valAt [this k] (get builder k)) - (valAt [this k not-found] (get builder k not-found)))))) + (valAt [_this k] (get builder k)) + (valAt [_this k not-found] (get builder k not-found)))))) (defrecord MapResultSetBuilder [^ResultSet rs rsmeta cols] RowBuilder - (->row [this] (transient {})) - (column-count [this] (count cols)) + (->row [_this] (transient {})) + (column-count [_this] (count cols)) (with-column [this row i] (with-column-value this row (nth cols (dec i)) (read-column-by-index (.getObject rs ^Integer i) rsmeta i))) - (with-column-value [this row col v] + (with-column-value [_this row col v] (assoc! row col v)) - (row! [this row] (persistent! row)) + (row! [_this row] (persistent! row)) ResultSetBuilder - (->rs [this] (transient [])) - (with-row [this mrs row] + (->rs [_this] (transient [])) + (with-row [_this mrs row] (conj! mrs row)) - (rs! [this mrs] (persistent! mrs))) + (rs! [_this mrs] (persistent! mrs))) (defn as-maps "Given a `ResultSet` and options, return a `RowBuilder` / `ResultSetBuilder` @@ -323,19 +323,19 @@ (defrecord ArrayResultSetBuilder [^ResultSet rs rsmeta cols] RowBuilder - (->row [this] (transient [])) - (column-count [this] (count cols)) + (->row [_this] (transient [])) + (column-count [_this] (count cols)) (with-column [this row i] (with-column-value this row nil (read-column-by-index (.getObject rs ^Integer i) rsmeta i))) - (with-column-value [this row _ v] + (with-column-value [_this row _ v] (conj! row v)) - (row! [this row] (persistent! row)) + (row! [_this row] (persistent! row)) ResultSetBuilder - (->rs [this] (transient [cols])) - (with-row [this ars row] + (->rs [_this] (transient [cols])) + (with-row [_this ars row] (conj! ars row)) - (rs! [this ars] (persistent! ars))) + (rs! [_this ars] (persistent! ars))) (defn as-arrays "Given a `ResultSet` and options, return a `RowBuilder` / `ResultSetBuilder` @@ -495,30 +495,30 @@ ;; marker, just for printing resolution InspectableMapifiedResultSet - (row-number [this] (.getRow rs)) - (column-names [this] (:cols @builder)) - (metadata [this] (d/datafy (.getMetaData rs))) + (row-number [_this] (.getRow rs)) + (column-names [_this] (:cols @builder)) + (metadata [_this] (d/datafy (.getMetaData rs))) clojure.lang.IPersistentMap - (assoc [this k v] + (assoc [_this k v] (assoc (row-builder @builder) k v)) - (assocEx [this k v] + (assocEx [_this k v] (.assocEx ^clojure.lang.IPersistentMap (row-builder @builder) k v)) - (without [this k] + (without [_this k] (dissoc (row-builder @builder) k)) java.lang.Iterable ; Java 7 compatible: no forEach / spliterator - (iterator [this] + (iterator [_this] (.iterator ^java.lang.Iterable (row-builder @builder))) clojure.lang.Associative - (containsKey [this k] + (containsKey [_this k] (try (.getObject rs ^String (name-fn k)) true (catch SQLException _ false))) - (entryAt [this k] + (entryAt [_this k] (try (clojure.lang.MapEntry. k (read-column-by-label (.getObject rs ^String (name-fn k)) @@ -526,28 +526,28 @@ (catch SQLException _))) clojure.lang.Counted - (count [this] + (count [_this] (column-count @builder)) clojure.lang.IPersistentCollection - (cons [this obj] + (cons [_this obj] (let [row (row-builder @builder)] (conj row obj))) - (empty [this] + (empty [_this] {}) - (equiv [this obj] + (equiv [_this obj] (.equiv ^clojure.lang.IPersistentCollection (row-builder @builder) obj)) ;; we support get with a numeric key for array-based builders: clojure.lang.ILookup - (valAt [this k] + (valAt [_this k] (try (if (number? k) (let [^Integer i (inc k)] (read-column-by-index (.getObject rs i) (:rsmeta @builder) i)) (read-column-by-label (.getObject rs ^String (name-fn k)) ^String (name-fn k))) (catch SQLException _))) - (valAt [this k not-found] + (valAt [_this k not-found] (try (if (number? k) (let [^Integer i (inc k)] @@ -558,12 +558,12 @@ ;; we support nth for array-based builders (i is primitive int here!): clojure.lang.Indexed - (nth [this i] + (nth [_this i] (try (let [i (inc i)] (read-column-by-index (.getObject rs i) (:rsmeta @builder) i)) (catch SQLException _))) - (nth [this i not-found] + (nth [_this i not-found] (try (let [i (inc i)] (read-column-by-index (.getObject rs i) (:rsmeta @builder) i)) @@ -571,11 +571,11 @@ not-found))) clojure.lang.Seqable - (seq [this] + (seq [_this] (seq (row-builder @builder))) DatafiableRow - (datafiable-row [this connectable opts] + (datafiable-row [_this connectable opts] ;; since we have to call these eagerly, we trap any exceptions so ;; that they can be thrown when the actual functions are called (let [row (try (.getRow rs) (catch Throwable t t)) diff --git a/src/next/jdbc/types.clj b/src/next/jdbc/types.clj index 642c54e..3639975 100644 --- a/src/next/jdbc/types.clj +++ b/src/next/jdbc/types.clj @@ -1,11 +1,11 @@ -;; copyright (c) 2018-2021 Sean Corfield, all rights reserved +;; copyright (c) 2018-2024 Sean Corfield, all rights reserved (ns next.jdbc.types "Provides convenience functions for wrapping values you pass into SQL operations that have per-instance implementations of `SettableParameter` so that `.setObject()` is called with the appropriate `java.sql.Types` value." (:require [clojure.string :as str] - [next.jdbc.prepare :as prep]) + [next.jdbc.prepare]) (:import (java.lang.reflect Field Modifier) (java.sql PreparedStatement)))