linting
Signed-off-by: Sean Corfield <sean@corfield.org>
This commit is contained in:
parent
44b3cc206f
commit
a5be7d00cb
5 changed files with 69 additions and 67 deletions
|
|
@ -4,6 +4,7 @@ Only accretive/fixative changes will be made from now on.
|
||||||
|
|
||||||
* 1.3.next in progress
|
* 1.3.next in progress
|
||||||
* Address [#268](https://github.com/seancorfield/next-jdbc/issues/268) by expanding the documentation around `insert-multi!` and `insert!`.
|
* 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
|
* 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.
|
* 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.
|
||||||
|
|
|
||||||
|
|
@ -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
|
(ns next.jdbc.connection
|
||||||
"Standard implementations of `get-datasource` and `get-connection`.
|
"Standard implementations of `get-datasource` and `get-connection`.
|
||||||
|
|
@ -330,7 +330,8 @@
|
||||||
(component clazz db-spec close-fn))})))})))
|
(component clazz db-spec close-fn))})))})))
|
||||||
|
|
||||||
(comment
|
(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)
|
(import '(com.mchange.v2.c3p0 ComboPooledDataSource PooledDataSource)
|
||||||
'(com.zaxxer.hikari HikariDataSource))
|
'(com.zaxxer.hikari HikariDataSource))
|
||||||
(isa? PooledDataSource java.io.Closeable) ;=> false
|
(isa? PooledDataSource java.io.Closeable) ;=> false
|
||||||
|
|
@ -358,7 +359,7 @@
|
||||||
;; start the chosen datasource component:
|
;; start the chosen datasource component:
|
||||||
(def ds (component/start dbc))
|
(def ds (component/start dbc))
|
||||||
;; invoke datasource component to get the underlying javax.sql.DataSource:
|
;; 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:
|
;; stop the component and close the pooled datasource:
|
||||||
(component/stop ds)
|
(component/stop ds)
|
||||||
)
|
)
|
||||||
|
|
@ -368,9 +369,9 @@
|
||||||
[s]
|
[s]
|
||||||
[s {}])
|
[s {}])
|
||||||
|
|
||||||
(defn- ^Properties as-properties
|
(defn- as-properties
|
||||||
"Convert any seq of pairs to a `java.util.Properties` instance."
|
"Convert any seq of pairs to a `java.util.Properties` instance."
|
||||||
[m]
|
^Properties [m]
|
||||||
(let [p (Properties.)]
|
(let [p (Properties.)]
|
||||||
(doseq [[k v] m]
|
(doseq [[k v] m]
|
||||||
(.setProperty p (name k) (str v)))
|
(.setProperty p (name k) (str v)))
|
||||||
|
|
|
||||||
|
|
@ -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
|
(ns next.jdbc.optional
|
||||||
"Builders that treat NULL SQL values as 'optional' and omit the
|
"Builders that treat NULL SQL values as 'optional' and omit the
|
||||||
|
|
@ -11,8 +11,8 @@
|
||||||
|
|
||||||
(defrecord MapResultSetOptionalBuilder [^ResultSet rs rsmeta cols]
|
(defrecord MapResultSetOptionalBuilder [^ResultSet rs rsmeta cols]
|
||||||
rs/RowBuilder
|
rs/RowBuilder
|
||||||
(->row [this] (transient {}))
|
(->row [_this] (transient {}))
|
||||||
(column-count [this] (count cols))
|
(column-count [_this] (count cols))
|
||||||
(with-column [this row i]
|
(with-column [this row i]
|
||||||
;; short-circuit on null to avoid column reading logic
|
;; short-circuit on null to avoid column reading logic
|
||||||
(let [v (.getObject rs ^Integer i)]
|
(let [v (.getObject rs ^Integer i)]
|
||||||
|
|
@ -20,17 +20,17 @@
|
||||||
row
|
row
|
||||||
(rs/with-column-value this row (nth cols (dec i))
|
(rs/with-column-value this row (nth cols (dec i))
|
||||||
(rs/read-column-by-index v rsmeta 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
|
;; ensure that even if this is adapted, we omit null columns
|
||||||
(if (nil? v)
|
(if (nil? v)
|
||||||
row
|
row
|
||||||
(assoc! row col v)))
|
(assoc! row col v)))
|
||||||
(row! [this row] (persistent! row))
|
(row! [_this row] (persistent! row))
|
||||||
rs/ResultSetBuilder
|
rs/ResultSetBuilder
|
||||||
(->rs [this] (transient []))
|
(->rs [_this] (transient []))
|
||||||
(with-row [this mrs row]
|
(with-row [_this mrs row]
|
||||||
(conj! mrs row))
|
(conj! mrs row))
|
||||||
(rs! [this mrs] (persistent! mrs)))
|
(rs! [_this mrs] (persistent! mrs)))
|
||||||
|
|
||||||
(defn as-maps
|
(defn as-maps
|
||||||
"Given a `ResultSet` and options, return a `RowBuilder` / `ResultSetBuilder`
|
"Given a `ResultSet` and options, return a `RowBuilder` / `ResultSetBuilder`
|
||||||
|
|
@ -117,25 +117,25 @@
|
||||||
(let [mrsb (builder-fn rs opts)]
|
(let [mrsb (builder-fn rs opts)]
|
||||||
(reify
|
(reify
|
||||||
rs/RowBuilder
|
rs/RowBuilder
|
||||||
(->row [this] (rs/->row mrsb))
|
(->row [_this] (rs/->row mrsb))
|
||||||
(column-count [this] (rs/column-count mrsb))
|
(column-count [_this] (rs/column-count mrsb))
|
||||||
(with-column [this row i]
|
(with-column [_this row i]
|
||||||
;; short-circuit on null to avoid column reading logic
|
;; short-circuit on null to avoid column reading logic
|
||||||
(let [v (column-reader rs (:rsmeta mrsb) i)]
|
(let [v (column-reader rs (:rsmeta mrsb) i)]
|
||||||
(if (nil? v)
|
(if (nil? v)
|
||||||
row
|
row
|
||||||
(rs/with-column-value mrsb row (nth (:cols mrsb) (dec i))
|
(rs/with-column-value mrsb row (nth (:cols mrsb) (dec i))
|
||||||
(rs/read-column-by-index v (:rsmeta mrsb) 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
|
;; ensure that even if this is adapted, we omit null columns
|
||||||
(if (nil? v)
|
(if (nil? v)
|
||||||
row
|
row
|
||||||
(rs/with-column-value mrsb row col v)))
|
(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/ResultSetBuilder
|
||||||
(->rs [this] (rs/->rs mrsb))
|
(->rs [_this] (rs/->rs mrsb))
|
||||||
(with-row [this mrs row] (rs/with-row mrsb mrs row))
|
(with-row [_this mrs row] (rs/with-row mrsb mrs row))
|
||||||
(rs! [this mrs] (rs/rs! mrsb mrs))
|
(rs! [_this mrs] (rs/rs! mrsb mrs))
|
||||||
clojure.lang.ILookup
|
clojure.lang.ILookup
|
||||||
(valAt [this k] (get mrsb k))
|
(valAt [_this k] (get mrsb k))
|
||||||
(valAt [this k not-found] (get mrsb k not-found))))))
|
(valAt [_this k not-found] (get mrsb k not-found))))))
|
||||||
|
|
|
||||||
|
|
@ -183,37 +183,37 @@
|
||||||
(let [builder (builder-fn rs opts)]
|
(let [builder (builder-fn rs opts)]
|
||||||
(reify
|
(reify
|
||||||
RowBuilder
|
RowBuilder
|
||||||
(->row [this] (->row builder))
|
(->row [_this] (->row builder))
|
||||||
(column-count [this] (column-count builder))
|
(column-count [_this] (column-count builder))
|
||||||
(with-column [this row i]
|
(with-column [this row i]
|
||||||
(with-column-value this row (nth (:cols builder) (dec i))
|
(with-column-value this row (nth (:cols builder) (dec i))
|
||||||
(column-by-index-fn builder rs 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))
|
(with-column-value builder row col v))
|
||||||
(row! [this row] (row! builder row))
|
(row! [_this row] (row! builder row))
|
||||||
ResultSetBuilder
|
ResultSetBuilder
|
||||||
(->rs [this] (->rs builder))
|
(->rs [_this] (->rs builder))
|
||||||
(with-row [this mrs row] (with-row builder mrs row))
|
(with-row [_this mrs row] (with-row builder mrs row))
|
||||||
(rs! [this mrs] (rs! builder mrs))
|
(rs! [_this mrs] (rs! builder mrs))
|
||||||
clojure.lang.ILookup
|
clojure.lang.ILookup
|
||||||
(valAt [this k] (get builder k))
|
(valAt [_this k] (get builder k))
|
||||||
(valAt [this k not-found] (get builder k not-found))))))
|
(valAt [_this k not-found] (get builder k not-found))))))
|
||||||
|
|
||||||
(defrecord MapResultSetBuilder [^ResultSet rs rsmeta cols]
|
(defrecord MapResultSetBuilder [^ResultSet rs rsmeta cols]
|
||||||
RowBuilder
|
RowBuilder
|
||||||
(->row [this] (transient {}))
|
(->row [_this] (transient {}))
|
||||||
(column-count [this] (count cols))
|
(column-count [_this] (count cols))
|
||||||
(with-column [this row i]
|
(with-column [this row i]
|
||||||
(with-column-value this row (nth cols (dec i))
|
(with-column-value this row (nth cols (dec i))
|
||||||
(read-column-by-index (.getObject rs ^Integer i) rsmeta 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))
|
(assoc! row col v))
|
||||||
(row! [this row] (persistent! row))
|
(row! [_this row] (persistent! row))
|
||||||
ResultSetBuilder
|
ResultSetBuilder
|
||||||
(->rs [this] (transient []))
|
(->rs [_this] (transient []))
|
||||||
(with-row [this mrs row]
|
(with-row [_this mrs row]
|
||||||
(conj! mrs row))
|
(conj! mrs row))
|
||||||
(rs! [this mrs] (persistent! mrs)))
|
(rs! [_this mrs] (persistent! mrs)))
|
||||||
|
|
||||||
(defn as-maps
|
(defn as-maps
|
||||||
"Given a `ResultSet` and options, return a `RowBuilder` / `ResultSetBuilder`
|
"Given a `ResultSet` and options, return a `RowBuilder` / `ResultSetBuilder`
|
||||||
|
|
@ -323,19 +323,19 @@
|
||||||
|
|
||||||
(defrecord ArrayResultSetBuilder [^ResultSet rs rsmeta cols]
|
(defrecord ArrayResultSetBuilder [^ResultSet rs rsmeta cols]
|
||||||
RowBuilder
|
RowBuilder
|
||||||
(->row [this] (transient []))
|
(->row [_this] (transient []))
|
||||||
(column-count [this] (count cols))
|
(column-count [_this] (count cols))
|
||||||
(with-column [this row i]
|
(with-column [this row i]
|
||||||
(with-column-value this row nil
|
(with-column-value this row nil
|
||||||
(read-column-by-index (.getObject rs ^Integer i) rsmeta i)))
|
(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))
|
(conj! row v))
|
||||||
(row! [this row] (persistent! row))
|
(row! [_this row] (persistent! row))
|
||||||
ResultSetBuilder
|
ResultSetBuilder
|
||||||
(->rs [this] (transient [cols]))
|
(->rs [_this] (transient [cols]))
|
||||||
(with-row [this ars row]
|
(with-row [_this ars row]
|
||||||
(conj! ars row))
|
(conj! ars row))
|
||||||
(rs! [this ars] (persistent! ars)))
|
(rs! [_this ars] (persistent! ars)))
|
||||||
|
|
||||||
(defn as-arrays
|
(defn as-arrays
|
||||||
"Given a `ResultSet` and options, return a `RowBuilder` / `ResultSetBuilder`
|
"Given a `ResultSet` and options, return a `RowBuilder` / `ResultSetBuilder`
|
||||||
|
|
@ -495,30 +495,30 @@
|
||||||
;; marker, just for printing resolution
|
;; marker, just for printing resolution
|
||||||
|
|
||||||
InspectableMapifiedResultSet
|
InspectableMapifiedResultSet
|
||||||
(row-number [this] (.getRow rs))
|
(row-number [_this] (.getRow rs))
|
||||||
(column-names [this] (:cols @builder))
|
(column-names [_this] (:cols @builder))
|
||||||
(metadata [this] (d/datafy (.getMetaData rs)))
|
(metadata [_this] (d/datafy (.getMetaData rs)))
|
||||||
|
|
||||||
clojure.lang.IPersistentMap
|
clojure.lang.IPersistentMap
|
||||||
(assoc [this k v]
|
(assoc [_this k v]
|
||||||
(assoc (row-builder @builder) 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))
|
(.assocEx ^clojure.lang.IPersistentMap (row-builder @builder) k v))
|
||||||
(without [this k]
|
(without [_this k]
|
||||||
(dissoc (row-builder @builder) k))
|
(dissoc (row-builder @builder) k))
|
||||||
|
|
||||||
java.lang.Iterable ; Java 7 compatible: no forEach / spliterator
|
java.lang.Iterable ; Java 7 compatible: no forEach / spliterator
|
||||||
(iterator [this]
|
(iterator [_this]
|
||||||
(.iterator ^java.lang.Iterable (row-builder @builder)))
|
(.iterator ^java.lang.Iterable (row-builder @builder)))
|
||||||
|
|
||||||
clojure.lang.Associative
|
clojure.lang.Associative
|
||||||
(containsKey [this k]
|
(containsKey [_this k]
|
||||||
(try
|
(try
|
||||||
(.getObject rs ^String (name-fn k))
|
(.getObject rs ^String (name-fn k))
|
||||||
true
|
true
|
||||||
(catch SQLException _
|
(catch SQLException _
|
||||||
false)))
|
false)))
|
||||||
(entryAt [this k]
|
(entryAt [_this k]
|
||||||
(try
|
(try
|
||||||
(clojure.lang.MapEntry. k (read-column-by-label
|
(clojure.lang.MapEntry. k (read-column-by-label
|
||||||
(.getObject rs ^String (name-fn k))
|
(.getObject rs ^String (name-fn k))
|
||||||
|
|
@ -526,28 +526,28 @@
|
||||||
(catch SQLException _)))
|
(catch SQLException _)))
|
||||||
|
|
||||||
clojure.lang.Counted
|
clojure.lang.Counted
|
||||||
(count [this]
|
(count [_this]
|
||||||
(column-count @builder))
|
(column-count @builder))
|
||||||
|
|
||||||
clojure.lang.IPersistentCollection
|
clojure.lang.IPersistentCollection
|
||||||
(cons [this obj]
|
(cons [_this obj]
|
||||||
(let [row (row-builder @builder)]
|
(let [row (row-builder @builder)]
|
||||||
(conj row obj)))
|
(conj row obj)))
|
||||||
(empty [this]
|
(empty [_this]
|
||||||
{})
|
{})
|
||||||
(equiv [this obj]
|
(equiv [_this obj]
|
||||||
(.equiv ^clojure.lang.IPersistentCollection (row-builder @builder) obj))
|
(.equiv ^clojure.lang.IPersistentCollection (row-builder @builder) obj))
|
||||||
|
|
||||||
;; we support get with a numeric key for array-based builders:
|
;; we support get with a numeric key for array-based builders:
|
||||||
clojure.lang.ILookup
|
clojure.lang.ILookup
|
||||||
(valAt [this k]
|
(valAt [_this k]
|
||||||
(try
|
(try
|
||||||
(if (number? k)
|
(if (number? k)
|
||||||
(let [^Integer i (inc k)]
|
(let [^Integer i (inc k)]
|
||||||
(read-column-by-index (.getObject rs i) (:rsmeta @builder) i))
|
(read-column-by-index (.getObject rs i) (:rsmeta @builder) i))
|
||||||
(read-column-by-label (.getObject rs ^String (name-fn k)) ^String (name-fn k)))
|
(read-column-by-label (.getObject rs ^String (name-fn k)) ^String (name-fn k)))
|
||||||
(catch SQLException _)))
|
(catch SQLException _)))
|
||||||
(valAt [this k not-found]
|
(valAt [_this k not-found]
|
||||||
(try
|
(try
|
||||||
(if (number? k)
|
(if (number? k)
|
||||||
(let [^Integer i (inc k)]
|
(let [^Integer i (inc k)]
|
||||||
|
|
@ -558,12 +558,12 @@
|
||||||
|
|
||||||
;; we support nth for array-based builders (i is primitive int here!):
|
;; we support nth for array-based builders (i is primitive int here!):
|
||||||
clojure.lang.Indexed
|
clojure.lang.Indexed
|
||||||
(nth [this i]
|
(nth [_this i]
|
||||||
(try
|
(try
|
||||||
(let [i (inc i)]
|
(let [i (inc i)]
|
||||||
(read-column-by-index (.getObject rs i) (:rsmeta @builder) i))
|
(read-column-by-index (.getObject rs i) (:rsmeta @builder) i))
|
||||||
(catch SQLException _)))
|
(catch SQLException _)))
|
||||||
(nth [this i not-found]
|
(nth [_this i not-found]
|
||||||
(try
|
(try
|
||||||
(let [i (inc i)]
|
(let [i (inc i)]
|
||||||
(read-column-by-index (.getObject rs i) (:rsmeta @builder) i))
|
(read-column-by-index (.getObject rs i) (:rsmeta @builder) i))
|
||||||
|
|
@ -571,11 +571,11 @@
|
||||||
not-found)))
|
not-found)))
|
||||||
|
|
||||||
clojure.lang.Seqable
|
clojure.lang.Seqable
|
||||||
(seq [this]
|
(seq [_this]
|
||||||
(seq (row-builder @builder)))
|
(seq (row-builder @builder)))
|
||||||
|
|
||||||
DatafiableRow
|
DatafiableRow
|
||||||
(datafiable-row [this connectable opts]
|
(datafiable-row [_this connectable opts]
|
||||||
;; since we have to call these eagerly, we trap any exceptions so
|
;; since we have to call these eagerly, we trap any exceptions so
|
||||||
;; that they can be thrown when the actual functions are called
|
;; that they can be thrown when the actual functions are called
|
||||||
(let [row (try (.getRow rs) (catch Throwable t t))
|
(let [row (try (.getRow rs) (catch Throwable t t))
|
||||||
|
|
|
||||||
|
|
@ -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
|
(ns next.jdbc.types
|
||||||
"Provides convenience functions for wrapping values you pass into SQL
|
"Provides convenience functions for wrapping values you pass into SQL
|
||||||
operations that have per-instance implementations of `SettableParameter`
|
operations that have per-instance implementations of `SettableParameter`
|
||||||
so that `.setObject()` is called with the appropriate `java.sql.Types` value."
|
so that `.setObject()` is called with the appropriate `java.sql.Types` value."
|
||||||
(:require [clojure.string :as str]
|
(:require [clojure.string :as str]
|
||||||
[next.jdbc.prepare :as prep])
|
[next.jdbc.prepare])
|
||||||
(:import (java.lang.reflect Field Modifier)
|
(:import (java.lang.reflect Field Modifier)
|
||||||
(java.sql PreparedStatement)))
|
(java.sql PreparedStatement)))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue