(add-path relationship)
Adds relationship's top-level path, using either the :as alias or column name as the segment.
Adds relationship's top-level path, using either the :as alias or column name as the segment.
(by-type relationships)
Groups relationships by relationship type.
Groups relationships by relationship type.
(group-fields fields)
Takes collection of fields, groups by field :type.
Takes collection of fields, groups by field :type.
(group-relationships table)
Takes a parsed data spec. Breaks out relationships from a table's fields, groups them into one-to-one and one-to-many, promotes the one-to-ones up to the root level, and also promotes the first level of many-to-many to the root level.
It also builds a path for each relationship that describes how to associate data into the correct shape for the spec.
The effect is that all the groups of one-to-one relationships that can be queried from the database together are grouped at the same level together, and all of each group's one-to-many relationships are at the top level of the group.
One-to-many relationships constitute deeper levels in the tree.
Eg., a spec like this (non-essential parts elided): {:type :table :name "foo" :fields ({:type :relationship :source-table {:name "foo"} :column :foo/bar_id :target {:type :table :name "bar" :fields ({:type :relationship :source-table {:name "bar"} :column :bar/fizz_id :target {:type :table :name "fizz" :fields ({:type :relationship :source-table {:name "fizz"} :column :buzz/fizz_id :target {:type :table :name "buzz"}})}})}} {:type :relationship :source-table {:name "foo"} :column :baz/foo_id :target {:type :table :name "baz"}})}
Would get analyzed to: {:type :table :name "foo" :relationships {:one [{:type :relationship :source-table {:name "foo"} :column :foo/bar_id :path (:bar_id) :target {:type :table :name "bar"}} {:type :relationship :source-table {:name "bar"} :column :bar/fizz_id :path (:bar_id :fizz_id) :target {:type :table :name "fizz"}}] :many [{:type :relationship :source-table {:name "foo"} :column :baz/foo_id :path :target {:type :table :name "baz"}} {:type :relationship :source-table {:name "fizz"} :column :buzz/fizz_id :target {:type :table :name "buzz"}}]}}
Takes a parsed data spec. Breaks out relationships from a table's fields, groups them into one-to-one and one-to-many, promotes the one-to-ones up to the root level, and also promotes the first level of many-to-many to the root level. It also builds a path for each relationship that describes how to associate data into the correct shape for the spec. The effect is that all the groups of one-to-one relationships that can be queried from the database together are grouped at the same level together, and all of each group's one-to-many relationships are at the top level of the group. One-to-many relationships constitute deeper levels in the tree. Eg., a spec like this (non-essential parts elided): {:type :table :name "foo" :fields ({:type :relationship :source-table {:name "foo"} :column :foo/bar_id :target {:type :table :name "bar" :fields ({:type :relationship :source-table {:name "bar"} :column :bar/fizz_id :target {:type :table :name "fizz" :fields ({:type :relationship :source-table {:name "fizz"} :column :buzz/fizz_id :target {:type :table :name "buzz"}})}})}} {:type :relationship :source-table {:name "foo"} :column :baz/foo_id :target {:type :table :name "baz"}})} Would get analyzed to: {:type :table :name "foo" :relationships {:one [{:type :relationship :source-table {:name "foo"} :column :foo/bar_id :path (:bar_id) :target {:type :table :name "bar"}} {:type :relationship :source-table {:name "bar"} :column :bar/fizz_id :path (:bar_id :fizz_id) :target {:type :table :name "fizz"}}] :many [{:type :relationship :source-table {:name "foo"} :column :baz/foo_id :path :target {:type :table :name "baz"}} {:type :relationship :source-table {:name "fizz"} :column :buzz/fizz_id :target {:type :table :name "buzz"}}]}}
(one-to-one? {:keys [source-table column] :as relationship})
True if relationship for table is a one-to-many.
True if relationship for table is a one-to-many.
(path-prepender path-seg)
Takes a path segment and returns a function that takes a relationship and returns the relationship with the path segment prepended to its path.
Takes a path segment and returns a function that takes a relationship and returns the relationship with the path segment prepended to its path.
(promote-relationships rels)
Takes a relationship map with :one
and :many
keys. Returns a
new relationship map where the first level of nested :one
relationships has been promoted to the top level, and the :many
relationships of all the resulting single relationships have been
promoted top the top level :many
relationships. Promoted
relationships have the path segment from their parent's path
prepended to their own.
Takes a relationship map with `:one` and `:many` keys. Returns a new relationship map where the first level of nested `:one` relationships has been promoted to the top level, and the `:many` relationships of all the resulting single relationships have been promoted top the top level `:many` relationships. Promoted relationships have the path segment from their parent's path prepended to their own.
(relationship-type relationship)
Takes a table and relationship. Returns sither :one-to-one if a one-to-one relationship, or :one-to-many if a one-to-many relationship.
Takes a table and relationship. Returns sither :one-to-one if a one-to-one relationship, or :one-to-many if a one-to-many relationship.
(relationship? x)
True if x is a relationship spec.
True if x is a relationship spec.
(repeated-join-tables rels)
Takes a collection of relationships and returns a collection of any repeated tables, or nil if none.
Takes a collection of relationships and returns a collection of any repeated tables, or nil if none.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close