Merge branch 'develop' into xtdb-testing

This commit is contained in:
Sean Corfield 2024-12-02 19:01:43 -08:00
commit 80748a9593
12 changed files with 60 additions and 76 deletions

View file

@ -19,7 +19,7 @@ jobs:
- name: Setup Clojure - name: Setup Clojure
uses: DeLaGuardo/setup-clojure@master uses: DeLaGuardo/setup-clojure@master
with: with:
cli: '1.12.0.1479' cli: '1.12.0.1488'
- name: Cache All The Things - name: Cache All The Things
uses: actions/cache@v4 uses: actions/cache@v4
with: with:

View file

@ -17,7 +17,7 @@ jobs:
- name: Setup Clojure - name: Setup Clojure
uses: DeLaGuardo/setup-clojure@master uses: DeLaGuardo/setup-clojure@master
with: with:
cli: '1.12.0.1479' cli: '1.12.0.1488'
- name: Cache All The Things - name: Cache All The Things
uses: actions/cache@v4 uses: actions/cache@v4
with: with:
@ -64,7 +64,7 @@ jobs:
- name: Setup Clojure - name: Setup Clojure
uses: DeLaGuardo/setup-clojure@master uses: DeLaGuardo/setup-clojure@master
with: with:
cli: '1.12.0.1479' cli: '1.12.0.1488'
- name: Cache All The Things - name: Cache All The Things
uses: actions/cache@v4 uses: actions/cache@v4
with: with:

View file

@ -17,7 +17,7 @@ jobs:
- name: Setup Clojure - name: Setup Clojure
uses: DeLaGuardo/setup-clojure@master uses: DeLaGuardo/setup-clojure@master
with: with:
cli: '1.12.0.1479' cli: '1.12.0.1488'
- name: Cache All The Things - name: Cache All The Things
uses: actions/cache@v4 uses: actions/cache@v4
with: with:

View file

@ -1,3 +0,0 @@
FROM gitpod/workspace-full
RUN brew install clojure/tools/clojure@1.12.0.1479

View file

@ -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

View file

