(add-edge-with-id g ent-name related-ent-name id)
When indicating :ent-a references :ent-b, include a
:relation-attrs
graph attribute that includes the attributes via
which :ent-a
references :ent-b
.
For example, if the :project
named :p0
has an :owner-id
and
:updated-by-id
that both reference the :user
named :u0
, then
the edge from :p0
to :u0
will if a :relation-attrs
attribute
with value #{:owner-id :updated-by-id}
.
This can be used e.g. to set the values for :owner-id
and
:updated-by-id
.
When indicating :ent-a references :ent-b, include a `:relation-attrs` graph attribute that includes the attributes via which `:ent-a` references `:ent-b`. For example, if the `:project` named `:p0` has an `:owner-id` and `:updated-by-id` that both reference the `:user` named `:u0`, then the edge from `:p0` to `:u0` will if a `:relation-attrs` attribute with value `#{:owner-id :updated-by-id}`. This can be used e.g. to set the values for `:owner-id` and `:updated-by-id`.
(add-ent {:keys [data] :as db} ent-name ent-type query-term)
Add an ent, and its related ents, to the ent-db
Add an ent, and its related ents, to the ent-db
(add-ent-type-query db ent-type-query ent-type)
A query is composed of ent-type-queries, where each ent-type-query specifies the ents that should be created for that type. This function adds the ents for an ent-type-query.
A query is composed of ent-type-queries, where each ent-type-query specifies the ents that should be created for that type. This function adds the ents for an ent-type-query.
(add-n-ents db ent-type num-ents query-term)
Used when a query is something like [3]
Used when a query is something like [3]
(add-ref-ents db)
Ents are added in two stages: first, all ents that are declared in the query are added. During that process, we keep track of ref-ents, ents which are automatically generated in order to satisfy relations. This function adds those ref ents if an ent of the same name doesn't exist already.
Ents are added in two stages: first, all ents that are declared in the query are added. During that process, we keep track of ref-ents, ents which are automatically generated in order to satisfy relations. This function adds those ref ents if an ent of the same name doesn't exist already.
(all-ent-relations db)
(all-ent-relations db ents)
Given a db, returns a map of ent-type to map of entity relations.
An example return value is: {:patient {:p0 {:created-by :u0 :updated-by :u1} :p1 {:created-by :u0 :updated-by :u2}} :user {:u0 {:friends-with :u0}}}
Given a db, returns a map of ent-type to map of entity relations. An example return value is: {:patient {:p0 {:created-by :u0 :updated-by :u1} :p1 {:created-by :u0 :updated-by :u2}} :user {:u0 {:friends-with :u0}}}
(attr-map db attr)
(attr-map {:keys [data] :as db} attr ents)
Produce a map where each key is a node and its value is a graph attr on that node
Produce a map where each key is a node and its value is a graph attr on that node
(bound-descendants? {:keys [types schema relation-graph]}
query-bindings
related-ent-type)
Check whether query-relations
contains bindings that apply to any
descendants of related-ent-type
Check whether `query-relations` contains bindings that apply to any descendants of `related-ent-type`
(bound-relation-attr-name {:keys [schema]} ent-name related-ent-type index)
Template for when a binding necessitates you add a new entity
Template for when a binding necessitates you add a new entity
(build-ent-db {:keys [schema] :as db} query)
Produce a new db that contains all ents specified by query
Produce a new db that contains all ents specified by query
(coll-relation-attr? db ent relation-attr)
Given a db, ent, and relation-attr, determines whether the relation is a coll attr.
Given a db, ent, and relation-attr, determines whether the relation is a coll attr.
(conformed-query-opts query-term relation-attr)
These conformed query opts allow us to 1) validate the query term and 2) dispatch on what kind of query was supplied.
This is one of the most complicated parts of SM because users can
supply different types of values for the :refs
key of a query:
:ent-name
):ent-names
):ent-count
)These types are captured by the ::refs
specs, and the specs it
composes. The type for the supplied query-term is returned as
:qr-type
.
Each of these qr-types corresponds to a constraint of either :coll
or :unary
. The constraint is returned as :qr-constraint
.
Conforming the query opts provides the qr-type
and qr-constraint
so that dependent functions can dispatch on these values.
These conformed query opts allow us to 1) validate the query term and 2) dispatch on what kind of query was supplied. This is one of the most complicated parts of SM because users can supply different types of values for the `:refs` key of a query: 1. an ent-name for unary relations (type: `:ent-name`) 2. a vector of ent-names for coll relations (type: `:ent-names`) 3. a number for coll relations (type: `:ent-count`) These types are captured by the `::refs` specs, and the specs it composes. The type for the supplied query-term is returned as `:qr-type`. Each of these qr-types corresponds to a constraint of either `:coll` or `:unary`. The constraint is returned as `:qr-constraint`. Conforming the query opts provides the `qr-type` and `qr-constraint` so that dependent functions can dispatch on these values.
(default-node-name {:keys [schema]} ent-type)
Whenever specmonstah needs to create a node that's not manually named, it uses this to generate the default name.
Whenever specmonstah needs to create a node that's not manually named, it uses this to generate the default name.
(ent-index g ent-type)
Used to keep track of entity's insertion order in graph relative to other entities of the same type.
Used to keep track of entity's insertion order in graph relative to other entities of the same type.
(ent-related-by-attr? db ent-name related-ent relation-attr)
Is ent A related to ent B by the given relation-attr?
Is ent A related to ent B by the given relation-attr?
(ent-relations db ent)
Given a db and an ent, returns a map of relation attr to ent-name.
Given a db and an ent, returns a map of relation attr to ent-name.
(ent-schema {:keys [schema data]} ent-name)
Given an ent name, return the schema of its corresponding type
Given an ent name, return the schema of its corresponding type
(ents-by-type db)
(ents-by-type db ents)
Given a db, returns a map of ent-type to a set of entities of that type. Optionally pass in a seq of the ents that should be included.
Given a db, returns a map of ent-type to a set of entities of that type. Optionally pass in a seq of the ents that should be included.
(identical-prefixes schema)
Schemas are invalid if two types have the same prefix. This checks that.
Schemas are invalid if two types have the same prefix. This checks that.
(incrementing-node-name {:keys [data schema]} ent-type)
A template for creating distinct node names.
A template for creating distinct node names.
(invalid-constraints schema)
Constraints that reference nonexistent relation attrs
Constraints that reference nonexistent relation attrs
(invalid-schema-relations schema)
Relations that reference nonexistent types
Relations that reference nonexistent types
(numeric-node-name schema ent-type index)
Template for generating a node name
Template for generating a node name
(query-ents {:keys [data queries] :as db})
Get seq of nodes that are explicitly defined in the query
Get seq of nodes that are explicitly defined in the query
(query-relation db ent-name relation-attr)
Returns the conformed relation for an ent's relation-attr. Handles polymorphic relations.
Returns the conformed relation for an ent's relation-attr. Handles polymorphic relations.
(referenced-ent-attrs {:keys [data] :as db} ent-name)
seq of [referenced-ent relation-attr]
seq of [referenced-ent relation-attr]
(related-ents {:keys [schema data] :as db}
ent-name
relation-attr
related-ent-type
query-term)
Returns all related ents for an ent's relation-attr
Returns all related ents for an ent's relation-attr
(related-ents-by-attr {:keys [data] :as db} ent-name relation-attr)
All ents related to ent via relation-attr
All ents related to ent via relation-attr
(relation-attrs {:keys [data]} ent-name referenced-ent)
Given an ent A and an ent it references B, return the set of attrs by which A references B
Given an ent A and an ent it references B, return the set of attrs by which A references B
(relation-attrs-with-constraint db ent-name constraint)
Given an ent name, return all relation attributes which include the constraint.
Given an ent name, return all relation attributes which include the constraint.
(relation-graph schema)
A graph of the type dependencies in a schema. If entities of type
:project
reference an entity of type :user
via :owner-id
, then
this will return a graph where the :project
node connects to the
:user
node
A graph of the type dependencies in a schema. If entities of type `:project` reference an entity of type `:user` via `:owner-id`, then this will return a graph where the `:project` node connects to the `:user` node
(required-ents db ent-name)
For ent A, returns all the referenced ents that ent A requires as specified in the schema's constraints. Used to order ent sequences; ensures that required ents are positioned before the ents that require them.
For ent A, returns all the referenced ents that ent A requires as specified in the schema's constraints. Used to order ent sequences; ensures that required ents are positioned before the ents that require them.
(sort-by-required {:keys [schema data] :as db} ents)
If :a0 depends on :b0, returns the vector [:b0 :a0]
If :a0 depends on :b0, returns the vector [:b0 :a0]
(uniq-relation-attr? db ent relation-attr)
Given a db, ent, and relation-attr, determines whether the relation is a uniq attr.
Given a db, ent, and relation-attr, determines whether the relation is a uniq attr.
(validate-related-ents-query {:keys [schema data] :as db}
ent-name
relation-attr
query-term)
Check that the refs value supplied in a query is a collection if the relation type is collection, or a keyword if the relation type is unary. If the reference is omit, no further validation is required.
Check that the refs value supplied in a query is a collection if the relation type is collection, or a keyword if the relation type is unary. If the reference is omit, no further validation is required.
(visit-ents db visit-key visit-fns)
(visit-ents db visit-key visit-fns ents)
Perform visit-fns
on ents, storing return value as a graph
attribute under visit-key
Perform `visit-fns` on ents, storing return value as a graph attribute under `visit-key`
(visit-ents-once db visit-key visit-fns)
(visit-ents-once db visit-key visit-fns ents)
Like visit-ents
but doesn't call visit-fn
if the ent already
has a visit-key
attribute
Like `visit-ents` but doesn't call `visit-fn` if the ent already has a `visit-key` attribute
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close