Git Product home page Git Product logo

ddb's Introduction

Accessing Amazon DynamoDB

Authenticating

inets:start().
ssl:start().
lager:start().
application:start(ibrowse).
ddb_iam:credentials("access key", "secret").
{'ok', Key, Secret, Token} = ddb_iam:token(129600).
ddb:credentials(Key, Secret, Token).

Creating a table with a hash key

ddb:create_table(<<"foo">>, ddb:key_type(<<"hashkey">>, 'string'), 10, 10).

Creating a table with hash and range keys

ddb:create_table(<<"bar">>, ddb:key_type(<<"hashkey">>, 'string', <<"rangekey">>, 'number'), 10, 10).

Adding a record to a table with a hash key

ddb:put(<<"foo">>, [{<<"hashkey">>, <<"hash key value">>, 'string'},
                    {<<"field1">>, <<"string value">>, 'string'}, 
                    {<<"field2">>, <<"100">>, 'number'}]).

Adding a record to a table with hash and range keys

ddb:put(<<"bar">>, [{<<"hashkey">>, <<"hash key value">>, 'string'},
                    {<<"rangekey">>, <<"1000">>, 'number'},
                    {<<"field1">>, <<"string value">>, 'string'}, 
                    {<<"field2">>, <<"100">>, 'number'}]).

ddb:put(<<"bar">>, [{<<"hashkey">>, <<"hash key value">>, 'string'},
                    {<<"rangekey">>, <<"2000">>, 'number'},
                    {<<"field3">>, <<"string value">>, 'string'}]).

Fetching a record from a table using a hash key

ddb:get(<<"foo">>, ddb:key_value(<<"hash key value">>, 'string')).

Fetching a record from a table using hash and range keys

ddb:get(<<"bar">>, ddb:key_value(<<"hash key value">>, 'string', <<"1000">>, 'number')).

Querying a table

ddb:find(<<"bar">>, {<<"hash key value">>, 'string'}, {'between', 'number', [<<"1000">>, <<"2000">>]}).

Changing value (and type) of one field while deleting another

ddb:update(<<"foo">>, ddb:key_value(<<"hash key value">>, 'string'), 
                      [{<<"field1">>, <<"1">>, 'number', 'put'},
                       {<<"field2">>, 'delete'}]).

Adding to a string set field and returning pre-update values of updated fields

ddb:update(<<"foo">>, ddb:key_value(<<"hash key value">>, 'string'), 
                      [{<<"field2">>, [<<"1">>, <<"2">>], ['string'], 'add'}],
                      'updated_old').

Deleting an item from a string set field and returning the values of all fields before the update

ddb:update(<<"foo">>, ddb:key_value(<<"hash key value">>, 'string'), 
                      [{<<"field2">>, [<<"1">>], ['string'], 'delete'}],
                      'all_old').

Update field1 only when field2 does not exist

ddb:cond_update(<<"foo">>, ddb:key_value(<<"hash key value">>, 'string'), 
                           [{<<"field1">>, <<"1">>, 'number', 'put'}],
                           {'does_not_exist', <<"field2">>}).

Update field1 only when field2 exists and has a numerical value of 1

ddb:cond_update(<<"foo">>, ddb:key_value(<<"hash key value">>, 'string'), 
                           [{<<"field1">>, <<"2">>, 'number', 'put'}],
                           {'exists', <<"field2">>, [<<"2">>], ['string']}).

See src/ddb.erl for the rest of the API.

Note that dates in Dynamo are represented as seconds since Unix epoch!

All data is stored as strings but you have to specify whether each field is a string or a number.

ddb's People

Contributors

deadzen avatar joelreymont avatar tsloughter avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.