@ -3,16 +3,20 @@
Only accretive/fixative changes will be made from now on. Only accretive/fixative changes will be made from now on.
* 1.3.next in progress * 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"`. * 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 [#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. * 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). * Removed (experimental) `:name-fn` option since the driver for it no longer exists (qualified columns names in XTDB).
* 1.3.955 -- 2024-10-06 * 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. * 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). * 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 [#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`. * Update testing deps; `docker-compose` => `docker compose`.
* 1.3.939 -- 2024-05-17 * 1.3.939 -- 2024-05-17

View file

@ -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: 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) [![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.955)](https://cljdoc.org/d/com.github.seancorfield/next.jdbc/CURRENT) [![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) [![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) [![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) * [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). * 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. 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.

View file

@ -7,7 +7,7 @@
camel-snake-kebab/camel-snake-kebab {:mvn/version "0.4.3"}} camel-snake-kebab/camel-snake-kebab {:mvn/version "0.4.3"}}
:aliases :aliases
{;; for help: clojure -A:deps -T:build help/doc {;; 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"}} slipset/deps-deploy {:mvn/version "0.2.2"}}
:ns-default build} :ns-default build}
@ -22,33 +22,33 @@
io.github.cognitect-labs/test-runner io.github.cognitect-labs/test-runner
{:git/tag "v0.5.1" :git/sha "dfb30dd"} {:git/tag "v0.5.1" :git/sha "dfb30dd"}
;; connection pooling ;; 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"} com.mchange/c3p0 {:mvn/version "0.10.1"}
;; JDBC drivers ;; JDBC drivers
;; 10.16.x is JDK17+ ;; 10.16.x is JDK17+
org.apache.derby/derby {:mvn/version "10.15.2.0"} org.apache.derby/derby {:mvn/version "10.15.2.0"}
org.apache.derby/derbyshared {: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"} com.h2database/h2 {:mvn/version "2.3.232"}
net.sourceforge.jtds/jtds {:mvn/version "1.3.1"} net.sourceforge.jtds/jtds {:mvn/version "1.3.1"}
org.mariadb.jdbc/mariadb-java-client {:mvn/version "3.4.1"} org.mariadb.jdbc/mariadb-java-client {:mvn/version "3.5.1"}
com.mysql/mysql-connector-j {:mvn/version "9.0.0"} com.mysql/mysql-connector-j {:mvn/version "9.1.0"}
;; 42.7.4 changes update count (to -1) for stored procs: ;; 42.7.4 changes update count (to -1) for stored procs:
org.postgresql/postgresql {:mvn/version "42.7.4"} org.postgresql/postgresql {:mvn/version "42.7.4"}
io.zonky.test/embedded-postgres {:mvn/version "2.0.7"} io.zonky.test/embedded-postgres {:mvn/version "2.1.0"}
io.zonky.test.postgres/embedded-postgres-binaries-darwin-amd64 {:mvn/version "17.0.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.0.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.0.0"} io.zonky.test.postgres/embedded-postgres-binaries-windows-amd64 {:mvn/version "17.2.0"}
org.xerial/sqlite-jdbc {:mvn/version "3.46.1.3"} org.xerial/sqlite-jdbc {:mvn/version "3.47.1.0"}
com.microsoft.sqlserver/mssql-jdbc {:mvn/version "12.8.1.jre11"} com.microsoft.sqlserver/mssql-jdbc {:mvn/version "12.8.1.jre11"}
;; prerelease XTDB JDBC module: ;; prerelease XTDB JDBC module:
com.xtdb/xtdb-jdbc {:mvn/version "2.0.0-SNAPSHOT"} com.xtdb/xtdb-jdbc {:mvn/version "2.0.0-SNAPSHOT"}
;; use log4j2 to reduce log noise during testing: ;; 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: ;; bridge everything into log4j:
org.apache.logging.log4j/log4j-1.2-api {: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.0"} org.apache.logging.log4j/log4j-jcl {:mvn/version "2.24.2"}
org.apache.logging.log4j/log4j-jul {:mvn/version "2.24.0"} org.apache.logging.log4j/log4j-jul {:mvn/version "2.24.2"}
org.apache.logging.log4j/log4j-slf4j-impl {:mvn/version "2.24.0"}} org.apache.logging.log4j/log4j-slf4j-impl {:mvn/version "2.24.2"}}
:jvm-opts ["-Dlog4j2.configurationFile=log4j2-info.properties"] :jvm-opts ["-Dlog4j2.configurationFile=log4j2-info.properties"]
:exec-fn cognitect.test-runner.api/test}}} :exec-fn cognitect.test-runner.api/test}}}

View file

