aggregate.core

->1

(->1 relation-kw entity-kw)(->1 relation-kw entity-kw options)
Returns a relation-spec for a :one> relationship.
Available options:
:fk-kw            A keyword denoting the foreign-key name.
:owned?           A boolean telling if the related entity is owned,
                  i.e. will be deleted when the owner or the link is
                  deleted. Defaults to true.

->mn

(->mn relation-kw entity-kw)(->mn relation-kw entity-kw options)
Returns a relation-spec for a :<many> relationship.
Available options:
:query-fn         A function returning records by a foreign key.
:update-links-fn  A function for updating link table records.
:owned?           A boolean telling if the related entity is owned,
                  i.e. will be deleted when the owner or the link is
                  deleted. Defaults to false.

->n

(->n relation-kw entity-kw)(->n relation-kw entity-kw options)
Returns a relation-spec for a :<many relationship.
Available options:
:fk-kw            A keyword denoting the foreign-key name.
:query-fn         A function returning records by a foreign key.
:owned?           A boolean telling if the related entity is owned,
                  i.e. will be deleted when the owner or the link is
                  deleted. Defaults to true.

delete!

(delete! er-config db-spec m)(delete! er-config db-spec entity-kw m-or-id)
Removes an aggregate datastructure from the database.
Returns the number of deleted records.

entity

(entity & args)
Returns an entity-spec from an entity keyword, an optional
options-map and an arbitrary number of relation-specs, i.e.
    (agg/entity entity-kw options-map? relations)
Available options:
:read-fn       A function (fn [db-spec id]) returning the
               record with primary key value id as a map.
:insert-fn     A function (fn [db-spec row-map]) that inserts
               the row-map as record, and returns the row-map
               containing the new primary key value.
:update-fn     A function (fn [db-spec set-map]) that updates
               the record identified by the primary key value
               within set-map with the values of set-map.
:delete-fn     A function (fn [db-spec id]) that deletes the
               record identified by the primary key value.
:id-kw         The keyword to be used to get/assoc the primary
               key value. It is also used as primary key
               column name in default DB access functions.

extract-id

(extract-id id-kw insert-result)
Extracts id value from results like ({:scope_identity() 2}) or ({:id 2, ...}).

load

(load er-config db-spec entity-kw id)(load er-config db-spec m)
Loads an aggregate by id, the entity-kw denotes the aggregate root.
Returns a map containing the entity-kw in ::entity and all data, or
nil if the entity-kw is unknown or the record does not exist.

make-delete-fn

(make-delete-fn tablename id-kw)
Returns a delete function [db-spec id -> (Seq id)] for a specific
table, which deletes the record id points to. It returns the number
of deleted records (usually 1), or nil if none was deleted.
The tablename may be passed as string or keyword.

make-entity-options

(make-entity-options tablename)(make-entity-options tablename id-kw)
Returns a map containing all four default JDBC based implementations
for read, insert, update and delete.

make-er-config

(make-er-config & args)
Creates a er-config map from an optional options-map and an
arbitrary number of entity-specs, i.e.
    (agg/make-er-config options-map? entities)
Available options:
:read-fn-factory          A function (fn [tablename]) returning the
                          default read function.
:insert-fn-factory        A function (fn [tablename]) returning the
                          default insert function.
:update-fn-factory        A function (fn [tablename]) returning the
                          default update function.
:delete-fn-factory        A function (fn [tablename]) returning the
                          default delete function.
:query-<many-fn-factory   A function (fn [tablename fk-kw]) returning
                          the default query-for-many function using
                          one foreign key.
:query-<many>-fn-factory  A function (fn [tablename linktablename fk-a fk-b])
                          returning the default query-for-many function
                          that uses a linktable.
:update-links-fn-factory  A function (fn [linktablename fk-a fk-b])
                          returning the default function to update
                          link tables.
:id-kw                    A keyword that is taken as default primary
                          key column name.
:persisted-pred-fn        A predicate (fn [db-spec entity-kw id-kw row-map])
                          that returns true if the given row-map is already
                          present in DB.

make-insert-fn

(make-insert-fn tablename id-kw)
Returns an insert function [db-spec row-map -> row-map] for a specific table.
It returns the record, possibly augmented with the generated id in
an :id slot. The tablename may be passed as string or keyword.

make-query-<many-fn

(make-query-<many-fn tablename fk-kw)
Returns a finder function [db-spec id -> (Seq Map)] for a specific
table, that returns -- as sequence of maps -- all records that have
id as value of the foreign key field denoted by fk-kw.
Assumes a simple n to 1 relationship.

make-query-<many>-fn

(make-query-<many>-fn tablename linktablename fk-a fk-b)(make-query-<many>-fn tablename linktablename fk-a fk-b b-id-kw)
Returns a finder function [db-spec id -> (Seq Map)] for a
specific table whose records are in a m to n relationship
realized by a link table containing two foreign keys. The
function returns a sequence of maps.

make-read-fn

(make-read-fn tablename id-kw)
Returns a read function [db-spec id -> row-map] for a specific table.
It returns a single record or nil. The tablename may be passed as
string or keyword.

make-update-fn

(make-update-fn tablename id-kw)
Returns an update function [db-spec set-map -> set-map] for a
specific table, which takes a map of values and updates the record
denoted by the :id contained in set-map. It returns the set-map.
The tablename may be passed as string or keyword.

only

(only er-config & entity-relation-seqs)
Removes all relations that are NOT specified by the vectors.
A vector must begin with an entity-kw, all remaining items denote
relations.

persisted?

(persisted? db-spec entity-kw id-kw m)
Returns true if the map m has already been persisted.
It is assumed that the existence of an id-kw key is enough evidence.

save!

(save! er-config db-spec m)(save! er-config db-spec entity-kw m)
Saves an aggregate data structure to the database.

without

(without er-config & entities-or-entity-relation-seqs)
Removes entities (specified by a keyword) and relations (specified
in a vector, where the first item is the entity keyword) from the er-config.