mongologic.history
delete
(delete {database :database, {:keys [history-collection]} :entity, :as model-component} record-id)
Deletes the current version of the specified record from the history. This
is meant to be used to clean up history after a failed update, as otherwise
the latest version of a record would be in the history.
Returns:
- the number of records deleted
find-all-by-record-id
(find-all-by-record-id {database :database, {:keys [history-collection]} :entity, :as model-component} id)
Returns the history of the specified record.
find-latest-matching-record-at
(find-latest-matching-record-at {database :database, {:keys [history-collection]} :entity, :as model-component} id datetime conditions)
Returns:
- what was at `datetime` the latest version of the record specified by
`id` that matched the specified `conditions`, or
- nil if a record with the given id is not found anywhere,
including history (i.e. if the record has never existed)
find-record-at
(find-record-at model-component id datetime)
Returns:
- the specified record as it was at the specified time, or
- a map with a :deleted_at key if the record was deleted by the
specified time, or
- nil if a record with the given id is not found anywhere,
including history (i.e. if the record has never existed)
save
(save {database :database, {:keys [history-collection]} :entity, :as model-component} record-id)
Saves the specified record in the history.
Returns:
- [false nil] if the record was not found
- [false {:base [:insert-error]}] if insertion into the database fails
- [true created-history-record] otherwisesave-delete
(save-delete {database :database, {:keys [history-collection]} :entity, :as model-component} record-id)
Saves the delete of the specified record in the history.
Two history records are created, one stores the record that is going to be
deleted, with the original :created_at and :updated_at values, the other
essentially stores the time of the deletion in a :deleted_at field.
Returns:
- [false nil] if the record was not found
- [false {:base [:insert-error]}] if insertion into the database fails
- [true saved-record] otherwise