Liking cljdoc? Tell your friends :D

toucan2.tools.with-temp


do-with-tempclj

(do-with-temp modelable attributes f)
source

do-with-temp*clj

(do-with-temp* model₁ explicit-attributes f)

Implementation of with-temp. You can implement this if you need to do some sort of special behavior for a particular model. But normally you would just implement with-temp-defaults. If you need to do special setup when using with-temp, you can implement a :before method:

(m/defmethod do-with-temp* :before :default
  [_model _explicit-attributes f]
  (set-up-db!)
  f)

explicit-attributes are the attributes specified in the with-temp form itself, any may be nil. The default implementation merges the attributes from with-temp-defaults like

(merge {} (with-temp-defaults model) explict-attributes)

do-with-temp* is defined in toucan2.tools.with-temp (toucan2/tools/with_temp.clj:26).

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 primary methods are known:

Implementation of [[with-temp]]. You can implement this if you need to do some sort of special behavior for a
  particular model. But normally you would just implement [[with-temp-defaults]]. If you need to do special setup when
  using [[with-temp]], you can implement a `:before` method:

  ```clj
  (m/defmethod do-with-temp* :before :default
    [_model _explicit-attributes f]
    (set-up-db!)
    f)
  ```

  `explicit-attributes` are the attributes specified in the `with-temp` form itself, any may be `nil`. The default
  implementation merges the attributes from [[with-temp-defaults]] like

  ```clj
  (merge {} (with-temp-defaults model) explict-attributes)
  ```

do-with-temp* is defined in [[toucan2.tools.with-temp]] (toucan2/tools/with_temp.clj:26).

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 primary methods are known:

* `:default`, defined in [[toucan2.tools.with-temp]] (toucan2/tools/with_temp.clj:49) 
sourceraw docstring

with-tempcljmacro

(with-temp [modelable temp-object-binding attributes & more] & body)

Define a temporary instance of a model and bind it to temp-object-binding. The object is inserted using [[insert/insert-returning-instances!]] using the values from with-temp-defaults merged with a map of attributes. At the conclusion of body, the object is deleted. This is primarily intended for usage in tests, so this adds a [[clojure.test/testing]] context around body as well.

with-temp can create multiple objects in one form if you pass additional bindings.

temp-object-binding and attributes are optional, and default to _ and nil, respectively. If you're creating multiple objects at once these must be explicitly specified.

Examples:

;;; use the with-temp-defaults for :models/bird
(with-temp [:models/bird bird]
  (do-something bird))

;;; use the with-temp-defaults for :models/bird merged with {:name "Lucky Pigeon"}
(with-temp [:models/bird bird {:name "Lucky Pigeon"}]
  (do-something bird))

;;; define multiple instances at the same time
(with-temp [:models/bird bird-1 {:name "Parroty"}
            :models/bird bird-2 {:name "Green Friend", :best-friend-id (:id bird-1)}]
  (do-something bird))

If you want to implement custom behavior for a model other than default values, you can implement do-with-temp*.

Define a temporary instance of a model and bind it to `temp-object-binding`. The object is inserted
using [[insert/insert-returning-instances!]] using the values from [[with-temp-defaults]] merged with a map of
`attributes`. At the conclusion of `body`, the object is deleted. This is primarily intended for usage in tests, so
this adds a [[clojure.test/testing]] context around `body` as well.

[[with-temp]] can create multiple objects in one form if you pass additional bindings.

`temp-object-binding` and `attributes` are optional, and default to `_` and `nil`, respectively. If you're creating
multiple objects at once these must be explicitly specified.

Examples:

```clj
;;; use the with-temp-defaults for :models/bird
(with-temp [:models/bird bird]
  (do-something bird))

;;; use the with-temp-defaults for :models/bird merged with {:name "Lucky Pigeon"}
(with-temp [:models/bird bird {:name "Lucky Pigeon"}]
  (do-something bird))

;;; define multiple instances at the same time
(with-temp [:models/bird bird-1 {:name "Parroty"}
            :models/bird bird-2 {:name "Green Friend", :best-friend-id (:id bird-1)}]
  (do-something bird))
```

If you want to implement custom behavior for a model other than default values, you can implement [[do-with-temp*]].
sourceraw docstring

with-temp-defaultsclj

(with-temp-defaults model)

with-temp-defaults is defined in toucan2.tools.with-temp (toucan2/tools/with_temp.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 primary methods are known:

with-temp-defaults is defined in [[toucan2.tools.with-temp]] (toucan2/tools/with_temp.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 primary methods are known:

* `:default`, defined in [[toucan2.tools.with-temp]] (toucan2/tools/with_temp.clj:22) 
sourceraw docstring

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

× close