Versioned (Versioned v0.2.1) View Source
Tools for operating on versioned records.
Link to this section Summary
Functions
Given a versioned struct, populate its :version_id field.
Deletes a struct using its primary key and adds a deleted version.
Get a version by its (version) id where module is the non-version schema.
Get the most recent version of module with the given entity_id.
List all versions for a schema module, newest first.
Get the query to fetch all the versions for a schema, newest first.
Inserts a versioned struct defined via Ecto.Schema or a changeset.
Get the timestamp for the very first version of this entity.
Preload version associations.
Updates a changeset (of a versioned schema) using its primary key.
True if the given module or struct is a version.
Get the version module from the subject module.
True if the Ecto.Schema module is versioned.
Build the query to populate the :version_id virtual field on a versioned
entity.
Link to this section Functions
Specs
Given a versioned struct, populate its :version_id field.
Specs
delete( struct_or_changeset :: Ecto.Schema.t() | Ecto.Changeset.t(), opts :: Keyword.t() ) :: {:ok, Ecto.Schema.t()} | {:error, any()} | {:error, Ecto.Multi.name(), any(), %{required(Ecto.Multi.name()) => any()}}
Deletes a struct using its primary key and adds a deleted version.
Specs
get(module(), any(), keyword()) :: Ecto.Schema.t() | nil
Get a version by its (version) id where module is the non-version schema.
Options can include anything used by the repo's get/3.
Specs
get_last(module(), any(), keyword()) :: Ecto.Schema.t() | nil
Get the most recent version of module with the given entity_id.
Options can include anything used by the repo's get/3.
Specs
history(module() | Ecto.Schema.t(), any(), keyword()) :: [Ecto.Schema.t()]
List all versions for a schema module, newest first.
History will be found based on a module name and id or pass in a struct.
Options can include anything used by the repo's all/2 and
history_query/3.
Specs
history_query(module(), any(), keyword()) :: Ecto.Queryable.t()
Get the query to fetch all the versions for a schema, newest first.
Options
:limit- Max number of records to return. Default: return all records.
Specs
insert(Ecto.Schema.t() | Ecto.Changeset.t(), keyword()) :: {:ok, Ecto.Schema.t()} | {:error, any()} | {:error, Ecto.Multi.name(), any(), %{required(Ecto.Multi.name()) => any()}}
Inserts a versioned struct defined via Ecto.Schema or a changeset.
This function calls to the Ecto.Repo module twice -- once to insert the
record itself, and once to insert a copy as the first version in the
versions table.
Specs
inserted_at(struct()) :: DateTime.t() | nil
Get the timestamp for the very first version of this entity.
Specs
preload(Ecto.Schema.t() | [Ecto.Schema.t()] | nil, atom() | list() | nil) :: Ecto.Schema.t() | [Ecto.Schema.t()]
Preload version associations.
Example
iex> pv = Repo.get(Person.Version, "7f85b58b-ef57-4288-ade0-ff47f0ceb116")
iex> Versioned.preload(pv, :fancy_hobby_versions)
%Person.Version{
id: "7f85b58b-ef57-4288-ade0-ff47f0ceb116",
fancy_hobby_versions: [
%{id: "a2a911fb-e2a6-459c-93e2-616be0fa1a45", name: "Jenga"}
]
}
Specs
update(Ecto.Changeset.t(), keyword()) :: {:ok, Ecto.Schema.t()} | {:error, any()} | {:error, Ecto.Multi.name(), any(), %{required(Ecto.Multi.name()) => any()}}
Updates a changeset (of a versioned schema) using its primary key.
This function uses the Ecto.Repo module, first calling update/2 to update
the record itself, and then insert/1 to add a copy of the new version to
the versions table.
Specs
version?(module() | Ecto.Schema.t()) :: boolean()
True if the given module or struct is a version.
Specs
Get the version module from the subject module.
Specs
versioned?(module() | Ecto.Schema.t()) :: boolean()
True if the Ecto.Schema module is versioned.
This means there is a corresponding Ecto.Schema module with an extra ".Version" on the end.
Specs
with_version_id(Ecto.Queryable.t(), Ecto.Schema.t() | nil) :: Ecto.Query.t()
Build the query to populate the :version_id virtual field on a versioned
entity.
query may be any existing base query for the entity which is versioned.
mod, if defined, should be the entity module name itself. If not defined,
query must be this module name and not any type of query.