Rivet.Ecto.Collection behaviour (rivet v2.5.2)

View Source

For data models using Ecto. Options:

id_type: :uuid, :intid, :none — how to handle record ID features: [:short_id] — enable/disable ShortId required: [:field, ...] — list of fields required for this model update: [:field, ...] — list of fields allowed to be updated on this model create: [:field, ...] — list of additional fields allowed only on creation.

                      unlike the other fields, whatever is provided is
                      concatenated to required and update. This defaults
                      to `[:id]`, so specify it as `[]` for no additional
                      create fields.

foreign_keys: [:field, ...] - list of foreign key constraints (if any) unique: [:field, ...] — list of unique constraints (if any)

recap:

  • create: ONLY on create, but is still optional (default: :id)
  • required: MUST exist on create, and at the intersection of required and update, those values must also exist
  • update: things that can be updated

Note: fk and unique may also be tuple: {:key, [keyword-list options]}

Summary

Functions

iex> enrich_query_args(%Ecto.Query{}, order_by: [asc: :asdf]) #Ecto.Query<from q0 in query, order_by: [asc: q0.asdf]> iex> enrich_query_args(%Ecto.Query{}, desc: :asdf) #Ecto.Query<from q0 in query, order_by: [desc: q0.asdf]> iex> enrich_query_args(%Ecto.Query{}, asc: :asdf) #Ecto.Query<from q0 in query, order_by: [asc: q0.asdf]> iex> enrich_query_args(%Ecto.Query{}, limit: 10) #Ecto.Query<from q0 in query, limit: ^10> iex> enrich_query_args(%Ecto.Query{}, preload: [:narf]) #Ecto.Query<from q0 in query, preload: [:narf]> iex> enrich_query_args(%Ecto.Query{}, select: [:narf]) #Ecto.Query<from q0 in query, select: [:narf]>

Callbacks

build(params)

(optional)
@callback build(params :: map()) :: Ecto.Changeset.t()

change_post(item, changes)

(optional)
@callback change_post(item :: map(), changes :: map()) :: map()

change_prep(item, changes)

(optional)
@callback change_prep(item :: map(), changes :: map()) :: {:ok, map()}

changeset(item, params)

(optional)
@callback changeset(item :: map(), params :: map()) :: Ecto.Changeset.t()

create_post(item, changes)

(optional)
@callback create_post(item :: map(), changes :: map()) :: map()

create_prep(item, changes)

(optional)
@callback create_prep(item :: map(), changes :: map()) :: {:ok, map()}

delete(item)

(optional)
@callback delete(item :: map()) :: {:ok | :error, Ecto.Changeset.t() | map()}

validate(t)

(optional)
@callback validate(Ecto.Changeset.t()) :: Ecto.Changeset.t()

Functions

enrich_query_args(query, args)

iex> enrich_query_args(%Ecto.Query{}, order_by: [asc: :asdf]) #Ecto.Query<from q0 in query, order_by: [asc: q0.asdf]> iex> enrich_query_args(%Ecto.Query{}, desc: :asdf) #Ecto.Query<from q0 in query, order_by: [desc: q0.asdf]> iex> enrich_query_args(%Ecto.Query{}, asc: :asdf) #Ecto.Query<from q0 in query, order_by: [asc: q0.asdf]> iex> enrich_query_args(%Ecto.Query{}, limit: 10) #Ecto.Query<from q0 in query, limit: ^10> iex> enrich_query_args(%Ecto.Query{}, preload: [:narf]) #Ecto.Query<from q0 in query, preload: [:narf]> iex> enrich_query_args(%Ecto.Query{}, select: [:narf]) #Ecto.Query<from q0 in query, select: [:narf]>