From e03de7828adfec45271949e940ca45a1ecc9db3b Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Sat, 14 Sep 2019 13:32:34 -0700 Subject: [PATCH] Document PR #64 Add to change log, Getting Started, and ns docstring for `next.jdbc.specs`. Also note docs in GitHub are for **master** now. --- CHANGELOG.md | 2 +- README.md | 2 +- doc/getting-started.md | 6 ++++ src/next/jdbc/specs.clj | 61 ++++++++++++++++------------------------- 4 files changed, 32 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c6b212..0a2155b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +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.7 release: -* None. +* Add `next.jdbc.specs/unstrument`. PR #64 (@gerred). ## Stable Builds diff --git a/README.md b/README.md index 7b0dd35..d86511f 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ The latest versions on Clojars and on cljdoc: [![Clojars Project](https://clojars.org/seancorfield/next.jdbc/latest-version.svg)](https://clojars.org/seancorfield/next.jdbc) [![cljdoc badge](https://cljdoc.org/badge/seancorfield/next.jdbc)](https://cljdoc.org/d/seancorfield/next.jdbc/CURRENT) -This documentation is for the 1.0.7 release -- [see the CHANGELOG](CHANGELOG.md). +This documentation is for **master** after the 1.0.7 release -- [see the CHANGELOG](CHANGELOG.md). * [Getting Started](/doc/getting-started.md) * [Migrating from `clojure.java.jdbc`](/doc/migration-from-clojure-java-jdbc.md) diff --git a/doc/getting-started.md b/doc/getting-started.md index 4b45538..2c94ed1 100644 --- a/doc/getting-started.md +++ b/doc/getting-started.md @@ -250,4 +250,10 @@ Call to #'next.jdbc/execute! did not conform to spec. In the `:problems` output, you'll see the `:path [:sql :sql-params]` and `:pred vector?` for the `:val "SELECT * FROM fruit"`. Without the specs' assistance, this mistake would produce a more cryptic error, a `ClassCastException`, that a `Character` cannot be cast to a `String`, from inside `next.jdbc.prepare`. +A convenience function also exists to revert that instrumentation: + +```clojure +(specs/unstrument) ; undoes the instrumentation of all next.jdbc API functions +``` + [Friendly SQL Functions :>](/doc/friendly-sql-functions.md) diff --git a/src/next/jdbc/specs.clj b/src/next/jdbc/specs.clj index dbbb057..ef83770 100644 --- a/src/next/jdbc/specs.clj +++ b/src/next/jdbc/specs.clj @@ -13,7 +13,8 @@ extend `Sourceable` or `Connectable`, those specs will likely be too strict. In addition, there is an `instrument` function that provides a simple - way to instrument all of the `next.jdbc` functions." + way to instrument all of the `next.jdbc` functions, and `unstrument` + to undo that." (:require [clojure.spec.alpha :as s] [clojure.spec.test.alpha :as st] [next.jdbc :as jdbc] @@ -183,42 +184,28 @@ :where ::sql-params) :opts (s/? ::opts-map))) +(def ^:private fns-with-specs + [`jdbc/get-datasource + `jdbc/get-connection + `jdbc/prepare + `jdbc/plan + `jdbc/execute! + `jdbc/execute-one! + `jdbc/transact + `jdbc/with-transaction + `connection/->pool + `prepare/execute-batch! + `prepare/set-parameters + `sql/insert! + `sql/insert-multi! + `sql/query + `sql/find-by-keys + `sql/get-by-id + `sql/update! + `sql/delete!]) + (defn instrument [] - (st/instrument [`jdbc/get-datasource - `jdbc/get-connection - `jdbc/prepare - `jdbc/plan - `jdbc/execute! - `jdbc/execute-one! - `jdbc/transact - `jdbc/with-transaction - `connection/->pool - `prepare/execute-batch! - `prepare/set-parameters - `sql/insert! - `sql/insert-multi! - `sql/query - `sql/find-by-keys - `sql/get-by-id - `sql/update! - `sql/delete!])) + (st/instrument fns-with-specs)) (defn unstrument [] - (st/unstrument [`jdbc/get-datasource - `jdbc/get-connection - `jdbc/prepare - `jdbc/plan - `jdbc/execute! - `jdbc/execute-one! - `jdbc/transact - `jdbc/with-transaction - `connection/->pool - `prepare/execute-batch! - `prepare/set-parameters - `sql/insert! - `sql/insert-multi! - `sql/query - `sql/find-by-keys - `sql/get-by-id - `sql/update! - `sql/delete!])) + (st/unstrument fns-with-specs))