Liking cljdoc? Tell your friends :D

dgknght.app-lib.models


->idclj/s

(->id model-or-id)

Given a model with the id is stored at :id, or the id iteself, return the id.

E.g.: (->id 123) => 123 (->id {:id 456 :name "John"}) => 456

Given a model with the id is stored at :id, or the id iteself, return the id.

E.g.:
(->id 123) => 123
(->id {:id 456 :name "John"}) => 456
sourceraw docstring

extract-nestedclj/s

(extract-nested model base-key)

Given a model with an inner model nested at the top level via prefixed keys, returns a model with the nested model in a nested map. This is useful when storing data in a SQL database and you need to look up a relationship via SQL JOIN and then extract that model after read.

E.g. (extract-nested {:id 1 :order-number "001" :customer-id 2 :customer-name "John Doe"} :customer) => {:id 1 :order-number "001" :customer-id 2 :customer {:id 2 :name "John Doe"}}

Given a model with an inner model nested at the top level via
prefixed keys, returns a model with the nested model in a
nested map. This is useful when storing data in a SQL database
and you need to look up a relationship via SQL JOIN and then
extract that model after read.

E.g.
(extract-nested {:id 1
                 :order-number "001"
                 :customer-id 2
                 :customer-name "John Doe"}
                :customer) => {:id 1
                               :order-number "001"
                               :customer-id 2
                               :customer {:id 2
                                          :name "John Doe"}}
sourceraw docstring

map-indexclj/s

(map-index values)
(map-index key-fn values)

Given a sequence of maps and a key function, returns a map of the values in the collection where the keys are the values retrieved by the key function.

E.g.: (index :id [{:id 1 :name "One"}]) => {1 {:id 1 :name "One"}}

Given a sequence of maps and a key function, returns a map of the
values in the collection where the keys are the values retrieved by the key function.

E.g.:
(index :id [{:id 1 :name "One"}]) => {1 {:id 1 :name "One"}}
sourceraw docstring

nestclj/s

(nest collection)
(nest {:keys [parent-fn] :or {parent-fn :parent-id} :as opts} collection)

Given a collection of maps with recursive references, returns the same list with children assigned to their parents.

options: :id-fn - A key or fn that extracts the id from each model. Defaults to :id. :parent-fn - A key or fn that extracts the parent id from each model. Defaults to :parent-id. :decorate-child-fn - A function that receives a child and parent when the child is added to the parent :decorate-parent-fn - A function that receives each model that has children with the model as the first argument and the children as the second and returns the model.

Given a collection of maps with recursive references, returns the same list with
children assigned to their parents.

options:
  :id-fn              - A key or fn that extracts the id from each model. Defaults to :id.
  :parent-fn          - A key or fn that extracts the parent id from each model. Defaults to :parent-id.
  :decorate-child-fn  - A function that receives a child and parent when the child is added to the parent
  :decorate-parent-fn - A function that receives each model that has children with the model as the first argument and the children as the second and returns the model.
sourceraw docstring

unnestclj/s

(unnest collection)
(unnest options collection)

Given a nested collection, return a flattened list

Given a nested collection, return a flattened list
sourceraw docstring

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

× close