diff --git a/CHANGELOG.md b/CHANGELOG.md index 264eb0a..a317a37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Only accretive/fixative changes will be made from now on. The following changes have been committed to the **master** branch since the 1.0.1 release: +* Fix #42 by adding specs for `execute-batch!` and `set-parameters` in `next.jdbc.prepare`. * Fix #40 by adding `next.jdbc.prepare/execute-batch!`. * Expose `next.jdbc.connect/dbtypes` as a table of known database types and aliases, along with their class name(s), port, and other JDBC string components. * Improved docstrings and documentation, especially around prepared statement handling. diff --git a/src/next/jdbc/specs.clj b/src/next/jdbc/specs.clj index a3ddd19..63cc8bc 100644 --- a/src/next/jdbc/specs.clj +++ b/src/next/jdbc/specs.clj @@ -3,7 +3,9 @@ (ns next.jdbc.specs "Specs for the core API of next.jdbc. - The functions from `next.jdbc` and `next.jdbc.sql` have specs here. + The functions from `next.jdbc`, `next.jdbc.sql`, and `next.jdbc.prepare` + have specs here. + Just `:args` are spec'd. These specs are intended to aid development with `next.jdbc` by catching simple errors in calling the library. The `connectable` argument is currently just `any?` but both @@ -15,6 +17,7 @@ (:require [clojure.spec.alpha :as s] [clojure.spec.test.alpha :as st] [next.jdbc :as jdbc] + [next.jdbc.prepare :as prepare] [next.jdbc.sql :as sql]) (:import (java.sql Connection PreparedStatement) (javax.sql DataSource))) @@ -51,6 +54,11 @@ (s/def ::sql-params (s/and vector? (s/cat :sql string? :params (s/* any?)))) +(s/def ::params (s/coll-of any? :kind sequential?)) + +(s/def ::batch-size pos-int?) +(s/def ::large boolean?) +(s/def ::batch-opts (s/keys :opt-un [::batch-size ::large])) (s/fdef jdbc/get-datasource :args (s/cat :spec ::db-spec)) @@ -94,6 +102,15 @@ :opts (s/? ::opts-map))) :body (s/* any?))) +(s/fdef prepare/execute-batch! + :args (s/cat :ps ::prepared-statement + :param-groups (s/coll-of ::params :kind sequential?) + :opts (s/? ::batch-opts))) + +(s/fdef prepare/set-parameters + :args (s/cat :ps ::prepared-statement + :params ::params)) + (s/fdef sql/insert! :args (s/cat :connectable ::connectable :table keyword? @@ -156,6 +173,8 @@ `jdbc/execute-one! `jdbc/transact `jdbc/with-transaction + `prepare/execute-batch! + `prepare/set-parameters `sql/insert! `sql/insert-multi! `sql/query