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

@spec add_version_id(map()) :: map()

Given a versioned struct, populate its :version_id field.

Link to this function

delete!(struct_or_changeset, opts \\ [])

View Source
@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.

Link to this function

delete(struct_or_changeset, opts \\ [])

View Source
@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.

Link to this function

get(module, ver_id, opts \\ [])

View Source
@spec get(module(), any(), keyword()) :: Ecto.Schema.t() | nil

Proxy function for the given repo module's get/3.

Link to this function

get_by(queryable, clauses, opts \\ [])

View Source
@spec get_by(Ecto.Queryable.t(), keyword() | map(), keyword()) ::
  Ecto.Schema.t() | nil

Proxy function for the given repo module's get_by/3.

Link to this function

get_last(module, entity_id, opts \\ [])

View Source
@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.

Link to this function

history(module_or_struct, id_or_opts \\ [], opts \\ [])

View Source
@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.

Link to this function

history_query(module, id, opts \\ [])

View Source
@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.
Link to this function

insert!(struct_or_changeset, opts \\ [])

View Source
@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.

Link to this function

insert(struct_or_changeset, opts \\ [])

View Source
@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.

Link to this function

one(queryable, opts \\ [])

View Source
@spec one(
  Ecto.Queryable.t(),
  keyword()
) :: Ecto.Schema.t() | nil

Proxy function for the given repo module's one/3.

Link to this function

preload(list_or_struct, preload)

View Source
@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"}
  ]
}
Link to this function

update!(struct_or_changeset, opts \\ [])

View Source
@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.

Link to this function

update(changeset, opts \\ [])

View Source
@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.

@spec version_mod(module()) :: module()

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.

Link to this function

with_version_id(queryable, mod \\ nil)

View Source
@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.