EctoSparkles.ErlangTermBinary (ecto_sparkles v0.1.1)

A custom Ecto type for handling the serialization of arbitrary data types stored as binary data in the database. Requires the underlying DB field to be a binary.

Link to this section Summary

Functions

Callback implementation for Ecto.Type.cast/1.

Provides custom casting rules for params. Nothing changes here. We only need to handle deserialization.

Converting the data structure to binary for storage.

Callback implementation for Ecto.Type.embed_as/1.

Callback implementation for Ecto.Type.equal?/2.

Convert the raw binary value from the database back to the desired term.

Callback implementation for Ecto.Type.type/0.

Link to this section Functions

Callback implementation for Ecto.Type.cast/1.

Link to this function

cast(atom, term)

Provides custom casting rules for params. Nothing changes here. We only need to handle deserialization.

Converting the data structure to binary for storage.

Callback implementation for Ecto.Type.embed_as/1.

Link to this function

equal?(term1, term2)

Callback implementation for Ecto.Type.equal?/2.

Link to this function

load(raw_binary)

Convert the raw binary value from the database back to the desired term.

Uses Plug.Crypto.non_executable_binary_to_term/2 - a restricted version of :erlang.binary_to_term/2 that forbids executable terms, such as anonymous functions.

By default this function does not restrict atoms, except if compiled in prod env, then the [:safe] option is set, so only existing (and loaded) atoms will be deserialized.

Callback implementation for Ecto.Type.type/0.