Exddb
Simple lightweight object mapper for DynamoDB and Elixir.
This is a work in progress, interfaces can and probably will change. That is why its verison 0.x.x.
Opinionated Assumptions
The library assumes that you want to define a schema for some of the things you keep in your awesome schema-free database.
It also argues that you want to always write the full items to DynamoDB and not take advantage of
UpdateItem API.
Defining your data model
defmodule MyShopApp.ReceiptModel do
use Exddb.Model
@table_name "receipts"
@key :receipt_id
# define our schema
model do
field :receipt_id, :string
field :client_id, :string, null: false
field :total, :float
field :items, :integer
field :processed, :boolean
field :raw, :binary
end
endSetup a repository
All database operations are done through a repository module.
defmodule MyShopApp.Repo do
use Exddb.Repo, table_name_prefix: "shopdb_"
endUsing the repository:
record = ReceiptModel.new receipt_id: "123-456", raw: "something important", processed: true
{:ok, _record} = Repo.insert(record)Running tests with local DynamoDB
Amazon provides java service that mimics DynamoDB for local development.
I run it inside a Docker container
$ docker run -d -p 8000:8000 --name dynamodb deangiberson/aws-dynamodb-localThen run tests with the local DynamoDB
$ mix test --only localRunning tests using AWS
To run tests using DynamoDB on your AWS account:
$ mix test --only require_aws