View Source TUID.ParameterizedType (tuid v0.1.0)

Documentation for TUID.ParameterizedType.

ParameterizedType implemention for use with Ecto to use TUIDs (tagged, unique ids) as Ecto Types.

Summary

Functions

Generates a loaded version of the data.

Casts the given input to the ParameterizedType with the given parameters.

Dumps the given term into an Ecto native type.

Dictates how the type should be treated inside embeds.

Returns the underlying schema type for the ParameterizedType.

Callback to convert the options specified in the field macro into parameters to be used in other callbacks.

Loads the given term into a ParameterizedType.

Functions

Generates a loaded version of the data.

This callback is invoked when a parameterized type is given to field with the :autogenerate flag.

Casts the given input to the ParameterizedType with the given parameters.

Specifically, convert a TUID, such as user_C19xa4ANGXSz72USEyc2m to a binary UUID for storage into the DB.

For more information on casting, see Ecto.Type.cast/1.

Link to this function

dump(slug, dumper, params)

View Source

Dumps the given term into an Ecto native type.

It receives a dumper function in case the parameterized type is also a composite type. In order to dump the inner type, the dumper must be called with the inner type and the inner value as argument.

For more information on dumping, see Ecto.Type.dump/1. Note that this callback will be called when dumping a nil value, unlike Ecto.Type.dump/1.

Link to this function

embed_as(format, params)

View Source

Dictates how the type should be treated inside embeds.

For more information on embedding, see Ecto.Type.embed_as/1

Link to this function

equal?(term1, term2, params)

View Source

Returns the underlying schema type for the ParameterizedType.

For more information on schema types, see Ecto.Type.type/0

Callback to convert the options specified in the field macro into parameters to be used in other callbacks.

This function is called at compile time, and should raise if invalid values are specified. It is idiomatic that the parameters returned from this are a map. field and schema will be injected into the options automatically.

For example, this schema specification

schema "my_table" do
  field :my_field, MyParameterizedType, opt1: :foo, opt2: nil
end

will result in the call:

MyParameterizedType.init([schema: "my_table", field: :my_field, opt1: :foo, opt2: nil])
Link to this function

load(data, loader, params)

View Source

Loads the given term into a ParameterizedType.

It receives a loader function in case the parameterized type is also a composite type. In order to load the inner type, the loader must be called with the inner type and the inner value as argument.

For more information on loading, see Ecto.Type.load/1. Note that this callback will be called when loading a nil value, unlike Ecto.Type.load/1.