View Source Versioned (Versioned v0.4.0)
Tools for operating on versioned records.
Link to this section Summary
Functions
Given a versioned struct
, populate its :version_id
field.
Same as delete/2
but returns the struct or raises if the changeset is
invalid.
Deletes a struct using its primary key and adds a deleted version.
Proxy function for the given repo module's get/3
.
Proxy function for the given repo module's get_by/3
.
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.
Same as insert/2
but returns the struct or raises if the changeset is
invalid.
Inserts a versioned struct defined via Ecto.Schema or a changeset.
Get the timestamp for the very first version of this entity.
Proxy function for the given repo module's one/3
.
Preload version associations.
Same as update/2
but returns the struct or raises if the changeset is
invalid.
Updates a versioned changeset using its primary key.
Get the version module from the subject module.
True if the given module or struct is a version.
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
Given a versioned struct
, populate its :version_id
field.
@spec delete!( Ecto.Schema.t() | Ecto.Changeset.t(), keyword() ) :: Ecto.Schema.t() | no_return()
Same as delete/2
but returns the struct or raises if the changeset is
invalid.
@spec delete( Ecto.Schema.t() | Ecto.Changeset.t(), keyword() ) :: {: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.
@spec get(module(), any(), keyword()) :: Ecto.Schema.t() | nil
Proxy function for the given repo module's get/3
.
@spec get_by(Ecto.Queryable.t(), keyword() | map(), keyword()) :: Ecto.Schema.t() | nil
Proxy function for the given repo module's get_by/3
.
@spec 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
.
@spec 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
.
@spec history_query(module(), any(), keyword()) :: Ecto.Queryable.t()
Get the query to fetch all the versions for a schema, newest first.
options
Options
:limit
- Max number of records to return. Default: return all records.
@spec insert!( Ecto.Schema.t() | Ecto.Changeset.t(), keyword() ) :: Ecto.Schema.t() | no_return()
Same as insert/2
but returns the struct or raises if the changeset is
invalid.
@spec 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.
@spec inserted_at(struct()) :: DateTime.t() | nil
Get the timestamp for the very first version of this entity.
@spec one( Ecto.Queryable.t(), keyword() ) :: Ecto.Schema.t() | nil
Proxy function for the given repo module's one/3
.
@spec preload(Ecto.Schema.t() | [Ecto.Schema.t()] | nil, atom() | list() | nil) :: Ecto.Schema.t() | [Ecto.Schema.t()]
Preload version associations.
example
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"}
]
}
@spec update!( Ecto.Changeset.t(), keyword() ) :: Ecto.Schema.t() | no_return()
Same as update/2
but returns the struct or raises if the changeset is
invalid.
@spec update( Ecto.Changeset.t(), keyword() ) :: {:ok, Ecto.Schema.t()} | {:error, any()} | {:error, Ecto.Multi.name(), any(), %{required(Ecto.Multi.name()) => any()}}
Updates a versioned changeset using its primary key.
Get the version module from the subject module.
@spec version?(module() | Ecto.Schema.t()) :: boolean()
True if the given module or struct is a version.
@spec 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.
@spec 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.