Skip to content

Commit

Permalink
clj-kondo changes
Browse files Browse the repository at this point in the history
  • Loading branch information
csummers committed Jul 29, 2023
1 parent 7a977c2 commit a806bdf
Show file tree
Hide file tree
Showing 13 changed files with 189 additions and 194 deletions.
8 changes: 5 additions & 3 deletions .clj-kondo/config.edn
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{:linters {:refer-all {:exclude [clojure.test]}
:unused-binding {:exclude-destructured-as true
:exclude-destructured-keys-in-fn-args true}}}
{:linters {:refer-all {:exclude [clojure.test]}
:unused-binding {:exclude-unused-as true
:exclude-destructured-as true
:exclude-destructured-keys-in-fn-args true}}
:skip-comments true}
4 changes: 4 additions & 0 deletions .github/workflows/lint-test-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ jobs:
uses: DeLaGuardo/setup-clojure@11.0
with:
cli: "latest"
clj-kondo: "latest"

- name: Clojure
run: clojure -P -M:test

- name: Lint
run: clj-kondo --lint ./

- name: Test
run: bin/kaocha :core
3 changes: 1 addition & 2 deletions examples/princess-bride/src/princess_bride/db.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
(ns princess-bride.db
(:require [hugsql.core :as hugsql]))
(ns princess-bride.db)

