crontab v1.1.0 Crontab.CronExpression.Ecto.Type

Provides a type for Ecto usage.

The underlying data type should be a map.

Migration Example

create table(:my_table) do
  add :schedule, :map
end

Schema Example

schema "my_table" do
  field :schedule, CronExpression.Ecto.Type
end

Summary

Functions

Casts the given input to the custom type

Dumps the given term into an Ecto native type

Loads the given term into a custom type

Returns the underlying schema type for the custom type

Types

map_expression()
map_expression() :: %{extended: boolean, reboot: boolean, second: [Crontab.CronExpression.value], minute: [Crontab.CronExpression.value], hour: [Crontab.CronExpression.value], day: [Crontab.CronExpression.value], month: [Crontab.CronExpression.value], weekday: [Crontab.CronExpression.value], year: [Crontab.CronExpression.value]}

Functions

cast(cron_expression)
cast(any) :: {:ok, Crontab.CronExpression.t} | :error

Casts the given input to the custom type.

This callback is called on external input and can return any type, as long as the dump/1 function is able to convert the returned value back into an Ecto native type. There are two situations where this callback is called:

  1. When casting values by Ecto.Changeset
  2. When passing arguments to Ecto.Query

Callback implementation for Ecto.Type.cast/1.

dump(arg1)
dump(any) :: {:ok, Crontab.CronExpression.t} | :error

Dumps the given term into an Ecto native type.

This callback is called with any term that was stored in the struct and it needs to validate them and convert it to an Ecto native type.

Callback implementation for Ecto.Type.dump/1.

load(arg1)
load(any) :: {:ok, Crontab.CronExpression.t} | :error

Loads the given term into a custom type.

This callback is called when loading data from the database and receive an Ecto native type. It can return any type, as long as the dump/1 function is able to convert the returned value back into an Ecto native type.

Callback implementation for Ecto.Type.load/1.

type()
type() :: :map

Returns the underlying schema type for the custom type.

For example, if you want to provide your own date structures, the type function should return :date.

Note this function is not required to return Ecto primitive types, the type is only required to be known by the adapter.

Callback implementation for Ecto.Type.type/0.