Liking cljdoc? Tell your friends :D

toucan2.tools.before-delete


before-deleteclj

(before-delete model₁ instance)

Underlying method implemented when using define-before-delete. You probably shouldn't be adding implementations to this method directly, unless you know what you are doing!

before-delete is defined in toucan2.tools.before-delete (toucan2/tools/before_delete.clj:16).

It caches methods using a methodical.impl.cache.watching.WatchingCache.

It uses the method combination methodical.impl.combo.threaded.ThreadingMethodCombination with the threading strategy :thread-last.

It uses the dispatcher methodical.impl.dispatcher.multi_default.MultiDefaultDispatcher with hierarchy #'clojure.core/global-hierarchy and prefs {}.

The default value is :default.

It uses the method table methodical.impl.method_table.standard.StandardMethodTable.

These aux methods are known:

:around methods:

Underlying method implemented when using [[define-before-delete]]. You *probably* shouldn't be adding implementations
  to this method directly, unless you know what you are doing!

before-delete is defined in [[toucan2.tools.before-delete]] (toucan2/tools/before_delete.clj:16).

It caches methods using a `methodical.impl.cache.watching.WatchingCache`.

It uses the method combination `methodical.impl.combo.threaded.ThreadingMethodCombination`
with the threading strategy `:thread-last`.

It uses the dispatcher `methodical.impl.dispatcher.multi_default.MultiDefaultDispatcher`
with hierarchy `#'clojure.core/global-hierarchy`
and prefs `{}`.

The default value is `:default`.

It uses the method table `methodical.impl.method_table.standard.StandardMethodTable`.

These aux methods are known:

`:around` methods:

* `:default`, defined in [[toucan2.tools.before-delete]] (toucan2/tools/before_delete.clj:24) 
sourceraw docstring

define-before-deletecljmacro

(define-before-delete model [instance-binding] & body)

Define a method that will be called for every instance that is about to be deleted. The results of this before-delete method are ultimately ignored, but the entire operation (both the original delete and the recursive select) are done in a transaction, so you can use before-delete to enforce preconditions and abort deletes when they fail, or do something for side effects.

Before-delete is implemented by first selecting all the rows matching the toucan2.delete/delete! conditions and then transducing those rows and calling the before-delete method this macro defines on each row. Because before-delete has to fetch every instance matching the condition, defining a before-delete method can be quite expensive! For example, a delete! operation that deletes a million rows would normally be a single database call; with before-delete in place, it would have to fetch and transduce all million rows and apply before-delete to each of them before even getting to the DELETE operation! So be sure you really need before-delete behavior before opting in to it.

To skip before-delete behavior, you can always use the model's raw table name directly, e.g.

(t2/delete! (t2/table-name :models/user) ...)

This might be wise when deleting a large number of rows.

Define a method that will be called for every instance that is about to be deleted. The results of this before-delete
method are ultimately ignored, but the entire operation (both the original delete and the recursive select) are done
in a transaction, so you can use before-delete to enforce preconditions and abort deletes when they fail, or do
something for side effects.

Before-delete is implemented by first selecting all the rows matching the [[toucan2.delete/delete!]] conditions and
then transducing those rows and calling the [[before-delete]] method this macro defines on each row. Because
before-delete has to fetch every instance matching the condition, defining a before-delete method can be quite
expensive! For example, a `delete!` operation that deletes a million rows would normally be a single database call;
with before-delete in place, it would have to fetch and transduce all million rows and apply [[before-delete]] to each
of them *before* even getting to the `DELETE` operation! So be sure you *really* need before-delete behavior before
opting in to it.

To skip before-delete behavior, you can always use the model's raw table name directly, e.g.

```clj
(t2/delete! (t2/table-name :models/user) ...)
```

This might be wise when deleting a large number of rows.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close