diff --git a/.github/workflows/test-and-release.yml b/.github/workflows/test-and-release.yml index d230216..ab4c541 100644 --- a/.github/workflows/test-and-release.yml +++ b/.github/workflows/test-and-release.yml @@ -19,7 +19,7 @@ jobs: - name: Setup Clojure uses: DeLaGuardo/setup-clojure@master with: - cli: '1.12.0.1479' + cli: '1.12.0.1488' - name: Cache All The Things uses: actions/cache@v4 with: diff --git a/.github/workflows/test-and-snapshot.yml b/.github/workflows/test-and-snapshot.yml index ca60996..a932628 100644 --- a/.github/workflows/test-and-snapshot.yml +++ b/.github/workflows/test-and-snapshot.yml @@ -17,7 +17,7 @@ jobs: - name: Setup Clojure uses: DeLaGuardo/setup-clojure@master with: - cli: '1.12.0.1479' + cli: '1.12.0.1488' - name: Cache All The Things uses: actions/cache@v4 with: @@ -64,7 +64,7 @@ jobs: - name: Setup Clojure uses: DeLaGuardo/setup-clojure@master with: - cli: '1.12.0.1479' + cli: '1.12.0.1488' - name: Cache All The Things uses: actions/cache@v4 with: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a5a3833..87b2fc4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,7 +17,7 @@ jobs: - name: Setup Clojure uses: DeLaGuardo/setup-clojure@master with: - cli: '1.12.0.1479' + cli: '1.12.0.1488' - name: Cache All The Things uses: actions/cache@v4 with: diff --git a/.gitpod.dockerfile b/.gitpod.dockerfile deleted file mode 100644 index ad0dc02..0000000 --- a/.gitpod.dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM gitpod/workspace-full - -RUN brew install clojure/tools/clojure@1.12.0.1479 diff --git a/.gitpod.yml b/.gitpod.yml deleted file mode 100644 index c0ef6c2..0000000 --- a/.gitpod.yml +++ /dev/null @@ -1,23 +0,0 @@ -image: - file: .gitpod.dockerfile - -vscode: - extensions: - - betterthantomorrow.calva - - mauricioszabo.clover - -tasks: - - name: Prepare deps/clover - init: | - clojure -A:test -P - echo 50505 > .socket-repl-port - mkdir ~/.config/clover - cp .clover/config.cljs ~/.config/clover/ - - name: Start REPL - command: clojure -J-Dclojure.server.repl="{:address \"0.0.0.0\" :port 50505 :accept clojure.core.server/repl}" -A:test - - name: See Changes - command: code CHANGELOG.md - -github: - prebuilds: - develop: true diff --git a/CHANGELOG.md b/CHANGELOG.md index 71fc70c..7a40ffd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,16 +3,20 @@ Only accretive/fixative changes will be made from now on. * 1.3.next in progress + * Update dev/test dependencies. + +* 1.3.967 -- 2024-12-02 * Address [#288](https://github.com/seancorfield/next-jdbc/issues/288) by adding speculative support for `:dbtype "xtdb"`. * Fix [#287](https://github.com/seancorfield/next-jdbc/issues/287) by merging user-supplied options over `:return-keys true`. * Fix [#282](https://github.com/seancorfield/next-jdbc/issues/282) by tracking raw `Connection` objects for active TXs, which relaxes several of the conditions around nested transactions. + * Replace `assert` calls with proper validation, throwing `IllegalArgumentException` on failure. * Removed (experimental) `:name-fn` option since the driver for it no longer exists (qualified columns names in XTDB). * 1.3.955 -- 2024-10-06 * Address [#285](https://github.com/seancorfield/next-jdbc/issues/285) by setting the default Clojure version to the earliest supported (1.10.3) to give a better hint to users. * Update PostgreSQL **Tips & Tricks** example code to fix possible NPE. PR [#284](https://github.com/seancorfield/next-jdbc/pull/284) from [@ExNexu](https://github.com/ExNexu). * Address [#283](https://github.com/seancorfield/next-jdbc/issues/283) by adding a note in the documentation, linking to the PostgreSQL bug report about `ANY(array)`. - * ~Address [#269](https://github.com/seancorfield/next-jdbc/issues/269) by adding `:name-fn` as an option (primarily for the SQL builder functions, but also for result set processing); the default is `clojure.core/name` but you can now use `next.jdbc.sql.builder/qualified-name` to preserve the qualifier.~ _[This was remove in 1.3.next since XTDB no longer supports qualified column names]_ + * ~Address [#269](https://github.com/seancorfield/next-jdbc/issues/269) by adding `:name-fn` as an option (primarily for the SQL builder functions, but also for result set processing); the default is `clojure.core/name` but you can now use `next.jdbc.sql.builder/qualified-name` to preserve the qualifier.~ _[This was removed in 1.3.967 since XTDB no longer supports qualified column names]_ * Update testing deps; `docker-compose` => `docker compose`. * 1.3.939 -- 2024-05-17 diff --git a/README.md b/README.md index 5c0338d..ba3fd5e 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,8 @@ The next generation of `clojure.java.jdbc`: a new low-level Clojure wrapper for The latest versions on Clojars and on cljdoc: -[![Clojars](https://img.shields.io/badge/clojars-com.github.seancorfield/next.jdbc_1.3.955-blue.svg?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAABjFBMVEUAAAAdCh0qDikdChwAAAAnDSY0EjM2FjUnDiYnDSYnDSYpDigyEDEEAQRGNUb///////8mDSYAAAAAAAAAAAAFAgUqEyoAAAAAAAAAAAAFAgUAAABXU1c2FjVMx+dQx+f///////9Nx+b////4/f6y4vRPt+RQtOT///9Qt+P///8oDSey4vRQr9/////3/P5hzelNx+dNx+dNx+f///8AAAAuDy0zETIAAAAoDScAAAAAAAARBREAAAAvDy40ETMwEC9gSF+Ne42ilKKuoK6Rg5B5ZXlaP1o4Gzf///9nTWZ4YncyEDF/bn/8/Pz9/P339/c1FTUlDCRRM1AbCRtlS2QyEDEuDy1gRWAxEDAzETIwEC/g4OAvDy40EjOaiZorDiq9sbzNyM3UzdQyEDE0ETMzETKflZ/UzdQ5Fzmu4fNYyuhNx+dPt+RLu9xQyOhBbo81GTuW2vCo4PJNx+c4MFE5N1lHiLFEhKQyEDGDboMzETI5Fjh5bXje2d57aHrIw8jc2NyWhJUrDioxe9o4AAAAPnRSTlMAkf+IAQj9+e7n6e31RtqAD/QAAAED+A0ZEQ8DwvkLBsmcR4aG8+cdAD6C8/MC94eP+qoTrgH+/wj1HA8eEvpXOCUAAAABYktHRA8YugDZAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3wcHFjou4Z/shwAAAUpJREFUOMul0/VTwzAUB/AAwyW4y3B3h8EDNuTh7u6UDHcd8I+TbHSjWdrjju/1h77kc+3Lu5aQvyakF/r6B5wu1+DQMEBomLRtG0EpozYDCEccA4iIjIqOiY0bB5iYxHgZ4FQCpYneKmmal0aQPMOXZnUAvJhLkbpInf8NFtKCTrGImK6DJcTlDGl/BXGV6oCsrSNIYAM3aQDwl2xJYBtBB5lZAuyYgWzY3YMcNcjN2wc4EGMEFTg8+hlyfgEenygAj71Q9FBExH0wKC4p1bRTJlJWXqEAVNM05ovbXfkPAHBmAUQPAGaAsXMBLiwA8z3h0gRcsWsObuAWLJu8Awb3ZoB5T8EvS/CgBo9Y5Z8TPwXBJwlUI9Ia/yRrEZ8lID71Olrf0MiamkkL4kurDEjba+C/e2sninR0wrsH8eMTvrqIWbodjh7jyjdtCY3Aniz4jwAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAxNS0wNy0wN1QyMjo1ODo0NiswMjowMCgWtSoAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMTUtMDctMDdUMjI6NTg6NDYrMDI6MDBZSw2WAAAAAElFTkSuQmCC)](https://clojars.org/com.github.seancorfield/next.jdbc) -[![cljdoc](https://cljdoc.org/badge/com.github.seancorfield/next.jdbc?1.3.955)](https://cljdoc.org/d/com.github.seancorfield/next.jdbc/CURRENT) +[![Clojars](https://img.shields.io/badge/clojars-com.github.seancorfield/next.jdbc_1.3.967-blue.svg?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAABjFBMVEUAAAAdCh0qDikdChwAAAAnDSY0EjM2FjUnDiYnDSYnDSYpDigyEDEEAQRGNUb///////8mDSYAAAAAAAAAAAAFAgUqEyoAAAAAAAAAAAAFAgUAAABXU1c2FjVMx+dQx+f///////9Nx+b////4/f6y4vRPt+RQtOT///9Qt+P///8oDSey4vRQr9/////3/P5hzelNx+dNx+dNx+f///8AAAAuDy0zETIAAAAoDScAAAAAAAARBREAAAAvDy40ETMwEC9gSF+Ne42ilKKuoK6Rg5B5ZXlaP1o4Gzf///9nTWZ4YncyEDF/bn/8/Pz9/P339/c1FTUlDCRRM1AbCRtlS2QyEDEuDy1gRWAxEDAzETIwEC/g4OAvDy40EjOaiZorDiq9sbzNyM3UzdQyEDE0ETMzETKflZ/UzdQ5Fzmu4fNYyuhNx+dPt+RLu9xQyOhBbo81GTuW2vCo4PJNx+c4MFE5N1lHiLFEhKQyEDGDboMzETI5Fjh5bXje2d57aHrIw8jc2NyWhJUrDioxe9o4AAAAPnRSTlMAkf+IAQj9+e7n6e31RtqAD/QAAAED+A0ZEQ8DwvkLBsmcR4aG8+cdAD6C8/MC94eP+qoTrgH+/wj1HA8eEvpXOCUAAAABYktHRA8YugDZAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3wcHFjou4Z/shwAAAUpJREFUOMul0/VTwzAUB/AAwyW4y3B3h8EDNuTh7u6UDHcd8I+TbHSjWdrjju/1h77kc+3Lu5aQvyakF/r6B5wu1+DQMEBomLRtG0EpozYDCEccA4iIjIqOiY0bB5iYxHgZ4FQCpYneKmmal0aQPMOXZnUAvJhLkbpInf8NFtKCTrGImK6DJcTlDGl/BXGV6oCsrSNIYAM3aQDwl2xJYBtBB5lZAuyYgWzY3YMcNcjN2wc4EGMEFTg8+hlyfgEenygAj71Q9FBExH0wKC4p1bRTJlJWXqEAVNM05ovbXfkPAHBmAUQPAGaAsXMBLiwA8z3h0gRcsWsObuAWLJu8Awb3ZoB5T8EvS/CgBo9Y5Z8TPwXBJwlUI9Ia/yRrEZ8lID71Olrf0MiamkkL4kurDEjba+C/e2sninR0wrsH8eMTvrqIWbodjh7jyjdtCY3Aniz4jwAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAxNS0wNy0wN1QyMjo1ODo0NiswMjowMCgWtSoAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMTUtMDctMDdUMjI6NTg6NDYrMDI6MDBZSw2WAAAAAElFTkSuQmCC)](https://clojars.org/com.github.seancorfield/next.jdbc) +[![cljdoc](https://cljdoc.org/badge/com.github.seancorfield/next.jdbc?1.3.967)](https://cljdoc.org/d/com.github.seancorfield/next.jdbc/CURRENT) [![Slack](https://img.shields.io/badge/slack-next.jdbc-orange.svg?logo=slack)](https://clojurians.slack.com/app_redirect?channel=sql) [![Join Slack](https://img.shields.io/badge/slack-join_clojurians-orange.svg?logo=slack)](http://clojurians.net) @@ -20,7 +20,7 @@ The documentation on [cljdoc.org](https://cljdoc.org/d/com.github.seancorfield/n * [Migrating from `clojure.java.jdbc`](https://cljdoc.org/d/com.github.seancorfield/next.jdbc/CURRENT/doc/migration-from-clojure-java-jdbc) * Feedback via [issues](https://github.com/seancorfield/next-jdbc/issues) or in the [`#sql` channel on the Clojurians Slack](https://clojurians.slack.com/messages/C1Q164V29/) or the [`#sql` stream on the Clojurians Zulip](https://clojurians.zulipchat.com/#narrow/stream/152063-sql). -The documentation on GitHub is for **develop** since the 1.3.955 release -- [see the CHANGELOG](https://github.com/seancorfield/next-jdbc/blob/develop/CHANGELOG.md) and then read the [corresponding updated documentation](https://github.com/seancorfield/next-jdbc/tree/develop/doc) on GitHub if you want. Older versions of `next.jdbc` were published under the `seancorfield` group ID and you can find [older seancorfield/next.jdbc documentation on cljdoc.org](https://cljdoc.org/versions/seancorfield/next.jdbc). +The documentation on GitHub is for **develop** since the 1.3.967 release -- [see the CHANGELOG](https://github.com/seancorfield/next-jdbc/blob/develop/CHANGELOG.md) and then read the [corresponding updated documentation](https://github.com/seancorfield/next-jdbc/tree/develop/doc) on GitHub if you want. Older versions of `next.jdbc` were published under the `seancorfield` group ID and you can find [older seancorfield/next.jdbc documentation on cljdoc.org](https://cljdoc.org/versions/seancorfield/next.jdbc). This project follows the version scheme MAJOR.MINOR.COMMITS where MAJOR and MINOR provide some relative indication of the size of the change, but do not follow semantic versioning. In general, all changes endeavor to be non-breaking (by moving to new names rather than by breaking existing names). COMMITS is an ever-increasing counter of commits since the beginning of this repository. diff --git a/deps.edn b/deps.edn index 0ae12bb..32e32d2 100644 --- a/deps.edn +++ b/deps.edn @@ -7,7 +7,7 @@ camel-snake-kebab/camel-snake-kebab {:mvn/version "0.4.3"}} :aliases {;; for help: clojure -A:deps -T:build help/doc - :build {:deps {io.github.clojure/tools.build {:mvn/version "0.10.5"} + :build {:deps {io.github.clojure/tools.build {:mvn/version "0.10.6"} slipset/deps-deploy {:mvn/version "0.2.2"}} :ns-default build} @@ -22,33 +22,33 @@ io.github.cognitect-labs/test-runner {:git/tag "v0.5.1" :git/sha "dfb30dd"} ;; connection pooling - com.zaxxer/HikariCP {:mvn/version "6.0.0"} + com.zaxxer/HikariCP {:mvn/version "6.2.1"} com.mchange/c3p0 {:mvn/version "0.10.1"} ;; JDBC drivers ;; 10.16.x is JDK17+ org.apache.derby/derby {:mvn/version "10.15.2.0"} org.apache.derby/derbyshared {:mvn/version "10.15.2.0"} - org.hsqldb/hsqldb {:mvn/version "2.7.3"} + org.hsqldb/hsqldb {:mvn/version "2.7.4"} com.h2database/h2 {:mvn/version "2.3.232"} net.sourceforge.jtds/jtds {:mvn/version "1.3.1"} - org.mariadb.jdbc/mariadb-java-client {:mvn/version "3.4.1"} - com.mysql/mysql-connector-j {:mvn/version "9.0.0"} + org.mariadb.jdbc/mariadb-java-client {:mvn/version "3.5.1"} + com.mysql/mysql-connector-j {:mvn/version "9.1.0"} ;; 42.7.4 changes update count (to -1) for stored procs: org.postgresql/postgresql {:mvn/version "42.7.4"} - io.zonky.test/embedded-postgres {:mvn/version "2.0.7"} - io.zonky.test.postgres/embedded-postgres-binaries-darwin-amd64 {:mvn/version "17.0.0"} - io.zonky.test.postgres/embedded-postgres-binaries-linux-amd64 {:mvn/version "17.0.0"} - io.zonky.test.postgres/embedded-postgres-binaries-windows-amd64 {:mvn/version "17.0.0"} - org.xerial/sqlite-jdbc {:mvn/version "3.46.1.3"} + io.zonky.test/embedded-postgres {:mvn/version "2.1.0"} + io.zonky.test.postgres/embedded-postgres-binaries-darwin-amd64 {:mvn/version "17.2.0"} + io.zonky.test.postgres/embedded-postgres-binaries-linux-amd64 {:mvn/version "17.2.0"} + io.zonky.test.postgres/embedded-postgres-binaries-windows-amd64 {:mvn/version "17.2.0"} + org.xerial/sqlite-jdbc {:mvn/version "3.47.1.0"} com.microsoft.sqlserver/mssql-jdbc {:mvn/version "12.8.1.jre11"} ;; prerelease XTDB JDBC module: com.xtdb/xtdb-jdbc {:mvn/version "2.0.0-SNAPSHOT"} ;; use log4j2 to reduce log noise during testing: - org.apache.logging.log4j/log4j-api {:mvn/version "2.24.0"} + org.apache.logging.log4j/log4j-api {:mvn/version "2.24.2"} ;; bridge everything into log4j: - org.apache.logging.log4j/log4j-1.2-api {:mvn/version "2.24.0"} - org.apache.logging.log4j/log4j-jcl {:mvn/version "2.24.0"} - org.apache.logging.log4j/log4j-jul {:mvn/version "2.24.0"} - org.apache.logging.log4j/log4j-slf4j-impl {:mvn/version "2.24.0"}} + org.apache.logging.log4j/log4j-1.2-api {:mvn/version "2.24.2"} + org.apache.logging.log4j/log4j-jcl {:mvn/version "2.24.2"} + org.apache.logging.log4j/log4j-jul {:mvn/version "2.24.2"} + org.apache.logging.log4j/log4j-slf4j-impl {:mvn/version "2.24.2"}} :jvm-opts ["-Dlog4j2.configurationFile=log4j2-info.properties"] :exec-fn cognitect.test-runner.api/test}}} diff --git a/doc/getting-started.md b/doc/getting-started.md index 50f13c5..90ec12e 100644 --- a/doc/getting-started.md +++ b/doc/getting-started.md @@ -11,12 +11,12 @@ It is designed to work with Clojure 1.10 or later, supports `datafy`/`nav`, and You can add `next.jdbc` to your project with either: ```clojure -com.github.seancorfield/next.jdbc {:mvn/version "1.3.955"} +com.github.seancorfield/next.jdbc {:mvn/version "1.3.967"} ``` for `deps.edn` or: ```clojure -[com.github.seancorfield/next.jdbc "1.3.955"] +[com.github.seancorfield/next.jdbc "1.3.967"] ``` for `project.clj` or `build.boot`. @@ -38,7 +38,7 @@ For the examples in this documentation, we will use a local H2 database on disk, ```clojure ;; deps.edn {:deps {org.clojure/clojure {:mvn/version "1.12.0"} - com.github.seancorfield/next.jdbc {:mvn/version "1.3.955"} + com.github.seancorfield/next.jdbc {:mvn/version "1.3.967"} com.h2database/h2 {:mvn/version "2.2.224"}}} ``` diff --git a/src/next/jdbc/result_set.clj b/src/next/jdbc/result_set.clj index 962d66d..cb30397 100644 --- a/src/next/jdbc/result_set.clj +++ b/src/next/jdbc/result_set.clj @@ -58,6 +58,9 @@ (mapv (fn [^Integer i] (keyword (.getColumnLabel rsmeta i))) (range 1 (inc (if rsmeta (.getColumnCount rsmeta) 0))))) +(defn- validate [expr ^String msg] + (when-not expr (throw (IllegalArgumentException. msg)))) + (defn get-modified-column-names "Given `ResultSetMetaData`, return a vector of modified column names, each qualified by the table from which it came. @@ -66,8 +69,8 @@ [^ResultSetMetaData rsmeta opts] (let [qf (:qualifier-fn opts) lf (:label-fn opts)] - (assert qf ":qualifier-fn is required") - (assert lf ":label-fn is required") + (validate qf ":qualifier-fn is required") + (validate lf ":label-fn is required") (mapv (fn [^Integer i] (if-let [q (some-> (get-table-name rsmeta i) (qf) (not-empty))] (keyword q (-> (.getColumnLabel rsmeta i) (lf))) @@ -81,7 +84,7 @@ Requires the `:label-fn` option." [^ResultSetMetaData rsmeta opts] (let [lf (:label-fn opts)] - (assert lf ":label-fn is required") + (validate lf ":label-fn is required") (mapv (fn [^Integer i] (keyword (lf (.getColumnLabel rsmeta i)))) (range 1 (inc (if rsmeta (.getColumnCount rsmeta) 0)))))) @@ -910,7 +913,7 @@ (first sql-params) (rest sql-params) opts)] - (reduce-stmt stmt f init opts))) + (reduce-stmt stmt f init opts))) r/CollFold (coll-fold [_ n combinef reducef] (with-open [con (p/get-connection this opts) @@ -926,12 +929,12 @@ (first sql-params) (rest sql-params) opts)] - (if-let [rs (stmt->result-set stmt opts)] - (let [builder-fn (get opts :builder-fn as-maps) - builder (builder-fn rs opts)] - (when (.next rs) - (datafiable-row (row-builder builder) this opts))) - {:next.jdbc/update-count (.getUpdateCount stmt)}))) + (if-let [rs (stmt->result-set stmt opts)] + (let [builder-fn (get opts :builder-fn as-maps) + builder (builder-fn rs opts)] + (when (.next rs) + (datafiable-row (row-builder builder) this opts))) + {:next.jdbc/update-count (.getUpdateCount stmt)}))) (-execute-all [this sql-params opts] (with-open [con (p/get-connection this opts) stmt (prepare/create con @@ -982,8 +985,8 @@ java.sql.Statement (-execute [this sql-params opts] - (assert (= 1 (count sql-params)) - "Parameters cannot be provided when executing a non-prepared Statement") + (validate (= 1 (count sql-params)) + "Parameters cannot be provided when executing a non-prepared Statement") (reify clojure.lang.IReduceInit (reduce [_ f init] @@ -994,8 +997,8 @@ (.getConnection this) opts)) (toString [_] "`IReduceInit` from `plan` -- missing reduction?"))) (-execute-one [this sql-params opts] - (assert (= 1 (count sql-params)) - "Parameters cannot be provided when executing a non-prepared Statement") + (validate (= 1 (count sql-params)) + "Parameters cannot be provided when executing a non-prepared Statement") (if-let [rs (stmt-sql->result-set this (first sql-params))] (let [builder-fn (get opts :builder-fn as-maps) builder (builder-fn rs opts)] @@ -1004,8 +1007,8 @@ (.getConnection this) opts))) {:next.jdbc/update-count (.getUpdateCount this)})) (-execute-all [this sql-params opts] - (assert (= 1 (count sql-params)) - "Parameters cannot be provided when executing a non-prepared Statement") + (validate (= 1 (count sql-params)) + "Parameters cannot be provided when executing a non-prepared Statement") (if (:multi-rs opts) (loop [go (.execute this (first sql-params)) acc []] (if-let [rs (stmt->result-set-update-count diff --git a/src/next/jdbc/sql/builder.clj b/src/next/jdbc/sql/builder.clj index f42c3b2..802597c 100644 --- a/src/next/jdbc/sql/builder.clj +++ b/src/next/jdbc/sql/builder.clj @@ -70,6 +70,9 @@ [key-map opts] (as-cols (keys key-map) opts)) +(defn- validate [expr ^String msg] + (when-not expr (throw (IllegalArgumentException. msg)))) + (defn by-keys "Given a hash map of column names and values and a clause type (`:set`, `:where`), return a vector of a SQL clause and its parameters. @@ -84,7 +87,7 @@ [(conj conds (str e " = ?")) (conj params v)]))) [[] []] key-map)] - (assert (seq where) "key-map may not be empty") + (validate (seq where) "key-map may not be empty") (into [(str (str/upper-case (safe-name clause)) " " (str/join (if (= :where clause) " AND " ", ") where))] params))) @@ -122,7 +125,7 @@ (let [entity-fn (:table-fn opts identity) params (as-keys key-map opts) places (as-? key-map opts)] - (assert (seq key-map) "key-map may not be empty") + (validate (seq key-map) "key-map may not be empty") (into [(str "INSERT INTO " (entity-fn (safe-name table)) " (" params ")" " VALUES (" places ")" @@ -144,11 +147,11 @@ If `:suffix` is provided in `opts`, that string is appended to the `INSERT ...` statement." [table cols rows opts] - (assert (apply = (count cols) (map count rows)) - "column counts are not consistent across cols and rows") + (validate (apply = (count cols) (map count rows)) + "column counts are not consistent across cols and rows") ;; to avoid generating bad SQL - (assert (seq cols) "cols may not be empty") - (assert (seq rows) "rows may not be empty") + (validate (seq cols) "cols may not be empty") + (validate (seq rows) "rows may not be empty") (let [table-fn (:table-fn opts identity) batch? (:batch opts) params (as-cols cols opts) @@ -195,7 +198,7 @@ [order-by opts] (when-not (vector? order-by) (throw (IllegalArgumentException. ":order-by must be a vector"))) - (assert (seq order-by) ":order-by may not be empty") + (validate (seq order-by) ":order-by may not be empty") (str "ORDER BY " (str/join ", " (map #(for-order-col % opts) order-by)))) diff --git a/test/next/jdbc/sql/builder_test.clj b/test/next/jdbc/sql/builder_test.clj index 38e60d1..1d577bf 100644 --- a/test/next/jdbc/sql/builder_test.clj +++ b/test/next/jdbc/sql/builder_test.clj @@ -158,7 +158,7 @@ (deftest test-for-update (testing "empty example (would be a SQL error)" - (is (thrown? AssertionError ; changed in #44 + (is (thrown? IllegalArgumentException (builder/for-update :user {:status 42} {}