[erlang-questions] say no to aws dynamodb boilerplate and welcome dsl!

Joel Reymont joelr1@REDACTED
Mon Mar 26 14:42:23 CEST 2012

Here's a DSL I whipped up to simplify working with Amazon DynamoDB by
automatically generating Erlang code. With a bit of thinking it could
be extended to SimpleDB, Python, etc.

I don't have a name for this language so I'm calling it DSL for
"Declarative Schema Language" or maybe "Dynamo Schema Language". Feel
free to propose a better name.

Here's an example schema. More comments further down.

record Publisher
 id        string (auto primary key) # auto-generated hash key
 stacks    [Stack.id] # set of stack ids, starts empty
 sub-count count (Subscription.stack.publisher.id)

record Stack
 id            string (auto primary key)
 publisher     Publisher.id
 subscriptions [Subscription.id]

#enum Frequency
#  disabled
#  immediate
#  daily
#  weekly
#  monthly

record Subscription
 id            string (auto primary key)
 user          User.id
 stack         Stack.id
# notify-freq   Frequency
 notify-freq   string
 language      string
 last-notified date

record NewDocs
 stack     Stack.id (primary key)
 add-date  date (secondary key)
 doc-id    string

record User
 id            string (primary key) # Issuu id?
 subscriptions [Subscription.id]

record UnconfirmedEmails
 id    string (auto primary key)
 email string

This generates Erlang code using http://github.com/wagerlabs/ddb that
looks like this


-export([setup/0, teardown/0,
        put/1, get/1, delete/1]).

setup() ->
                   ddb:key_type(<<"id">>, 'string'),
                   10, 10).

teardown() ->

and this


-export([setup/0, teardown/0,
        put/3, get/3, delete/3]).

setup() ->
                   ddb:key_type(<<"stack">>, 'string',
                                <<"add_date">>, 'string'),
                   10, 10).

teardown() ->

A bunch of code is missing but you should be able to auto-magically
update Publisher.stacks with Stack.id when a new stack is created
where Stack.publisher matches Publisher.id.

It's gets even better and you should be able to bump
Publisher.sub-count (subscription count) when a new subscription is
added to a publisher's stack!

Of course you should also be able to have put and get functions to
create, read and update the items, as well as functions to manipulate
the sets, e.g. Publisher.stacks, Stack.subscriptions and

What do you think?

Do you think this can be accomplished using the SQL syntax? How would
you update the Publisher.sub-count counter then?

   Thanks, Joel

P.S. I wrote the compiler in OCaml and it has a proper lexer, parser,
AST and code generator for Erlang.

- for hire: mac osx device driver ninja, kernel extensions and usb drivers
http://wagerlabs.com | @wagerlabs | http://www.linkedin.com/in/joelreymont

More information about the erlang-questions mailing list