View Source Dynamo.Encodable protocol (Dynamo v0.2.0)

Protocol used by the :any type (and nested :map/:list values) to encode structs and custom values that have no explicit field type.

Prefer an explicit Dynamo.Type on the schema field. Implement this protocol for values you want to embed inside :map/:list/:any fields:

defimpl Dynamo.Encodable, for: Money do
  def dump(m), do: {:ok, %{"N" => Money.to_string(m)}}
end

Schemas defined with Dynamo.Schema get an implementation automatically that dumps them as a nested M.

Decoding is one-directional: nested structs are loaded as plain string-keyed maps. Use a Dynamo.Type if you need typed nested structs.

Summary

Types

t()

All the types that implement this protocol.

Functions

Returns {:ok, attribute_value} or :error.

Types

t()

@type t() :: term()

All the types that implement this protocol.

Functions

dump(value)

@spec dump(t()) :: {:ok, map()} | :error

Returns {:ok, attribute_value} or :error.