(append-collection schema db entity-kw collection-key data)
(append-collection schema db entity-kw collection-key data meta)
Appends items to an existing collection.
(def entity-db-v1 {})
(def schema {:foos {:id :id}})
(def collection [{:id 1 :name "foo"} {:id 2 :name "bar"}])
(def entity-db-v2 (insert-collection schema entity-db-v1 :foos :list collection))
;; Returns the new version of entity db. Each item will be stored
;; in the internal store map and collection will contain only the
;; item ids.
(get-collection schema entity-db-v2 :foos :list)
;; Returns a collection of items named `:list`. Although internally collections
;; stores only a vector of ids, this function will return a vector of entities.
;;
;; [{:id 1 :name "foo"} {:id 2 :name "bar"}]
(def entity-db-v3 (append-collection schema entity-db-v2 :foos :list [{:id 3 :name "baz}]))
(get-collection schema entity-db-v3 :foos :list)
;; Returns [{:id 1 :name "foo"} {:id 2 :name "bar} {:id 3 :name "baz"}]
Appends items to an existing collection. ```clojure (def entity-db-v1 {}) (def schema {:foos {:id :id}}) (def collection [{:id 1 :name "foo"} {:id 2 :name "bar"}]) (def entity-db-v2 (insert-collection schema entity-db-v1 :foos :list collection)) ;; Returns the new version of entity db. Each item will be stored ;; in the internal store map and collection will contain only the ;; item ids. (get-collection schema entity-db-v2 :foos :list) ;; Returns a collection of items named `:list`. Although internally collections ;; stores only a vector of ids, this function will return a vector of entities. ;; ;; [{:id 1 :name "foo"} {:id 2 :name "bar"}] (def entity-db-v3 (append-collection schema entity-db-v2 :foos :list [{:id 3 :name "baz}])) (get-collection schema entity-db-v3 :foos :list) ;; Returns [{:id 1 :name "foo"} {:id 2 :name "bar} {:id 3 :name "baz"}] ```
(empty-collection db entity-kw collection-key)
(empty-collection db entity-kw collection-key meta)
Empties a collection, but leaves the meta intact. If the new meta is provided it will be merged into the current meta. Entities referenced from the collection will still be stored in the internal store, but won't be available through the collection API.
(def entity-db-v1 {})
(def schema {:foos {:id :id}})
(def foo-entity {:id 1 :name "bar"})
(def entity-db-v2 (insert-collection schema entity-db-v1 :foos :list [foo-entity]))
(get-collection schema entity-db-v2 :foos :list)
;; Returns `[{:id 1 :name "bar"}]`
(def entity-db-v3 (empty-collection schema entity-db-v2 :foos :list))
(get-collection schema entity-db-v2 :foos :list)
;; Returns `[]`
(get-item-by-id schema entity-db-v2 :foos 1)
;; Returns `{:id 1 :name "bar"}`
Empties a collection, but leaves the meta intact. If the new meta is provided it will be merged into the current meta. Entities referenced from the collection will still be stored in the internal store, but won't be available through the collection API. ```clojure (def entity-db-v1 {}) (def schema {:foos {:id :id}}) (def foo-entity {:id 1 :name "bar"}) (def entity-db-v2 (insert-collection schema entity-db-v1 :foos :list [foo-entity])) (get-collection schema entity-db-v2 :foos :list) ;; Returns `[{:id 1 :name "bar"}]` (def entity-db-v3 (empty-collection schema entity-db-v2 :foos :list)) (get-collection schema entity-db-v2 :foos :list) ;; Returns `[]` (get-item-by-id schema entity-db-v2 :foos 1) ;; Returns `{:id 1 :name "bar"}` ```
(get-collection schema db entity-kw collection-key)
(get-collection schema db entity-kw collection-key pull-relations)
Gets collection by it's key. Internally collections store only entity ids, but this function will return a collection of entities based on the ids stored in the collection
(def entity-db-v1 {})
(def schema {:foos {:id :id}})
(def collection [{:id 1 :name "foo"} {:id 2 :name "bar"}])
(def entity-db-v2 (insert-collection schema entity-db-v1 :foos :list collection))
;; Returns the new version of entity db. Each item will be stored
;; in the internal store map and collection will contain only the
;; item ids.
(get-collection schema entity-db-v2 :foos :list)
;; Returns a collection of items named `:list`. Although internally collections
;; stores only a vector of ids, this function will return a vector of entities.
;;
;; [{:id 1 :name "foo"} {:id 2 :name "bar"}]
Gets collection by it's key. Internally collections store only entity ids, but this function will return a collection of entities based on the ids stored in the collection ```clojure (def entity-db-v1 {}) (def schema {:foos {:id :id}}) (def collection [{:id 1 :name "foo"} {:id 2 :name "bar"}]) (def entity-db-v2 (insert-collection schema entity-db-v1 :foos :list collection)) ;; Returns the new version of entity db. Each item will be stored ;; in the internal store map and collection will contain only the ;; item ids. (get-collection schema entity-db-v2 :foos :list) ;; Returns a collection of items named `:list`. Although internally collections ;; stores only a vector of ids, this function will return a vector of entities. ;; ;; [{:id 1 :name "foo"} {:id 2 :name "bar"}] ```
Returns the meta data for a collection.
Returns the meta data for a collection.
(get-item-by-id schema db entity-kw id)
(get-item-by-id schema db entity-kw id pull-relations)
Gets an entity from the store by the id
Gets an entity from the store by the id
(get-item-meta schema db entity-kw id)
Gets meta data for an entity.
Gets meta data for an entity.
(get-named-item schema db entity-kw collection-key)
(get-named-item schema db entity-kw collection-key include-meta)
(get-named-item schema db entity-kw collection-key include-meta pull-relations)
Gets an entity referenced from the named item slot. Internally named slots store only entity ids but this function will return an entity based on the id.
Gets an entity referenced from the named item slot. Internally named slots store only entity ids but this function will return an entity based on the id.
(get-named-item-meta schema db entity-kw collection-key)
Returns the meta data for an entity referenced in the named item slot.
Returns the meta data for an entity referenced in the named item slot.
(insert-collection schema db entity-kw collection-key data)
(insert-collection schema db entity-kw collection-key data meta)
Inserts a collection of items into the EntityDB. Each item will be stored in the internal store map, and the collection will be stored as a vector of entity identities.
(def entity-db-v1 {})
(def schema {:foos {:id :id}})
(def collection [{:id 1 :name "foo"} {:id 2 :name "bar"}])
(def entity-db-v2 (insert-collection schema entity-db-v1 :foos :list collection))
;; Returns the new version of entity db. Each item will be stored
;; in the internal store map and collection will contain only the
;; item ids.
(get-collection schema entity-db-v2 :foos :list)
;; Returns a collection of items named `:list`. Although internally collections
;; stores only a vector of ids, this function will return a vector of entities.
;;
;; [{:id 1 :name "foo"} {:id 2 :name "bar"}]
Inserts a collection of items into the EntityDB. Each item will be stored in the internal store map, and the collection will be stored as a vector of entity identities. ```clojure (def entity-db-v1 {}) (def schema {:foos {:id :id}}) (def collection [{:id 1 :name "foo"} {:id 2 :name "bar"}]) (def entity-db-v2 (insert-collection schema entity-db-v1 :foos :list collection)) ;; Returns the new version of entity db. Each item will be stored ;; in the internal store map and collection will contain only the ;; item ids. (get-collection schema entity-db-v2 :foos :list) ;; Returns a collection of items named `:list`. Although internally collections ;; stores only a vector of ids, this function will return a vector of entities. ;; ;; [{:id 1 :name "foo"} {:id 2 :name "bar"}] ```
(insert-item schema db entity-kw item)
(insert-item schema db entity-kw item meta)
Inserts an item into the EntityDB collection.
(def schema {:foos {:id :id}})
(def entity-db-v1 {})
(def item {:id 1 :name "Foo"})
(def item-meta {:is-loading false})
(def entity-db-v2 (insert-item schema entity-db-v1 :foos item item-meta))
;; Returns the new version of the entity-db with the item inserted
;; inserted into the store
Inserts an item into the EntityDB collection. ```clojure (def schema {:foos {:id :id}}) (def entity-db-v1 {}) (def item {:id 1 :name "Foo"}) (def item-meta {:is-loading false}) (def entity-db-v2 (insert-item schema entity-db-v1 :foos item item-meta)) ;; Returns the new version of the entity-db with the item inserted ;; inserted into the store ```
(insert-item-when-not-nil schema db entity-kw item)
Inserts an entity into the EntityDB if the entity is not nil.
Inserts an entity into the EntityDB if the entity is not nil.
(insert-meta db entity-kw meta-key meta)
Inserts meta data for an entity or collection into the store.
Inserts meta data for an entity or collection into the store.
(insert-named-item schema db entity-kw collection-key item)
(insert-named-item schema db entity-kw collection-key item meta)
Inserts an item into the EntityDB, and references it from the named item slot.
Item will be stored in the internal store, and named item slot will contain only the identity of the item.
(def entity-db-v1 {})
(def schema {:foos {:id :id}})
(def entity-db-v2 (insert-named-item schema entity-db-v1 :foos :current {:id 1 :name "foo"}))
;; Returns the new version of the entity-db with the entity saved in the store and
;; referenced from the `:current` named item slot.
(get-named-item schema entity-db-v2 :foos :current)
;; Returns the entity referenced from the `:current` named slot.
Inserts an item into the EntityDB, and references it from the named item slot. Item will be stored in the internal store, and named item slot will contain only the identity of the item. ```clojure (def entity-db-v1 {}) (def schema {:foos {:id :id}}) (def entity-db-v2 (insert-named-item schema entity-db-v1 :foos :current {:id 1 :name "foo"})) ;; Returns the new version of the entity-db with the entity saved in the store and ;; referenced from the `:current` named item slot. (get-named-item schema entity-db-v2 :foos :current) ;; Returns the entity referenced from the `:current` named slot. ```
(make-dbal schema)
Returns a map with all public functions. These functions will have schema
partially applied to them so you don't have to pass the schema around.
Returns a map with all public functions. These functions will have `schema` partially applied to them so you don't have to pass the schema around.
(prepend-collection schema db entity-kw collection-key data)
(prepend-collection schema db entity-kw collection-key data meta)
Prepends items to an existing collection.
(def entity-db-v1 {})
(def schema {:foos {:id :id}})
(def collection [{:id 1 :name "foo"} {:id 2 :name "bar"}])
(def entity-db-v2 (insert-collection schema entity-db-v1 :foos :list collection))
;; Returns the new version of entity db. Each item will be stored
;; in the internal store map and collection will contain only the
;; item ids.
(get-collection schema entity-db-v2 :foos :list)
;; Returns a collection of items named `:list`. Although internally collections
;; stores only a vector of ids, this function will return a vector of entities.
;;
;; [{:id 1 :name "foo"} {:id 2 :name "bar"}]
(def entity-db-v3 (prepend-collection schema entity-db-v2 :foos :list [{:id 3 :name "baz"}]))
(get-collection schema entity-db-v3 :foos :list)
;; Returns [{:id 3 :name "baz"} {:id 1 :name "foo"} {:id 2 :name "bar"}]
Prepends items to an existing collection. ```clojure (def entity-db-v1 {}) (def schema {:foos {:id :id}}) (def collection [{:id 1 :name "foo"} {:id 2 :name "bar"}]) (def entity-db-v2 (insert-collection schema entity-db-v1 :foos :list collection)) ;; Returns the new version of entity db. Each item will be stored ;; in the internal store map and collection will contain only the ;; item ids. (get-collection schema entity-db-v2 :foos :list) ;; Returns a collection of items named `:list`. Although internally collections ;; stores only a vector of ids, this function will return a vector of entities. ;; ;; [{:id 1 :name "foo"} {:id 2 :name "bar"}] (def entity-db-v3 (prepend-collection schema entity-db-v2 :foos :list [{:id 3 :name "baz"}])) (get-collection schema entity-db-v3 :foos :list) ;; Returns [{:id 3 :name "baz"} {:id 1 :name "foo"} {:id 2 :name "bar"}] ```
(remove-collection db entity-kw collection-key)
Removes the collection. Entities referenced from the collection will still be stored in the internal store, but won't be available through the collection API.
(def entity-db-v1 {})
(def schema {:foos {:id :id}})
(def foo-entity {:id 1 :name "bar"})
(def entity-db-v2 (insert-collection schema entity-db-v1 :foos :list [foo-entity]))
(get-collection schema entity-db-v2 :foos :list)
;; Returns `[{:id 1 :name "bar"}]`
(def entity-db-v3 (remove-collection schema entity-db-v2 :foos :list))
(get-collection schema entity-db-v2 :foos :list)
;; Returns `nil`
(get-item-by-id schema entity-db-v2 :foos 1)
;; Returns `{:id 1 :name "bar"}`
Removes the collection. Entities referenced from the collection will still be stored in the internal store, but won't be available through the collection API. ```clojure (def entity-db-v1 {}) (def schema {:foos {:id :id}}) (def foo-entity {:id 1 :name "bar"}) (def entity-db-v2 (insert-collection schema entity-db-v1 :foos :list [foo-entity])) (get-collection schema entity-db-v2 :foos :list) ;; Returns `[{:id 1 :name "bar"}]` (def entity-db-v3 (remove-collection schema entity-db-v2 :foos :list)) (get-collection schema entity-db-v2 :foos :list) ;; Returns `nil` (get-item-by-id schema entity-db-v2 :foos 1) ;; Returns `{:id 1 :name "bar"}` ```
(remove-item schema db entity-kw id)
Removes item from the store. It will also remove it from any named-item slots or collections.
(def entity-db-v1 {})
(def schema {:foos {:id :id}})
(def foo-entity {:id 1 :name "Bar"})
;; insert `foo-entity` in the `:current` named item slot
(def entity-db-v2 (insert-named-item schema entity-db-v1 :foos :current foo-entity))
;; insert `foo-entity` as a part of the `:list` collection
(def entity-db-v3 (insert-collection schema entity-db-v2 :foos :list [foo-entity]))
;; get `foo-entity` from the entity-db
(get-item-by-id schema entity-db-v3 :foos 1)
;; returns `foo-entity`
(def entity-db-v4 (remove-item schema entity-db :foos 1))
(get-named-item schema entity-db-v4 :foos :current)
;; returns `nil`
(get-collection schema entity-db-v4 :foos :list)
;; returns []
Removes item from the store. It will also remove it from any named-item slots or collections. ```clojure (def entity-db-v1 {}) (def schema {:foos {:id :id}}) (def foo-entity {:id 1 :name "Bar"}) ;; insert `foo-entity` in the `:current` named item slot (def entity-db-v2 (insert-named-item schema entity-db-v1 :foos :current foo-entity)) ;; insert `foo-entity` as a part of the `:list` collection (def entity-db-v3 (insert-collection schema entity-db-v2 :foos :list [foo-entity])) ;; get `foo-entity` from the entity-db (get-item-by-id schema entity-db-v3 :foos 1) ;; returns `foo-entity` (def entity-db-v4 (remove-item schema entity-db :foos 1)) (get-named-item schema entity-db-v4 :foos :current) ;; returns `nil` (get-collection schema entity-db-v4 :foos :list) ;; returns [] ```
(remove-meta db entity-kw id)
Removes any meta data stored on the entity or collection
Removes any meta data stored on the entity or collection
(remove-named-item db entity-kw collection-key)
Removes the named-item slot. Entity will still be stored in the internal store, but won't be available through the named-item slot.
(def entity-db-v1 {})
(def schema {:foos {:id :id}})
(def foo-entity {:id 1 :name "bar"})
(def entity-db-v2 (insert-named-item schema entity-db-v1 :foos :current foo-entity))
(get-named-item schema entity-db-v1 :foos :current)
;; Returns `{:id 1 :name "bar"}`
(def entity-db-v3 (remove-named-item schema entity-db-v2 :foos :current))
(get-named-item schema entity-db-v2 :foos :current)
;; Returns `nil`
(get-item-by-id schema entity-db-v2 :foos 1)
;; Returns `{:id 1 :name "bar"}`
Removes the named-item slot. Entity will still be stored in the internal store, but won't be available through the named-item slot. ```clojure (def entity-db-v1 {}) (def schema {:foos {:id :id}}) (def foo-entity {:id 1 :name "bar"}) (def entity-db-v2 (insert-named-item schema entity-db-v1 :foos :current foo-entity)) (get-named-item schema entity-db-v1 :foos :current) ;; Returns `{:id 1 :name "bar"}` (def entity-db-v3 (remove-named-item schema entity-db-v2 :foos :current)) (get-named-item schema entity-db-v2 :foos :current) ;; Returns `nil` (get-item-by-id schema entity-db-v2 :foos 1) ;; Returns `{:id 1 :name "bar"}` ```
(vacuum db)
Removes orphaned entities from the EntityDB. Any entity that is not referenced in a collection or in a named item slot will be removed from the EntityDB
Removes orphaned entities from the EntityDB. Any entity that is not referenced in a collection or in a named item slot will be removed from the EntityDB
(wrap-collection-fn-with-relation-path relation-fn include-schema?)
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close