@ -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: You can add `next.jdbc` to your project with either:
```clojure ```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: for `deps.edn` or:
```clojure ```clojure
[com.github.seancorfield/next.jdbc "1.3.955"] [com.github.seancorfield/next.jdbc "1.3.967"]
``` ```
for `project.clj` or `build.boot`. 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 ```clojure
;; deps.edn ;; deps.edn
{:deps {org.clojure/clojure {:mvn/version "1.12.0"} {: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"}}} com.h2database/h2 {:mvn/version "2.2.224"}}}
``` ```

View file

@ -58,6 +58,9 @@
(mapv (fn [^Integer i] (keyword (.getColumnLabel rsmeta i))) (mapv (fn [^Integer i] (keyword (.getColumnLabel rsmeta i)))
(range 1 (inc (if rsmeta (.getColumnCount rsmeta) 0))))) (range 1 (inc (if rsmeta (.getColumnCount rsmeta) 0)))))
(defn- validate [expr ^String msg]
(when-not expr (throw (IllegalArgumentException. msg))))
(defn get-modified-column-names (defn get-modified-column-names
"Given `ResultSetMetaData`, return a vector of modified column names, each "Given `ResultSetMetaData`, return a vector of modified column names, each
qualified by the table from which it came. qualified by the table from which it came.
@ -66,8 +69,8 @@
[^ResultSetMetaData rsmeta opts] [^ResultSetMetaData rsmeta opts]
(let [qf (:qualifier-fn opts) (let [qf (:qualifier-fn opts)
lf (:label-fn opts)] lf (:label-fn opts)]
(assert qf ":qualifier-fn is required") (validate qf ":qualifier-fn is required")
(assert lf ":label-fn is required") (validate lf ":label-fn is required")
(mapv (fn [^Integer i] (mapv (fn [^Integer i]
(if-let [q (some-> (get-table-name rsmeta i) (qf) (not-empty))] (if-let [q (some-> (get-table-name rsmeta i) (qf) (not-empty))]
(keyword q (-> (.getColumnLabel rsmeta i) (lf))) (keyword q (-> (.getColumnLabel rsmeta i) (lf)))
@ -81,7 +84,7 @@
Requires the `:label-fn` option." Requires the `:label-fn` option."
[^ResultSetMetaData rsmeta opts] [^ResultSetMetaData rsmeta opts]
(let [lf (:label-fn 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)))) (mapv (fn [^Integer i] (keyword (lf (.getColumnLabel rsmeta i))))
(range 1 (inc (if rsmeta (.getColumnCount rsmeta) 0)))))) (range 1 (inc (if rsmeta (.getColumnCount rsmeta) 0))))))
@ -910,7 +913,7 @@
(first sql-params) (first sql-params)
(rest sql-params) (rest sql-params)
opts)] opts)]
(reduce-stmt stmt f init opts))) (reduce-stmt stmt f init opts)))
r/CollFold r/CollFold
(coll-fold [_ n combinef reducef] (coll-fold [_ n combinef reducef]
(with-open [con (p/get-connection this opts) (with-open [con (p/get-connection this opts)
@ -926,12 +929,12 @@
(first sql-params) (first sql-params)
(rest sql-params) (rest sql-params)
opts)] opts)]
(if-let [rs (stmt->result-set stmt opts)] (if-let [rs (stmt->result-set stmt opts)]
(let [builder-fn (get opts :builder-fn as-maps) (let [builder-fn (get opts :builder-fn as-maps)
builder (builder-fn rs opts)] builder (builder-fn rs opts)]
(when (.next rs) (when (.next rs)
(datafiable-row (row-builder builder) this opts))) (datafiable-row (row-builder builder) this opts)))
{:next.jdbc/update-count (.getUpdateCount stmt)}))) {:next.jdbc/update-count (.getUpdateCount stmt)})))
(-execute-all [this sql-params opts] (-execute-all [this sql-params opts]
(with-open [con (p/get-connection this opts) (with-open [con (p/get-connection this opts)
stmt (prepare/create con stmt (prepare/create con
@ -982,8 +985,8 @@
java.sql.Statement java.sql.Statement
(-execute [this sql-params opts] (-execute [this sql-params opts]
(assert (= 1 (count sql-params)) (validate (= 1 (count sql-params))
"Parameters cannot be provided when executing a non-prepared Statement") "Parameters cannot be provided when executing a non-prepared Statement")
(reify (reify
clojure.lang.IReduceInit clojure.lang.IReduceInit
(reduce [_ f init] (reduce [_ f init]
@ -994,8 +997,8 @@
(.getConnection this) opts)) (.getConnection this) opts))
(toString [_] "`IReduceInit` from `plan` -- missing reduction?"))) (toString [_] "`IReduceInit` from `plan` -- missing reduction?")))
(-execute-one [this sql-params opts] (-execute-one [this sql-params opts]
(assert (= 1 (count sql-params)) (validate (= 1 (count sql-params))
"Parameters cannot be provided when executing a non-prepared Statement") "Parameters cannot be provided when executing a non-prepared Statement")
(if-let [rs (stmt-sql->result-set this (first sql-params))] (if-let [rs (stmt-sql->result-set this (first sql-params))]
(let [builder-fn (get opts :builder-fn as-maps) (let [builder-fn (get opts :builder-fn as-maps)
builder (builder-fn rs opts)] builder (builder-fn rs opts)]
@ -1004,8 +1007,8 @@
(.getConnection this) opts))) (.getConnection this) opts)))
{:next.jdbc/update-count (.getUpdateCount this)})) {:next.jdbc/update-count (.getUpdateCount this)}))
(-execute-all [this sql-params opts] (-execute-all [this sql-params opts]
(assert (= 1 (count sql-params)) (validate (= 1 (count sql-params))
"Parameters cannot be provided when executing a non-prepared Statement") "Parameters cannot be provided when executing a non-prepared Statement")
(if (:multi-rs opts) (if (:multi-rs opts)
(loop [go (.execute this (first sql-params)) acc []] (loop [go (.execute this (first sql-params)) acc []]
(if-let [rs (stmt->result-set-update-count (if-let [rs (stmt->result-set-update-count

View file

@ -70,6 +70,9 @@
[key-map opts] [key-map opts]
(as-cols (keys key-map) opts)) (as-cols (keys key-map) opts))
(defn- validate [expr ^String msg]
(when-not expr (throw (IllegalArgumentException. msg))))
(defn by-keys (defn by-keys
"Given a hash map of column names and values and a clause type "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. (`:set`, `:where`), return a vector of a SQL clause and its parameters.
@ -84,7 +87,7 @@
[(conj conds (str e " = ?")) (conj params v)]))) [(conj conds (str e " = ?")) (conj params v)])))
[[] []] [[] []]
key-map)] 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)) " " (into [(str (str/upper-case (safe-name clause)) " "
(str/join (if (= :where clause) " AND " ", ") where))] (str/join (if (= :where clause) " AND " ", ") where))]
params))) params)))
@ -122,7 +125,7 @@
(let [entity-fn (:table-fn opts identity) (let [entity-fn (:table-fn opts identity)
params (as-keys key-map opts) params (as-keys key-map opts)
places (as-? 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)) (into [(str "INSERT INTO " (entity-fn (safe-name table))
" (" params ")" " (" params ")"
" VALUES (" places ")" " VALUES (" places ")"
@ -144,11 +147,11 @@
If `:suffix` is provided in `opts`, that string is appended to the If `:suffix` is provided in `opts`, that string is appended to the
`INSERT ...` statement." `INSERT ...` statement."
[table cols rows opts] [table cols rows opts]
(assert (apply = (count cols) (map count rows)) (validate (apply = (count cols) (map count rows))
"column counts are not consistent across cols and rows") "column counts are not consistent across cols and rows")
;; to avoid generating bad SQL ;; to avoid generating bad SQL
(assert (seq cols) "cols may not be empty") (validate (seq cols) "cols may not be empty")
(assert (seq rows) "rows may not be empty") (validate (seq rows) "rows may not be empty")
(let [table-fn (:table-fn opts identity) (let [table-fn (:table-fn opts identity)
batch? (:batch opts) batch? (:batch opts)
params (as-cols cols opts) params (as-cols cols opts)
@ -195,7 +198,7 @@
[order-by opts] [order-by opts]
(when-not (vector? order-by) (when-not (vector? order-by)
(throw (IllegalArgumentException. ":order-by must be a vector"))) (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 "ORDER BY "
(str/join ", " (map #(for-order-col % opts) order-by)))) (str/join ", " (map #(for-order-col % opts) order-by))))

View file

@ -158,7 +158,7 @@
(deftest test-for-update (deftest test-for-update
(testing "empty example (would be a SQL error)" (testing "empty example (would be a SQL error)"
(is (thrown? AssertionError ; changed in #44 (is (thrown? IllegalArgumentException
(builder/for-update :user (builder/for-update :user
{:status 42} {:status 42}
{} {}