Box.Ecto.Changeset (box v0.15.1)
View SourceEcto changeset helper functions.
Summary
Functions
Formats a changeset error
Generates a slug from another field on the schema
Generates a unique value. Requires at least a generator and a length
Hashes a value using Argon2
Puts a default value change if no value is provided
Updates a schema's timestamp from a boolean field. The schema needs to have a virtual field to check if it should update the timestamp or not.
Trims fields values in changeset
Applies a given function a valid changeset
Types
Functions
@spec format_error( {atom(), {String.t(), Keyword.t()}} | {String.t(), Keyword.t()}, [format_error_option()] ) :: String.t()
Formats a changeset error
@spec generate_slug(Ecto.Changeset.t(), [generate_slug_option()]) :: Ecto.Changeset.t()
Generates a slug from another field on the schema
@spec generate_unique(Ecto.Changeset.t(), atom(), Keyword.t()) :: Ecto.Changeset.t()
Generates a unique value. Requires at least a generator and a length
Examples
iex> generate_unique(changeset, :code, generator: Box.Generator.Base64, length: 12)
The above generates a 12 char long base 64 encoded string as ̀:code
Hashes a value using Argon2
@spec put_default_change(Ecto.Changeset.t(), atom(), (-> any()) | any()) :: Ecto.Changeset.t()
Puts a default value change if no value is provided
@spec touch_timestamp(Ecto.Changeset.t(), [touch_timestamp_option()]) :: Ecto.Changeset.t()
Updates a schema's timestamp from a boolean field. The schema needs to have a virtual field to check if it should update the timestamp or not.
By default, the function infers the timestamp field's name from the virtual field's name.
Example
Calling touch_timestamp(changeset, setter: :inverted)
will
attempt to update the inverted_at
timestamp. This can be
overriden with thie :key
option
@spec trim(Ecto.Changeset.t(), [atom()] | atom()) :: Ecto.Changeset.t()
Trims fields values in changeset
@spec update_valid(Ecto.Changeset.t(), (Ecto.Changeset.t() -> Ecto.Changeset.t())) :: Ecto.Changeset.t()
Applies a given function a valid changeset