Address #31 by improving string representation of reified objects
At least this should give a hint as to what you did wrong...
This commit is contained in:
parent
a09612cebe
commit
e1b42b1804
5 changed files with 24 additions and 5 deletions
|
|
@ -6,6 +6,7 @@ Only accretive/fixative changes will be made from now on.
|
|||
|
||||
The following changes have been committed to the **master** branch and will be in the 1.0.0 release:
|
||||
|
||||
* Address #31 by making `reify`'d objects produce a more informative string representation if they are printed (e.g., misusing `plan` by not reducing it or not mapping an operation over the rows).
|
||||
* Fix #26 by exposing `next.jdbc.result-set/datafiable-result-set` so that various `java.sql.DatabaseMetaData` methods that return result metadata information in `ResultSet`s can be easily turned into a fully realized result set.
|
||||
|
||||
## Stable Builds
|
||||
|
|
|
|||
|
|
@ -147,7 +147,8 @@
|
|||
(get-driver-connection url
|
||||
(assoc etc
|
||||
:user username
|
||||
:password password)))))
|
||||
:password password)))
|
||||
(toString [_] url)))
|
||||
|
||||
(defn- make-connection
|
||||
"Given a `DataSource` and a map of options, get a connection and update it
|
||||
|
|
|
|||
|
|
@ -343,7 +343,9 @@
|
|||
(datafiable-row [this connectable opts]
|
||||
(with-meta
|
||||
(row-builder @builder)
|
||||
{`core-p/datafy (navize-row connectable opts)})))))
|
||||
{`core-p/datafy (navize-row connectable opts)}))
|
||||
|
||||
(toString [_] "{row} from `plan` -- missing `map` or `reduce`?"))))
|
||||
|
||||
(extend-protocol
|
||||
DatafiableRow
|
||||
|
|
@ -411,7 +413,8 @@
|
|||
(first sql-params)
|
||||
(rest sql-params)
|
||||
opts)]
|
||||
(reduce-stmt stmt f init opts)))))
|
||||
(reduce-stmt stmt f init opts)))
|
||||
(toString [_] "`IReduceInit` from `plan` -- missing reduction?")))
|
||||
(-execute-one [this sql-params opts]
|
||||
(with-open [stmt (prepare/create this
|
||||
(first sql-params)
|
||||
|
|
@ -441,7 +444,8 @@
|
|||
(first sql-params)
|
||||
(rest sql-params)
|
||||
opts)]
|
||||
(reduce-stmt stmt f init opts))))))
|
||||
(reduce-stmt stmt f init opts))))
|
||||
(toString [_] "`IReduceInit` from `plan` -- missing reduction?")))
|
||||
(-execute-one [this sql-params opts]
|
||||
(with-open [con (p/get-connection this opts)]
|
||||
(with-open [stmt (prepare/create con
|
||||
|
|
@ -471,7 +475,8 @@
|
|||
(-execute [this _ opts]
|
||||
(reify clojure.lang.IReduceInit
|
||||
(reduce [_ f init]
|
||||
(reduce-stmt this f init (assoc opts :return-keys true)))))
|
||||
(reduce-stmt this f init (assoc opts :return-keys true)))
|
||||
(toString [_] "`IReduceInit` from `plan` -- missing reduction?")))
|
||||
(-execute-one [this _ opts]
|
||||
(if-let [rs (stmt->result-set this (assoc opts :return-keys true))]
|
||||
(let [builder-fn (get opts :builder-fn as-maps)
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@
|
|||
(testing "datasource via Associative"
|
||||
(let [ds (p/get-datasource db)]
|
||||
(is (instance? javax.sql.DataSource ds))
|
||||
(is (str/index-of (pr-str ds) (str "jdbc:" (:dbtype db))))
|
||||
;; checks get-datasource on a DataSource is identity
|
||||
(is (identical? ds (p/get-datasource ds)))
|
||||
(with-open [con (p/get-connection ds {})]
|
||||
|
|
@ -74,6 +75,7 @@
|
|||
(let [[url _] (#'c/spec->url+etc db)
|
||||
ds (p/get-datasource url)]
|
||||
(is (instance? javax.sql.DataSource ds))
|
||||
(is (str/index-of (pr-str ds) url))
|
||||
(with-open [con (p/get-connection ds {})]
|
||||
(is (instance? java.sql.Connection con)))))
|
||||
(testing "connection via map (Object)"
|
||||
|
|
|
|||
|
|
@ -118,3 +118,13 @@ INSERT INTO fruit (name, appearance, cost, grade)
|
|||
VALUES ('Pear', 'green', 49, 47)
|
||||
"]))))
|
||||
(is (= 4 (count (jdbc/execute! (ds) ["select * from fruit"]))))))
|
||||
|
||||
(deftest plan-misuse
|
||||
(let [s (pr-str (jdbc/plan (ds) ["select * from fruit"]))]
|
||||
(is (re-find #"missing reduction" s)))
|
||||
(let [s (pr-str (into [] (jdbc/plan (ds) ["select * from fruit"])))]
|
||||
(is (re-find #"missing `map` or `reduce`" s)))
|
||||
(let [s (pr-str (into [] (take 3) (jdbc/plan (ds) ["select * from fruit"])))]
|
||||
(is (re-find #"missing `map` or `reduce`" s)))
|
||||
(is (thrown? IllegalArgumentException
|
||||
(doall (take 3 (jdbc/plan (ds) ["select * from fruit"]))))))
|
||||
|
|
|
|||
Loading…
Reference in a new issue