Liking cljdoc? Tell your friends :D

toucan2.model

Methods related to resolving Toucan 2 models, appropriate table names to use when building queries for them, and namespaces to use for columns in query results.

Methods related to resolving Toucan 2 models, appropriate table names to use when building queries for them, and
namespaces to use for columns in query results.
raw docstring

default-connectableclj

(default-connectable model₁)

The default connectable that should be used when executing queries for model if no toucan2.connection/*current-connectable* is currently bound. By default, this just returns the global default connectable, :default, but you can tell Toucan to use a different default connectable for a model by implementing this method.

default-connectable is defined in toucan2.model (toucan2/model.clj:42).

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.model (toucan2/model.clj:50)

    It has the following documentation:

    Return nil, so we can fall thru to something else (presumably :default anyway)?

The default connectable that should be used when executing queries for `model` if
  no [[toucan2.connection/*current-connectable*]] is currently bound. By default, this just returns the global default
  connectable, `:default`, but you can tell Toucan to use a different default connectable for a model by implementing
  this method.

default-connectable is defined in [[toucan2.model]] (toucan2/model.clj:42).

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.model]] (toucan2/model.clj:50) 
  
  It has the following documentation:
  
  Return `nil`, so we can fall thru to something else (presumably `:default` anyway)?
sourceraw docstring

model->namespaceclj

(model->namespace model₁)

Return a map of namespaces to use when fetching results with this model.

(m/defmethod model->namespace ::my-model
  [_model]
  {::my-model      "x"
   ::another-model "y"})

model->namespace is defined in toucan2.model (toucan2/model.clj:162).

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.model (toucan2/model.clj:176)

    It has the following documentation:

    By default, don't namespace column names when fetching rows.

These aux methods are known:

:after methods:

  • :default, defined in toucan2.model (toucan2/model.clj:181)

    It has the following documentation:

    Validate the results.

Return a map of namespaces to use when fetching results with this model.

  ```clj
  (m/defmethod model->namespace ::my-model
    [_model]
    {::my-model      "x"
     ::another-model "y"})
  ```

model->namespace is defined in [[toucan2.model]] (toucan2/model.clj:162).

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.model]] (toucan2/model.clj:176) 
  
  It has the following documentation:
  
  By default, don't namespace column names when fetching rows.

These aux methods are known:

`:after` methods:

* `:default`, defined in [[toucan2.model]] (toucan2/model.clj:181) 
  
  It has the following documentation:
  
  Validate the results.
sourceraw docstring

namespaceclj

(namespace model)

Get the namespace that should be used to prefix keys associated with a model in query results. This is taken from the model's implementation of model->namespace.

Get the namespace that should be used to prefix keys associated with a `model` in query results. This is taken from the
model's implementation of [[model->namespace]].
sourceraw docstring

primary-key-values-mapclj

(primary-key-values-map instance)
(primary-key-values-map model m)

Return a map of primary key values for a Toucan 2 instance.

Return a map of primary key values for a Toucan 2 `instance`.
sourceraw docstring

primary-keysclj

(primary-keys model₁)

Return a sequence of the primary key columns names, as keywords, for a model. The default primary keys for a model are [:id]; implement this method if your model has different primary keys.

;; tell Toucan that :model/bird has a composite primary key consisting of the columns :id and :name
(m/defmethod primary-keys :model/bird
  [_model]
  [:id :name])

If an implementation returns a single keyword, the default :around method will automatically wrap it in a vector. It also validates that the ultimate result is a sequence of keywords, so it is safe to assume that calls to this will always return a sequence of keywords.

primary-keys is defined in toucan2.model (toucan2/model.clj:106).

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.model (toucan2/model.clj:215)

    It has the following documentation:

    By default the primary key for a model is the column :id; or :some-namespace/id if the model defines a namespace for itself with model->namespace.

These aux methods are known:

:around methods:

  • :default, defined in toucan2.model (toucan2/model.clj:125)

    It has the following documentation:

    If the PK comes back unwrapped, wrap it -- make sure results are always returned as a vector of keywords. Throw an error if results are in the incorrect format.

Return a sequence of the primary key columns names, as keywords, for a model. The default primary keys for a model are
  `[:id]`; implement this method if your model has different primary keys.

  ```clj
  ;; tell Toucan that :model/bird has a composite primary key consisting of the columns :id and :name
  (m/defmethod primary-keys :model/bird
    [_model]
    [:id :name])
  ```

  If an implementation returns a single keyword, the default `:around` method will automatically wrap it in a vector. It
  also validates that the ultimate result is a sequence of keywords, so it is safe to assume that calls to this will
  always return a sequence of keywords.

primary-keys is defined in [[toucan2.model]] (toucan2/model.clj:106).

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.model]] (toucan2/model.clj:215) 
  
  It has the following documentation:
  
  By default the primary key for a model is the column `:id`; or `:some-namespace/id` if the model defines a namespace
    for itself with [[model->namespace]].

These aux methods are known:

`:around` methods:

* `:default`, defined in [[toucan2.model]] (toucan2/model.clj:125) 
  
  It has the following documentation:
  
  If the PK comes back unwrapped, wrap it -- make sure results are always returned as a vector of keywords. Throw an
    error if results are in the incorrect format.
sourceraw docstring

resolve-modelclj

(resolve-model modelable₁)

Resolve a modelable to an actual Toucan model (usually a keyword). A modelable is anything that can be resolved to a model via this method. You can implement this method to define special model resolution behavior, for example toucan2-toucan1 defines a method for clojure.lang.Symbol that does namespace resolution to return an appropriate model keyword.

You can also implement this method to do define behaviors when a model is used, for example making sure some namespace with method implementation for the model is loaded, logging some information, etc.

resolve-model is defined in toucan2.model (toucan2/model.clj:18).

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.model (toucan2/model.clj:29)

    It has the following documentation:

    Default implementation. Return modelable as is, i.e., there is nothing to resolve, and we can use it directly as a model.

These aux methods are known:

:around methods:

  • :default, defined in toucan2.model (toucan2/model.clj:35)

    It has the following documentation:

    Log model resolution as it happens for debugging purposes.

Resolve a *modelable* to an actual Toucan *model* (usually a keyword). A modelable is anything that can be resolved to
  a model via this method. You can implement this method to define special model resolution behavior, for example
  `toucan2-toucan1` defines a method for `clojure.lang.Symbol` that does namespace resolution to return an appropriate
  model keyword.

  You can also implement this method to do define behaviors when a model is used, for example making sure some namespace
  with method implementation for the model is loaded, logging some information, etc.

resolve-model is defined in [[toucan2.model]] (toucan2/model.clj:18).

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.model]] (toucan2/model.clj:29) 
  
  It has the following documentation:
  
  Default implementation. Return `modelable` as is, i.e., there is nothing to resolve, and we can use it directly as a
    model.

These aux methods are known:

`:around` methods:

* `:default`, defined in [[toucan2.model]] (toucan2/model.clj:35) 
  
  It has the following documentation:
  
  Log model resolution as it happens for debugging purposes.
sourceraw docstring

select-pks-fnclj

(select-pks-fn modelable)

Return a function to get the value(s) of the primary key(s) from a row, as a single value or vector of values. Used by toucan2.select/select-pks-reducible and thus by toucan2.select/select-pks-set, toucan2.select/select-pks-vec, etc.

The primary keys are determined by primary-keys. By default this is simply the keyword :id.

Return a function to get the value(s) of the primary key(s) from a row, as a single value or vector of values. Used
by [[toucan2.select/select-pks-reducible]] and thus
by [[toucan2.select/select-pks-set]], [[toucan2.select/select-pks-vec]], etc.

The primary keys are determined by [[primary-keys]]. By default this is simply the keyword `:id`.
sourceraw docstring

table-nameclj

(table-name model₁)

Return the actual underlying table name that should be used to query a model.

By default for things that implement name, the table name is just (keyword (name x)).

(t2/table-name :models/user)
;; =>
:user

You can write your own implementations for this for models whose table names do not match their name.

This is guaranteed to return a keyword, so it can easily be used directly in Honey SQL queries and the like; if you return something else, the default :after method will convert it to a keyword for you.

table-name is defined in toucan2.model (toucan2/model.clj:55).

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.model (toucan2/model.clj:75)

    It has the following documentation:

    Fallback implementation. Redirects keywords to the implementation for clojure.lang.Named (use the name of the keyword). For everything else, throws an error, since we don't know how to get a table name from it.

  • clojure.lang.Named, defined in toucan2.model (toucan2/model.clj:91)

    It has the following documentation:

    Default implementation for anything that is a clojure.lang.Named, such as a keywords or symbols. Use the name as the table name.

    (t2/table-name :models/user) => :user
    
  • java.lang.String, defined in toucan2.model (toucan2/model.clj:101)

    It has the following documentation:

    Implementation for strings. Use the string name as-is.

These aux methods are known:

:after methods:

  • :default, defined in toucan2.model (toucan2/model.clj:84)

    It has the following documentation:

    Always return table names as keywords. This will facilitate using them directly inside Honey SQL, e.g.

    {:select [:*], :from [(t2/table-name MyModel)]}
    
Return the actual underlying table name that should be used to query a `model`.

  By default for things that implement `name`, the table name is just `(keyword (name x))`.

  ```clj
  (t2/table-name :models/user)
  ;; =>
  :user
  ```

  You can write your own implementations for this for models whose table names do not match their `name`.

  This is guaranteed to return a keyword, so it can easily be used directly in Honey SQL queries and the like; if you
  return something else, the default `:after` method will convert it to a keyword for you.

table-name is defined in [[toucan2.model]] (toucan2/model.clj:55).

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.model]] (toucan2/model.clj:75) 
  
  It has the following documentation:
  
  Fallback implementation. Redirects keywords to the implementation for `clojure.lang.Named` (use the `name` of the
    keyword). For everything else, throws an error, since we don't know how to get a table name from it.

* `clojure.lang.Named`, defined in [[toucan2.model]] (toucan2/model.clj:91) 
  
  It has the following documentation:
  
  Default implementation for anything that is a `clojure.lang.Named`, such as a keywords or symbols. Use the `name` as
    the table name.
  
    ```clj
    (t2/table-name :models/user) => :user
    ```

* `java.lang.String`, defined in [[toucan2.model]] (toucan2/model.clj:101) 
  
  It has the following documentation:
  
  Implementation for strings. Use the string name as-is.

These aux methods are known:

`:after` methods:

* `:default`, defined in [[toucan2.model]] (toucan2/model.clj:84) 
  
  It has the following documentation:
  
  Always return table names as keywords. This will facilitate using them directly inside Honey SQL, e.g.
  
      {:select [:*], :from [(t2/table-name MyModel)]}
sourceraw docstring

table-name->namespaceclj

(table-name->namespace model)

Take the model->namespace map for a model and return a map of string table name -> namespace. This is used to determine how to prefix columns in results based on their table name; see toucan2.jdbc.result-set/instance-builder-fn for an example of this usage.

Take the [[model->namespace]] map for a model and return a map of string table name -> namespace. This is used to
determine how to prefix columns in results based on their table name;
see [[toucan2.jdbc.result-set/instance-builder-fn]] for an example of this usage.
sourceraw docstring

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

× close