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

Mark Fine mark.fine@REDACTED
Mon Mar 26 23:50:20 CEST 2012


Ask AWS to ship the models they generate their SDKs from.

Mark

On Mon, Mar 26, 2012 at 5:42 AM, Joel Reymont <joelr1@REDACTED> wrote:
> 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)
> end
>
> record Stack
>  id            string (auto primary key)
>  publisher     Publisher.id
>  subscriptions [Subscription.id]
> end
>
> #enum Frequency
> #  disabled
> #  immediate
> #  daily
> #  weekly
> #  monthly
> #end
>
> record Subscription
>  id            string (auto primary key)
>  user          User.id
>  stack         Stack.id
> # notify-freq   Frequency
>  notify-freq   string
>  language      string
>  last-notified date
> end
>
> record NewDocs
>  stack     Stack.id (primary key)
>  add-date  date (secondary key)
>  doc-id    string
> end
>
> record User
>  id            string (primary key) # Issuu id?
>  subscriptions [Subscription.id]
> end
>
> record UnconfirmedEmails
>  id    string (auto primary key)
>  email string
> end
> ---
>
> This generates Erlang code using http://github.com/wagerlabs/ddb that
> looks like this
>
> ---
> -module(publisher).
>
> -export([setup/0, teardown/0,
>        put/1, get/1, delete/1]).
>
> setup() ->
>   ddb:create_table(<<"Publisher">>,
>                   ddb:key_type(<<"id">>, 'string'),
>                   10, 10).
>
> teardown() ->
>   ddb:remove_table(<<"Publisher">>).
> ---
>
> and this
>
> ---
> -module(newdocs).
>
> -export([setup/0, teardown/0,
>        put/3, get/3, delete/3]).
>
> setup() ->
>   ddb:create_table(<<"NewDocs">>,
>                   ddb:key_type(<<"stack">>, 'string',
>                                <<"add_date">>, 'string'),
>                   10, 10).
>
> teardown() ->
>   ddb:remove_table(<<"NewDocs">>).
> ---
>
> 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
> User.subscriptions.
>
> 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
> ---------------------+------------+---------------------------------------
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list