(def db
{:subprotocol "h2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@
(deftype HugsqlAdapterClojureJavaJdbc []

adapter/HugsqlAdapter
(execute [this db sqlvec options]
(execute [_ db sqlvec options]
(if (some #(= % (:command options)) [:insert :i!])
(jdbc/db-do-prepared-return-keys db sqlvec)
(apply jdbc/execute! db sqlvec (:command-options options))))

(query [this db sqlvec options]
(query [_ db sqlvec options]
(apply jdbc/query db sqlvec (:command-options options)))

(result-one [this result options]
(result-one [_ result _options]
(first result))

(result-many [this result options]
(result-many [_ result _options]
result)

(result-affected [this result options]
(result-affected [_ result _options]
(first result))

(result-raw [this result options]
(result-raw [_ result _options]
result)

(on-exception [this exception]
(on-exception [_ exception]
(throw exception)))

(defn hugsql-adapter-clojure-java-jdbc []
Expand Down
14 changes: 7 additions & 7 deletions hugsql-adapter-clojure-jdbc/src/hugsql/adapter/clojure_jdbc.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@
(deftype HugsqlAdapterClojureJdbc []

adapter/HugsqlAdapter
(execute [this db sqlvec options]
(execute [_ db sqlvec options]
(jdbc/execute db sqlvec
(merge {:returning (some #(= % (:command options)) [:insert :i!])}
(:command-options options))))

(query [this db sqlvec options]
(query [_ db sqlvec options]
(jdbc/fetch db sqlvec (:command-options options)))

(result-one [this result options]
(result-one [_ result _options]
(first result))

(result-many [this result options]
(result-many [_ result _options]
result)

(result-affected [this result options]
(result-affected [_ result _options]
result)

(result-raw [this result options]
(result-raw [_ result _options]
result)

(on-exception [this exception]
(on-exception [_ exception]
(throw exception)))

(defn hugsql-adapter-clojure-jdbc []
Expand Down
18 changes: 9 additions & 9 deletions hugsql-adapter-next-jdbc/src/hugsql/adapter/next_jdbc.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@
(deftype HugsqlAdapterNextJdbc [default-command-options]

adapter/HugsqlAdapter
(execute [this db sqlvec {:keys [command-options]
:or {command-options default-command-options}
:as options}]
(execute [_ db sqlvec {:keys [command-options]
:or {command-options default-command-options}
:as options}]
(jdbc/execute! db sqlvec
(if (some #(= % (:command options)) [:insert :i!])
(assoc command-options :return-keys true)
command-options)))

(query [this db sqlvec options]
(query [_ db sqlvec options]
(jdbc/execute! db sqlvec (or (:command-options options) default-command-options)))

(result-one [this result options]
(result-one [_ result _options]
(first result))

(result-many [this result options]
(result-many [_ result _options]
result)

(result-affected [this result options]
(result-affected [_ result _options]
(:next.jdbc/update-count (first result)))

(result-raw [this result options]
(result-raw [_ result _options]
result)

(on-exception [this exception]
(on-exception [_ exception]
(throw exception)))

(defn hugsql-adapter-next-jdbc
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
(ns hugsql-adapter-next-jdbc.core-test
(:require [clojure.test :refer :all]
[next.jdbc.result-set :as result-set]
[hugsql.core :as hugsql]
[hugsql.adapter.next-jdbc :as next-jdbc]))
[hugsql.adapter.next-jdbc :as next-jdbc]
[next.jdbc.result-set :as result-set]
[hugsql-adapter-next-jdbc.core_test.sql :as sql]))


(hugsql/def-db-fns "./hugsql_adapter_next_jdbc/queries.sql")
(hugsql/set-adapter! (next-jdbc/hugsql-adapter-next-jdbc))

(def conn {:dbtype "h2:mem" :dbname "test"})

(deftest create-table-test
(testing "Can create a table."
(is (not (nil? (create-colors-table conn))))))
(is (not (nil? (sql/create-colors-table conn))))))

(deftest row-tests
(testing "Can insert a row."
(is (= (insert-color conn {:name "ocher" :r 204 :g 119 :b 34})
(is (= (sql/insert-color conn {:name "ocher" :r 204 :g 119 :b 34})
[{:next.jdbc/update-count 1}])))
(testing "Can insert another row."
(is (= (insert-color conn {:name "crimson" :r 220 :g 20 :b 60})
(is (= (sql/insert-color conn {:name "crimson" :r 220 :g 20 :b 60})
[{:next.jdbc/update-count 1}])))
(testing ":insert command test"
(is (= (insert-color-alt conn {:name "crimson" :r 220 :g 20 :b 60})
(is (= (sql/insert-color-alt conn {:name "crimson" :r 220 :g 20 :b 60})
[{:COLORS/ID 3}])))
(testing "Can insert and return affected rows"
(is (= (update-color-affected conn {:r 100})
(is (= (sql/update-color-affected conn {:r 100})
3)))
(testing "Can select a row."
(is (= (:COLORS/ID (select-color-by-id conn {:id 1}))
(is (= (:COLORS/ID (sql/select-color-by-id conn {:id 1}))
1)))
(testing "Can select multiple rows."
(is (= (count (select-all-colors conn))
(is (= (count (sql/select-all-colors conn))
3))))

(deftest custom-builder-fn-test
(hugsql/set-adapter! (next-jdbc/hugsql-adapter-next-jdbc {:builder-fn result-set/as-unqualified-maps}))
(testing "Can select a row w/ custom builder fn"
(is (= (:ID (select-color-by-id conn {:id 1}))
(is (= (:ID (sql/select-color-by-id conn {:id 1}))
1))))
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(ns hugsql-adapter-next-jdbc.core-test.sql
(:require [hugsql.core :as hugsql]))

(hugsql/def-db-fns "hugsql_adapter_next_jdbc/queries.sql")
14 changes: 7 additions & 7 deletions hugsql-adapter/src/hugsql/adapter.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
(defprotocol HugsqlAdapter
"Hugsql Adapter Protocol"

(execute [this db sqlvec options]
(execute [_ db sqlvec options]
"Execute SQL/DDL/DML statement")

(query [this db sqlvec options]
(query [_ db sqlvec options]
"Query SQL statement (expecting result set)")

(result-one [this result options]
(result-one [_ result options]
"Result: returns one hashmap record")

(result-many [this result options]
(result-many [_ result options]
"Result: returns vector of hashmap records")

(result-affected [this result options]
(result-affected [_ result options]
"Result: returns integer of affected rows/records")

(result-raw [this result options]
(result-raw [_ result options]
"Result: returns raw result, untouched")

(on-exception [this exception]
(on-exception [_ exception]
"Exception handler allows adapter to redirect exceptions from HugSQL"))
10 changes: 5 additions & 5 deletions hugsql-core/src/hugsql/parameters.clj
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@
;; Default Object implementations
(extend-type Object
ValueParam
(value-param [param data options]
(value-param [param data _options]
["?" (get-in data (deep-get-vec (:name param)))])

ValueParamList
(value-param-list [param data options]
(value-param-list [param data _options]
(let [coll (get-in data (deep-get-vec (:name param)))]
(apply vector
(string/join "," (repeat (count coll) "?"))
Expand Down Expand Up @@ -130,15 +130,15 @@
(into [] (get-in data (deep-get-vec (:name param))))))])

SQLParam
(sql-param [param data options]
(sql-param [param data _options]
[(get-in data (deep-get-vec (:name param)))])

SQLVecParam
(sqlvec-param [param data options]
(sqlvec-param [param data _options]
(get-in data (deep-get-vec (:name param))))

SQLVecParamList
(sqlvec-param-list [param data options]
(sqlvec-param-list [param data _options]
(reduce
#(apply vector
(string/join " " [(first %1) (first %2)])
Expand Down
Loading

0 comments on commit a806bdf

Please sign in to comment.