Skip to content

Commit bbfc392

Browse files
authored
Empty string support (#23)
* Allow empty string attributes to be written to the DB. * Add credo, address credo suggestions, add additional documentation. * Add additional configuration documentation to README.
1 parent e16f2f1 commit bbfc392

File tree

14 files changed

+68
-21
lines changed

14 files changed

+68
-21
lines changed

CONTRIBUTING.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
Contributing
22
============
33

4-
Contributions to ExAws are always welcome! For contributions to this particular service, feel free to just open a PR or an issue. For larger scale contributions see: https://github.com/ex-aws/ex_aws/blob/master/CONTRIBUTING.md
4+
Contributions to ExAws.Dynamo are always welcome! For contributions to this particular service, feel free to just open a PR or an issue. For larger scale contributions see: https://github.com/ex-aws/ex_aws/blob/master/CONTRIBUTING.md
5+
6+
Before submitting any PR, please make sure that the code is adequately tested, formatted, and checked for other issues... in other words, please run
7+
8+
```bash
9+
mix format
10+
mix credo
11+
mix test
12+
```
13+
14+
and respond to any issues that are raised accordingly.

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,33 @@ Documentation for **ExAwsDynamo** can be found at [https://hexdocs.pm/ex_aws_dyn
2727

2828
### DynamoDB Local
2929

30-
If you are running this module against a local development instance of DynamoDB, you'll want to make sure that you have installed the latest version, `1.11.478` (released 2020-01-16). You can find links to download the latest version [here](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.DownloadingAndRunning.html).
30+
If you are running this module against a local development instance of DynamoDB, you'll want to make sure that you have installed the latest version, `1.13.1` (released 2020-05-29). You can find links to download the latest version [here](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.DownloadingAndRunning.html).
31+
32+
## Configuration
33+
34+
### **ExAws**
35+
36+
In order to use **ExAws.Dynamo** against a production instance of DynamoDB, your app will need to provide the following configuration for `:ex_aws`:
37+
38+
Example configuration:
39+
40+
```elixir
41+
config :ex_aws,
42+
access_key_id: [{:system, "AWS_ACCESS_KEY_ID"}, :instance_role],
43+
secret_access_key: [{:system, "AWS_SECRET_ACCESS_KEY"}, :instance_role]
44+
```
45+
46+
**:access_key_id** :: string
47+
48+
The ID portion of a set of AWS credentials.
49+
50+
**:secret_access_key** :: string
51+
52+
The secret portion of a set of AWS credentials.
53+
54+
Please see the [ExAws README](https://github.com/ex-aws/ex_aws) for additional reference.
55+
56+
## Testing
3157

3258
### Integration tests (optional)
3359

config/prod.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

lib/ex_aws/dynamo.ex

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ defmodule ExAws.Dynamo do
33
Operations on the AWS Dynamo service.
44
55
NOTE: When Mix.env in [:test, :dev] dynamo clients will run by default against
6-
Dynamodb local.
6+
DynamoDB local.
77
88
## Basic usage
99
```elixir
@@ -769,22 +769,19 @@ defmodule ExAws.Dynamo do
769769
{:condition_expression, binary}
770770
| {:expression_attribute_names, expression_attribute_names_vals}
771771
| {:expression_attribute_values, expression_attribute_values_vals}
772-
| {:return_values_on_condition_check_failure,
773-
return_values_on_condition_check_failure_vals}
772+
| {:return_values_on_condition_check_failure, return_values_on_condition_check_failure_vals}
774773
]
775774

776775
@type transact_update_item_opts :: [
777776
{:condition_expression, binary}
778777
| {:expression_attribute_names, expression_attribute_names_vals}
779778
| {:expression_attribute_values, expression_attribute_values_vals}
780-
| {:return_values_on_condition_check_failure,
781-
return_values_on_condition_check_failure_vals}
779+
| {:return_values_on_condition_check_failure, return_values_on_condition_check_failure_vals}
782780
| {:update_expression, binary}
783781
]
784782

785783
@type transact_write_item ::
786-
{:condition_check,
787-
{table_name :: binary, key :: primary_key, transact_standard_item_opts}}
784+
{:condition_check, {table_name :: binary, key :: primary_key, transact_standard_item_opts}}
788785
| {:delete, {table_name :: binary, key :: primary_key, transact_standard_item_opts}}
789786
| {:put, {table_name :: binary, item :: map(), transact_standard_item_opts}}
790787
| {:update, {table_name :: binary, key :: primary_key, transact_update_item_opts}}

lib/ex_aws/dynamo/decoder.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
defmodule ExAws.Dynamo.Decoder do
2-
@doc """
2+
@moduledoc """
33
Decodes a dynamo response into a struct.
44
55
If Dynamo.Decodable is implemented for the struct it will be called
@@ -48,7 +48,7 @@ defmodule ExAws.Dynamo.Decoder do
4848
def decode(%{"N" => value}) when is_binary(value), do: binary_to_number(value)
4949
def decode(%{"N" => value}) when value |> is_integer or value |> is_float, do: value
5050

51-
def decode(item = %{}) do
51+
def decode(%{} = item) do
5252
item
5353
|> Enum.reduce(%{}, fn {k, v}, map ->
5454
Map.put(map, k, decode(v))

lib/ex_aws/dynamo/encodable.ex

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,6 @@ defimpl ExAws.Dynamo.Encodable, for: Map do
7979

8080
def do_encode(map) do
8181
Enum.reduce(map, %{}, fn
82-
{_, ""}, map ->
83-
map
84-
8582
{k, v}, map when is_binary(k) ->
8683
Map.put(map, k, ExAws.Dynamo.Encodable.encode(v, []))
8784

lib/ex_aws/dynamo/lazy.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
defmodule ExAws.Dynamo.Lazy do
22
@moduledoc false
3+
34
## Implimentation of the lazy functions surfaced by ExAws.Dynamo.Client
45

56
@doc "Generates a scan stream"

mix.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ defmodule ExAws.Dynamo.Mixfile do
4343
# Run "mix help deps" to learn about dependencies.
4444
defp deps do
4545
[
46+
{:credo, "~> 1.4", only: [:dev, :test], runtime: false},
4647
{:ex_doc, ">= 0.0.0", only: :dev},
4748
{:hackney, ">= 0.0.0", only: [:dev, :test]},
48-
{:sweet_xml, ">= 0.0.0", only: [:dev, :test]},
4949
{:jason, ">= 0.0.0", only: [:dev, :test]},
50+
{:sweet_xml, ">= 0.0.0", only: [:dev, :test]},
5051
ex_aws()
5152
]
5253
end

mix.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
%{
2+
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"},
23
"certifi": {:hex, :certifi, "2.5.2", "b7cfeae9d2ed395695dd8201c57a2d019c0c43ecaf8b8bcb9320b40d6662f340", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm", "3b3b5f36493004ac3455966991eaf6e768ce9884693d9968055aeeeb1e575040"},
4+
"credo": {:hex, :credo, "1.4.0", "92339d4cbadd1e88b5ee43d427b639b68a11071b6f73854e33638e30a0ea11f5", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "1fd3b70dce216574ce3c18bdf510b57e7c4c85c2ec9cad4bff854abaf7e58658"},
35
"earmark": {:hex, :earmark, "1.3.2", "b840562ea3d67795ffbb5bd88940b1bed0ed9fa32834915125ea7d02e35888a5", [:mix], [], "hexpm", "e3be2bc3ae67781db529b80aa7e7c49904a988596e2dbff897425b48b3581161"},
46
"ex_aws": {:hex, :ex_aws, "2.1.3", "26b6f036f0127548706aade4a509978fc7c26bd5334b004fba9bfe2687a525df", [:mix], [{:configparser_ex, "~> 4.0", [hex: :configparser_ex, repo: "hexpm", optional: true]}, {:hackney, "~> 1.9", [hex: :hackney, repo: "hexpm", optional: true]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: true]}, {:jsx, "~> 2.8", [hex: :jsx, repo: "hexpm", optional: true]}, {:sweet_xml, "~> 0.6", [hex: :sweet_xml, repo: "hexpm", optional: true]}], "hexpm", "0bdbe2aed9f326922fc5a6a80417e32f0c895f4b3b2b0b9676ebf23dd16c5da4"},
57
"ex_doc": {:hex, :ex_doc, "0.20.2", "1bd0dfb0304bade58beb77f20f21ee3558cc3c753743ae0ddbb0fd7ba2912331", [:mix], [{:earmark, "~> 1.3", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "8e24fc8ff9a50b9f557ff020d6c91a03cded7e59ac3e0eec8a27e771430c7d27"},

test/lib/dynamo/encoder_test.exs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ defmodule ExAws.Dynamo.EncoderTest do
2121
assert Encoder.encode(0.4) == %{"N" => "0.4"}
2222
end
2323

24-
test "Encoder removes empty strings from a map" do
24+
test "Encoder allows empty strings in a map" do
2525
assert Encoder.encode(%{"data" => "value", "nodata" => ""}) == %{
26-
"M" => %{"data" => %{"S" => "value"}}
26+
"M" => %{
27+
"data" => %{"S" => "value"},
28+
"nodata" => %{"S" => ""}
29+
}
2730
}
2831
end
2932

0 commit comments

Comments
 (0)