Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
72 lines (58 sloc) 2.03 KB
(ns twitteur.utils.model.dml
"A lightweight functional DSL for writing Domain Model transactions.")
(defn- merge-clauses
"Incorporate DSL clauses into the map `m`. A DSL clause may be:
- a String, which will result in a :twitteur.schema/doc property
- a Map, which will be merged into the returned Map."
[m clauses]
(fn [m clause]
(string? clause) (assoc m :twitteur.schema/doc clause)
(map? clause) (merge m clause)
(throw (ex-info "Unidentified DML clause"
{::clause clause}))))
m clauses))
;; ------------------------------------------------------------------------------
;; Entity Type DSL
(defn entity-type
[ent-type-name & clauses]
{:twitteur.entity-type/name ent-type-name}
;; ------------------------------------------------------------------------------
;; Attribute DSL
(defn scalar
[name type & clauses]
{:twitteur.attribute/name name
:twitteur.attribute/ref-typed? false
:twitteur.attribute.scalar/type type}
(defn- ref-attr
[name type many? & clauses]
{:twitteur.attribute/name name
:twitteur.attribute/ref-typed? true
:twitteur.attribute.ref-typed/many? many?
:twitteur.attribute.ref-typed/type {:twitteur.entity-type/name type}}
(defn to-one
[name type & clauses]
(apply ref-attr name type false clauses))
(defn to-many
[name type & clauses]
(apply ref-attr name type true clauses))
(defn unique-id
"Marks this Attribute as uniquely identifying the Entities that have it (via `:twitteur.attribute/unique-identity`)."
{:twitteur.attribute/unique-identity true})
(defn private
"Marks this Attribute as not being publicly visible on Twitteur (via ``)."
{ true})
(defn derived
"Marks this Attribute as being computed from other Attributes (via `:twitteur.attribute/derived?`)."
{:twitteur.attribute/derived? true})