Revisionair v0.12.0 Revisionair.Storage behaviour

The Revisionair.Storage behaviour can be implemented by any persistence layer. It is used to:

  • Store the current version of a struct before it is updated.
  • Retrieve a previous version of a struct with a certain identifier.
  • List the whole history of a certain struct.

Because Revisionair.Storage is a behaviour, you are not limited in any way by the kind of persistence layer you want to use.

Note that, while written out in this behaviour, some Storage implementations might put restrictions on the kind of values structure_type and/or unique_identifier might have.

Metadata

A persistence layer is allowed to add more keys to the metadata map that was sent in.

At least, the :revision key must be set, as this can be used later to uniquely identify a single revision of a certain data structure, which is used in get_revision/3.

Options

It is possible to receive additional options; this will be the list of fields passed in from the storage_options: field of the Revisionair functions.

If you require default values for these options, add a configuration for your specific adapter implementation. This means that the configuration of different storage adapters will not interfere with one another.

Summary

Callbacks

Deletes all revisions for the given {structure_type, unique_identifier}

Returns a {structure, metadata}-list of all revisions of the given struture, newest-to-oldest

Returns the newest revision for the given {structure_type, unique_identifier} combination

Stores a new revision for the given map, uniquely identified by the {structure_type, unique_identifier} combination

Types

metadata()
metadata() :: %{revision: any}
options()
options() :: list
revision()
revision() :: any
structure()
structure() :: %{}
structure_type()
structure_type() :: integer | bitstring | atom
unique_identifier()
unique_identifier() :: integer | bitstring | atom

Callbacks

delete_all_revisions_of(structure_type, unique_identifier, options)
delete_all_revisions_of(structure_type, unique_identifier, options) ::
  :ok |
  :error

Deletes all revisions for the given {structure_type, unique_identifier}

get_revision(structure_type, unique_identifier, revision, options)
get_revision(structure_type, unique_identifier, revision, options) ::
  {:ok, {structure, metadata}} |
  :error
list_revisions(structure_type, unique_identifier, options)

Returns a {structure, metadata}-list of all revisions of the given struture, newest-to-oldest.

The metadata field is required to be a map, which has to include a :revision field.

newest_revision(structure_type, unique_identifier, options)
newest_revision(structure_type, unique_identifier, options) ::
  {:ok, {structure, metadata}} |
  :error

Returns the newest revision for the given {structure_type, unique_identifier} combination.

This callback is supplied decoupled from list_revisions for efficiency, because it is very common to check only the newest revision.

store_revision(structure, structure_type, unique_identifier, metadata, options)
store_revision(structure, structure_type, unique_identifier, metadata, options) ::
  :ok |
  :error

Stores a new revision for the given map, uniquely identified by the {structure_type, unique_identifier} combination.