Packages
ex_aws
0.3.0
2.7.0
2.6.1
2.6.0
2.5.11
2.5.10
2.5.9
2.5.8
2.5.7
2.5.6
2.5.5
2.5.4
2.5.3
2.5.2
2.5.1
2.5.0
2.4.4
2.4.3
2.4.2
2.4.1
2.4.0
2.3.4
2.3.3
2.3.2
2.3.1
2.3.0
2.2.10
2.2.9
2.2.8
2.2.7
2.2.6
2.2.5
2.2.4
2.2.3
2.2.2
2.2.1
2.2.0
2.1.9
2.1.8
2.1.7
2.1.6
2.1.5
2.1.4
2.1.3
2.1.2
2.1.1
2.1.0
2.0.2
2.0.1
2.0.0
1.1.5
1.1.4
1.1.3
1.1.2
1.1.1
1.1.0
1.0.0
1.0.0-rc.4
1.0.0-rc.3
1.0.0-rc.1
1.0.0-beta3
1.0.0-beta2
1.0.0-beta1
1.0.0-beta0
0.5.0
0.4.19
0.4.18
0.4.17
0.4.15
0.4.14
0.4.13
0.4.11
0.4.10
0.4.9
0.4.8
0.4.7
0.4.6
0.4.5
0.4.4
0.4.3
0.4.2
0.4.1
0.4.0
0.3.1
0.3.0
0.2.0
0.1.2
0.1.1
0.1.0
0.0.5
0.0.4
0.0.3
AWS client for Elixir. Currently supports Dynamo, DynamoStreams, EC2, Firehose, Kinesis, KMS, Lambda, RRDS, Route53, S3, SES, SNS, SQS, STS and others.
Current section
Files
Jump to
Current section
Files
lib/ex_aws/dynamo/encoder.ex
defmodule ExAws.Dynamo.Encoder do
@moduledoc """
Takes an elixir value and converts it into a dynamo style map.
```elixir
[1,2,3] |> #{__MODULE__}.encode
#=> %{"NS" => ["1", "2", "3"]}
"bubba" |> ExAws.Dynamo.Encoder.encode
#=> %{"S" => "bubba"}
```
This is handled via the ExAws.Dynamo.Encodable protocol.
"""
# These functions exist to ensure that encoding is idempotent.
def encode(%{"B" => _} = val), do: val
def encode(%{"BOOL" => _} = val), do: val
def encode(%{"BS" => _} = val), do: val
def encode(%{"L" => _} = val), do: val
def encode(%{"M" => _} = val), do: val
def encode(%{"NS" => _} = val), do: val
def encode(%{"NULL" => _} = val), do: val
def encode(%{"N" => _} = val), do: val
def encode(%{"S" => _} = val), do: val
def encode(%{"SS" => _} = val), do: val
def encode(value) do
ExAws.Dynamo.Encodable.encode(value)
end
# Use this in case you want to encode something already in dynamo format
# For some reason I cannot fathom. If you find yourself using this, please open an issue
# so I can find out why and better support this.
def encode!(value) do
ExAws.Dynamo.Encodable.encode(value)
end
def encode_flat(value) do
case ExAws.Dynamo.Encodable.encode(value) do
%{"M" => value} -> value
%{"L" => value} -> value
end
end
def atom_to_dynamo_type(:blob), do: "B"
def atom_to_dynamo_type(:boolean), do: "BOOL"
def atom_to_dynamo_type(:blob_set), do: "BS"
def atom_to_dynamo_type(:list), do: "L"
def atom_to_dynamo_type(:map), do: "M"
def atom_to_dynamo_type(:number_set), do: "NS"
def atom_to_dynamo_type(:null), do: "NULL"
def atom_to_dynamo_type(:number), do: "N"
def atom_to_dynamo_type(:string), do: "S"
def atom_to_dynamo_type(:string_set), do: "SS"
def atom_to_dynamo_type(value) do
raise ArgumentError, "Unknown dynamo type for value: #{inspect value}"
end
end