diff --git a/src/toucan2/delete.clj b/src/toucan2/delete.clj index 7b49e367..ad7e56aa 100644 --- a/src/toucan2/delete.clj +++ b/src/toucan2/delete.clj @@ -16,7 +16,7 @@ (defn reducible-delete {:arglists '([modelable & conditions? query?])} [modelable & unparsed-args] - (op/reducible ::delete modelable unparsed-args)) + (op/reducible-update* ::delete modelable unparsed-args)) (defn delete! "Returns number of rows deleted." diff --git a/src/toucan2/insert.clj b/src/toucan2/insert.clj index 615b9d28..041291f0 100644 --- a/src/toucan2/insert.clj +++ b/src/toucan2/insert.clj @@ -64,7 +64,7 @@ ;;;; [[reducible-insert]] and [[insert!]] -(m/defmethod op/reducible* [::insert :default] +(m/defmethod op/reducible-update* [::insert :default] [query-type model {:keys [rows], :as parsed-args}] (if (empty? rows) (do @@ -78,7 +78,7 @@ [modelable k v & more] [modelable columns row-vectors])} [modelable & unparsed-args] - (op/reducible ::insert modelable unparsed-args)) + (op/reducible-update ::insert modelable unparsed-args)) (defn insert! "Returns number of rows inserted." diff --git a/src/toucan2/operation.clj b/src/toucan2/operation.clj index cb90f6b0..258135f5 100644 --- a/src/toucan2/operation.clj +++ b/src/toucan2/operation.clj @@ -11,15 +11,17 @@ ;;;; things that return update count -;;; TODO -- give this a name that makes it's clear for 'write' operations, not read ones. -(m/defmulti reducible* +(m/defmulti reducible-update* "Return a reducible query based on `parsed-args`. This should return either an update count (number of rows updated) or a sequence of PK values for affected rows; which of these gets returned depends on [[toucan2.jdbc.query/options]] (for - the JDBC backend) or similar." + the JDBC backend) or similar. + + This is \"update\" in the sense that it is something that updates the database and returns an update count -- it could + mean a SQL `UPDATE`, `INSERT`, or `DELETE`." {:arglists '([query-type model parsed-args])} u/dispatch-on-first-two-args) -(m/defmethod reducible* :default +(m/defmethod reducible-update* :default [query-type model parsed-args] (query/with-resolved-query [query [model (:queryable parsed-args)]] (let [built-query (query/build query-type model (-> parsed-args @@ -27,14 +29,14 @@ (dissoc :queryable)))] (execute/reducible-query (model/deferred-current-connectable model) model built-query)))) -(defn reducible [query-type modelable unparsed-args] +(defn reducible-update [query-type modelable unparsed-args] (model/with-model [model modelable] (let [parsed-args (query/parse-args query-type model unparsed-args)] - (reducible* query-type model parsed-args)))) + (reducible-update* query-type model parsed-args)))) (defn returning-update-count! [query-type modelable unparsed-args] (u/with-debug-result ["%s %s returning update count" query-type modelable] - (reduce (fnil + 0 0) 0 (reducible query-type modelable unparsed-args)))) + (reduce (fnil + 0 0) 0 (reducible-update query-type modelable unparsed-args)))) ;;;; things that return PKs @@ -61,13 +63,13 @@ column, or a vector of primary key values in the same order as [[toucan2.model/primary-keys]] for models with composite primary keys. - The default implementation combines [[reducible*]] with [[return-pks-eduction]]." + The default implementation combines [[reducible-update*]] with [[return-pks-eduction]]." {:arglists '([query-type model parsed-args])} u/dispatch-on-first-two-args) (m/defmethod reducible-returning-pks* :default [query-type model parsed-args] - (return-pks-eduction model (reducible* query-type model parsed-args))) + (return-pks-eduction model (reducible-update* query-type model parsed-args))) (defn reducible-returning-pks "Helper wrapper for [[reducible-returning-pks*]] that also resolves `modelable` and parses `unparsed-args`." diff --git a/src/toucan2/tools/after.clj b/src/toucan2/tools/after.clj index 615f8ddf..0da42e92 100644 --- a/src/toucan2/tools/after.clj +++ b/src/toucan2/tools/after.clj @@ -91,7 +91,7 @@ ;;;; reducible update count -(m/defmethod op/reducible* :around [::after ::after] +(m/defmethod op/reducible-update* :around [::after ::after] [query-type model parsed-args] (cond (::doing-after? parsed-args) diff --git a/src/toucan2/tools/before_insert.clj b/src/toucan2/tools/before_insert.clj index 9298568f..6e64c69f 100644 --- a/src/toucan2/tools/before_insert.clj +++ b/src/toucan2/tools/before_insert.clj @@ -21,7 +21,7 @@ e))))) rows)) -(m/defmethod op/reducible* :before [::insert/insert ::before-insert] +(m/defmethod op/reducible-update* :before [::insert/insert ::before-insert] [_query-type model parsed-args] (assert (map? parsed-args)) (u/with-debug-result ["Do before insert for %s" model] @@ -33,7 +33,7 @@ ;;; ;;; By marking `::before-insert` as preferred over `:toucan2.tools.transformed/transformed` it will be done first (see ;;; https://github.com/camsaul/methodical#before-methods) -(m/prefer-method! #'op/reducible* +(m/prefer-method! #'op/reducible-update* [::insert/insert ::before-insert] [::insert/insert :toucan2.tools.transformed/transformed]) diff --git a/src/toucan2/tools/before_update.clj b/src/toucan2/tools/before_update.clj index 770be444..9e51ac68 100644 --- a/src/toucan2/tools/before_update.clj +++ b/src/toucan2/tools/before_update.clj @@ -54,7 +54,7 @@ pk-map pk-maps] (assoc parsed-args :changes changes, :kv-args pk-map)))))) -(m/defmethod op/reducible* :around [::update/update ::before-update] +(m/defmethod op/reducible-update* :around [::update/update ::before-update] [query-type model {::keys [doing-before-update?], :keys [changes], :as parsed-args}] (cond doing-before-update? diff --git a/src/toucan2/tools/compile.clj b/src/toucan2/tools/compile.clj index b4b6f28f..1e5bc016 100644 --- a/src/toucan2/tools/compile.clj +++ b/src/toucan2/tools/compile.clj @@ -63,3 +63,7 @@ ;; `(binding [query/*with-resolved-query-fn* identity-with-resolved-query] ;; (build ;; ~@body))) + +;; (defmacro parsed-args +;; [& body] +;; ) diff --git a/src/toucan2/tools/disallow.clj b/src/toucan2/tools/disallow.clj index e6ea755e..94021d34 100644 --- a/src/toucan2/tools/disallow.clj +++ b/src/toucan2/tools/disallow.clj @@ -7,14 +7,14 @@ [_query-type model _parsed-args] (throw (UnsupportedOperationException. (format "You cannot select %s." model)))) -(m/defmethod op/reducible* [:toucan2.delete/delete ::delete] +(m/defmethod op/reducible-update* [:toucan2.delete/delete ::delete] [_query-type model _parsed-args] (throw (UnsupportedOperationException. (format "You cannot delete instances of %s." model)))) -(m/defmethod op/reducible* [:toucan2.insert/insert ::insert] +(m/defmethod op/reducible-update* [:toucan2.insert/insert ::insert] [_query-type model _parsed-args] (throw (UnsupportedOperationException. (format "You cannot create new instances of %s." model)))) -(m/defmethod op/reducible* [:toucan2.update/update ::update] +(m/defmethod op/reducible-update* [:toucan2.update/update ::update] [_query-type model _parsed-args] (throw (UnsupportedOperationException. (format "You cannot update a %s after it has been created." model)))) diff --git a/src/toucan2/tools/helpers.clj b/src/toucan2/tools/helpers.clj index 85374665..9457458b 100644 --- a/src/toucan2/tools/helpers.clj +++ b/src/toucan2/tools/helpers.clj @@ -80,7 +80,7 @@ (pretty [_this] (list `->ReducibleBeforeDelete model parsed-args reducible-delete))) -(m/defmethod op/reducible* :around [::delete/delete ::before-delete] +(m/defmethod op/reducible-update* :around [::delete/delete ::before-delete] [query-type model parsed-args] (let [reducible-delete (next-method query-type model parsed-args)] (->ReducibleBeforeDelete model parsed-args reducible-delete))) diff --git a/src/toucan2/tools/transformed.clj b/src/toucan2/tools/transformed.clj index c230264e..729cd2f6 100644 --- a/src/toucan2/tools/transformed.clj +++ b/src/toucan2/tools/transformed.clj @@ -247,7 +247,7 @@ row-xform (apply comp row-xforms)] (map row-xform rows))) -(m/defmethod op/reducible* :before [::insert/insert ::transformed] +(m/defmethod op/reducible-update* :before [::insert/insert ::transformed] [_query-type model parsed-args] (assert (isa? model ::transformed)) (if-let [transforms (in-transforms model)] diff --git a/src/toucan2/update.clj b/src/toucan2/update.clj index ab3ca581..aeab218e 100644 --- a/src/toucan2/update.clj +++ b/src/toucan2/update.clj @@ -45,7 +45,7 @@ :set changes})] (next-method query-type model parsed-args))) -(m/defmethod op/reducible* [::update :default] +(m/defmethod op/reducible-update* [::update :default] [query-type model {:keys [changes], :as parsed-args}] (if (empty? changes) (do @@ -56,7 +56,7 @@ (defn reducible-update {:arglists '([modelable pk? conditions-map-or-query? & conditions-kv-args changes-map])} [modelable & unparsed-args] - (op/reducible* ::update modelable unparsed-args)) + (op/reducible-update* ::update modelable unparsed-args)) (defn update! {:arglists '([modelable pk? conditions-map-or-query? & conditions-kv-args changes-map])} diff --git a/test/toucan2/core_test.clj b/test/toucan2/core_test.clj new file mode 100644 index 00000000..36830ec7 --- /dev/null +++ b/test/toucan2/core_test.clj @@ -0,0 +1,5 @@ +(ns toucan2.core-test + "This is just a dummy namespace to make sure [[toucan2.core]] loads while we're running tests." + (:require [toucan2.core :as core])) + +(comment core/keep-me)