Packages
ecto_adapters_dynamodb
3.3.3
3.6.1
3.6.0
3.5.0
3.4.1
3.4.0
3.3.7
3.3.6
3.3.5
3.3.4
3.3.3
3.3.2
3.3.1
3.3.0
3.2.0
3.1.3
3.1.2
3.1.1
3.1.0
3.0.3
3.0.2
3.0.1
3.0.0
2.0.4
2.0.3
2.0.2
2.0.1
2.0.0
2.0.0-beta.1
2.0.0-beta.0
2.0.0-alpha.4
2.0.0-alpha.3
2.0.0-alpha.2
2.0.0-alpha.1
2.0.0-alpha.0
1.3.0
1.2.1
1.2.0
1.1.3
0.5.1
0.5.0
0.4.6
0.4.5
0.4.4
0.4.3
0.4.2
0.4.1
0.4.0
0.3.0
0.2.3
0.2.2
0.2.1
0.1.2
0.1.1
A DynamoDB adapter for Ecto supporting basic queries. See https://github.com/circles-learning-labs/ecto_adapters_dynamodb for detailed instructions.
Current section
Files
Jump to
Current section
Files
lib/ecto_adapters_dynamodb/dynamodbset.ex
defmodule Ecto.Adapters.DynamoDB.DynamoDBSet do
@moduledoc """
An Ecto type for handling MapSet, corresponding with DynamoDB's **set** types. Since ExAws
already encodes and decodes MapSet, we only handle casting and validation here.
"""
@behaviour Ecto.Type
@doc """
This type is actually a MapSet
"""
@impl Ecto.Type
def type, do: MapSet
@doc """
Confirm the type is a MapSet and its elements are of one type, number or binary
"""
@impl Ecto.Type
def cast(mapset) do
case mapset do
%MapSet{} -> if valid?(mapset), do: {:ok, mapset}, else: :error
_ -> :error
end
end
@doc """
Load as is
"""
@impl Ecto.Type
def load(mapset), do: {:ok, mapset}
@doc """
Dump as is
"""
@impl Ecto.Type
def dump(mapset), do: {:ok, mapset}
@doc """
Check if two terms are semantically equal
"""
@impl Ecto.Type
def equal?(%MapSet{} = term_a, %MapSet{} = term_b), do: MapSet.equal?(term_a, term_b)
def equal?(nil, %MapSet{}), do: false
def equal?(%MapSet{}, nil), do: false
def equal?(nil, nil), do: true
@doc """
Dictates how the type should be treated inside embeds
"""
@impl Ecto.Type
def embed_as(_), do: :self
defp valid?(mapset) do
Enum.all?(mapset, fn x -> is_number(x) end) or
Enum.all?(mapset, fn x -> is_binary(x) end)
end
end