(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-ents {:keys [schema] :as db} query)
Produce a new db with an ent graph that contains all ents specified by query
Produce a new db with an ent graph that contains all ents specified by 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.
(add-related-ents {:keys [data] :as db} ent-name ent-type query-term)
(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}}}
(assoc-referenced-val ent-data relation-attr relation-val constraints)
Look up related ent's attr value and assoc with parent ent
attr. :coll
relations will add value to a vector.
Look up related ent's attr value and assoc with parent ent attr. `:coll` relations will add value to a vector.
(assoc-referenced-vals db {:keys [ent-name visit-key visit-val]})
A visiting function that sets referenced values.
Given a schema like {:user {} :post {:relations {:created-by [:user :id]}}}
a :post's :created-by
key gets set to the :id
of the :user it references.
A visiting function that sets referenced values. Given a schema like {:user {} :post {:relations {:created-by [:user :id]}}} a :post's `:created-by` key gets set to the `:id` of the :user it references.
(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 [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
(bound-relation-attr-name-source ent-name)
(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 datapotato needs to create a node that's not manually named, it uses this to generate the default name.
Whenever datapotato needs to create a node that's not manually named, it uses this to generate the default name.
(ent-attr {:keys [data]} ent-name attr)
(ent-attrs {:keys [data]} ent-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-relation-constraints db ent 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 {:keys [data]})
returns all ents in the ent db
returns all ents in the ent db
(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.
(init-db {:keys [schema] :as db} query)
(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
(merge-overwrites _db {:keys [visit-val visit-query-opts schema-opts]})
Overwrites generated data with what's found in schema-opts or visit-query-opts.
Overwrites generated data with what's found in schema-opts or visit-query-opts.
(numeric-node-name schema ent-type index)
Template for generating a node name
Template for generating a node name
(omit-relation? db ent-name reference-key)
(omit? x)
(prune-required {:keys [data] :as db} required-attrs)
Updates ent graph, removing edges going from a 'required' ent to the 'requiring' ent, thus eliminating cycles.
Updates ent graph, removing edges going from a 'required' ent to the 'requiring' ent, thus eliminating cycles.
(query-ents {:keys [data] :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-opts {:keys [data]} ent-name)
(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-attrs {:keys [schema]})
Returns a map of {:ent-type #{:required-attr-1 :required-attr-2}}
.
Used to handle cycles.
Returns a map of `{:ent-type #{:required-attr-1 :required-attr-2}}`. Used to handle cycles.
(reset-relations db {:keys [ent-name visit-val]})
Generated data generates values agnostic of any schema constraints that may be
present. This function updates values in the generated data to match up with
constraints. First, it will remove any dummy ID's for a :coll
relation.
Next, it will remove any dummy ID's generated for an :omit
relation. The
updated ent-data map will be returned.
Generated data generates values agnostic of any schema constraints that may be present. This function updates values in the generated data to match up with constraints. First, it will remove any dummy ID's for a `:coll` relation. Next, it will remove any dummy ID's generated for an `:omit` relation. The updated ent-data map will be returned.
(sort-by-required db)
(sort-ents db)
Attempts to topsort ents. If that's not possible (cycles present),
uses sort-by-required
to resolve ordering of ents in cycle
Attempts to topsort ents. If that's not possible (cycles present), uses `sort-by-required` to resolve ordering of ents in cycle
(throw-invalid-spec arg-name spec data)
(topsort-ents {:keys [data]})
(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 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
(visit-fn-data db ent visit-key)
When a visit fn is called, it's passed this map as its second argument
When a visit fn is called, it's passed this map as its second argument
(wrap-gen-data-visiting-fn data-generating-visiting-fn)
Useful when writing visiting fns where data generated for ent A needs to be referenced by ent B.
Useful when writing visiting fns where data generated for ent A needs to be referenced by ent B.
(wrap-incremental-insert-visiting-fn source-key inserting-visiting-fn)
Takes generated data stored as an attributed under source-key
and inserts it
using inserting-visiting-fn
.
Respects overwrites and ensures that referenced vals are assoc'd in before inserting. Useful when dealing with db-generated ids.
Takes generated data stored as an attributed under `source-key` and inserts it using `inserting-visiting-fn`. Respects overwrites and ensures that referenced vals are assoc'd in before inserting. Useful when dealing with db-generated ids.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close