-
Notifications
You must be signed in to change notification settings - Fork 533
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5f52d75
commit a9265ad
Showing
6 changed files
with
52 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
defmodule ExAws.Dynamo do | ||
@moduledoc """ | ||
Defines a Dynamo Client | ||
By default you can use ExAws.Dynamo | ||
Operations on the AWS Dynamo service. | ||
NOTE: When Mix.env in [:test, :dev] dynamo clients will run by default against | ||
Dynamodb local. | ||
|
@@ -19,59 +17,20 @@ defmodule ExAws.Dynamo do | |
# Create a users table with a primary key of email [String] | ||
# and 1 unit of read and write capacity | ||
Dynamo.create_table("Users", "email", %{email: :string}, 1, 1) | ||
|> ExAws.request! | ||
user = %User{email: "[email protected]", name: "Bubba", age: 23, admin: false} | ||
# Save the user | ||
Dynamo.put_item("Users", user) | ||
Dynamo.put_item("Users", user) |> ExAws.request! | ||
# Retrieve the user by email and decode it as a User struct. | ||
result = Dynamo.get_item!("Users", %{email: user.email}) | ||
|> ExAws.request! | ||
|> Dynamo.Decoder.decode(as: User) | ||
assert user == result | ||
``` | ||
## Customization | ||
If you want more than one client you can define your own as follows. If you don't need more | ||
than one or plan on customizing the request process it's generally easier to just use | ||
and configure the ExAws.Dynamo client. | ||
``` | ||
defmodule MyApp.Dynamo do | ||
use ExAws.Dynamo.Client, otp_app: :my_otp_app | ||
end | ||
``` | ||
In your config | ||
``` | ||
config :my_otp_app, :ex_aws, | ||
dynamodb: [], # Dynamo config goes here | ||
``` | ||
You can now use MyApp.Dynamo as the root module for the Dynamo api without needing | ||
to pass in a particular configuration. | ||
This enables different otp apps to configure their AWS configuration separately. | ||
The alignment with a particular OTP app while convenient is however entirely optional. | ||
The following also works: | ||
``` | ||
defmodule MyApp.Dynamo do | ||
use ExAws.Dynamo.Client | ||
def config_root do | ||
Application.get_all_env(:my_aws_config_root) | ||
end | ||
end | ||
``` | ||
ExAws now expects the config for that dynamo client to live under | ||
```elixir | ||
config :my_aws_config_root | ||
dynamodb: [] # Dynamo config goes here | ||
``` | ||
Default config values can be found in ExAws.Config. | ||
## General notes | ||
All options are handled as underscored atoms instead of camelcased binaries as specified | ||
in the Dynamo API. IE `IndexName` would be `:index_name`. Anywhere in the API that requires | ||
|
@@ -98,31 +57,6 @@ defmodule ExAws.Dynamo do | |
``` | ||
Alternatively, if what's being encoded is a struct, you're always free to implement ExAws.Dynamo.Encodable for that struct. | ||
## Examples | ||
```elixir | ||
defmodule User do | ||
@derive [ExAws.Dynamo.Encodable] | ||
defstruct [:email, :name, :age, :admin] | ||
end | ||
alias ExAws.Dynamo | ||
# Create a users table with a primary key of email [String] | ||
# and 1 unit of read and write capacity | ||
Dynamo.create_table("Users", "email", %{email: :string}, 1, 1) | ||
user = %User{email: "[email protected]", name: "Bubba", age: 23, admin: false} | ||
# Save the user | ||
Dynamo.put_item("Users", user) | ||
# Retrieve the user by email and decode it as a User struct. | ||
result = Dynamo.get_item!("Users", %{email: user.email}) | ||
|> Dynamo.Decoder.decode(as: User) | ||
assert user == result | ||
``` | ||
http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Operations.html | ||
""" | ||
|
||
|
@@ -415,8 +349,7 @@ defmodule ExAws.Dynamo do | |
def batch_get_item(data, opts \\ []) do | ||
request_items = data | ||
|> Enum.reduce(%{}, fn {table_name, table_query}, query -> | ||
keys = table_query | ||
|> Dict.get(:keys) | ||
keys = table_query[:keys] | ||
|> Enum.map(&encode_values/1) | ||
|
||
dynamized_table_query = table_query | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters