Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update API for CreateTable to version 20120810

  • Loading branch information...
commit d221c77d0f886ba2ba13d3eff2adcfd976ddce50 1 parent a303dfa
@chrisavl chrisavl authored
Showing with 32 additions and 21 deletions.
  1. +9 −8 src/dinerl.erl
  2. +1 −1  src/dinerl_client.erl
  3. +22 −12 test/dinerl_test.erl
View
17 src/dinerl.erl
@@ -7,7 +7,7 @@
-export([setup/3, setup/4, api/1, api/2, api/3]).
--export([create_table/4, create_table/5, delete_table/1, delete_table/2]).
+-export([create_table/5, create_table/6, delete_table/1, delete_table/2]).
-export([describe_table/1, describe_table/2, update_table/3, update_table/4]).
-export([list_tables/0, list_tables/1, list_tables/2]).
-export([put_item/2, put_item/3, put_item/4]).
@@ -58,18 +58,19 @@ api(Name, Body, Timeout) ->
end.
--spec create_table(string()|binary(), keyschema(), integer(), integer()) -> jsonf().
-create_table(Name, Key, ReadsPerSecond, WritesPerSecond) ->
- create_table(Name, Key, ReadsPerSecond, WritesPerSecond, undefined).
+-spec create_table(string()|binary(), keyschema(), term(), integer(), integer()) -> jsonf().
+create_table(Name, KeySchema, AttrDefs, ReadsPerSecond, WritesPerSecond) ->
+ create_table(Name, KeySchema, AttrDefs, ReadsPerSecond, WritesPerSecond, undefined).
--spec create_table(string()|binary(), keyschema(), integer(), integer(), integer()) -> jsonf().
-create_table(Name, Key, ReadsPerSecond, WritesPerSecond, Timeout) ->
+-spec create_table(string()|binary(), keyschema(), term(), integer(), integer(), integer()) -> jsonf().
+create_table(Name, Key, AttrDefs, ReadsPerSecond, WritesPerSecond, Timeout) ->
api(create_table,
{[{<<"TableName">>, Name},
+ {<<"AttributeDefinitions">>, AttrDefs},
{<<"KeySchema">>, Key},
{<<"ProvisionedThroughput">>,
- {[{<<"ReadsPerSecond">>, ReadsPerSecond},
- {<<"WritesPerSecond">>, WritesPerSecond}]}}]}, Timeout).
+ {[{<<"ReadCapacityUnits">>, ReadsPerSecond},
+ {<<"WriteCapacityUnits">>, WritesPerSecond}]}}]}, Timeout).
delete_table(Name) ->
delete_table(Name, undefined).
View
2  src/dinerl_client.erl
@@ -26,7 +26,7 @@ method_name(update_item) ->
%% Table related operations
%%
method_name(create_table) ->
- "DynamoDBv20110924.CreateTable";
+ "DynamoDB_20120810.CreateTable";
method_name(list_tables) ->
"DynamoDBv20110924.ListTables";
method_name(describe_table) ->
View
34 test/dinerl_test.erl
@@ -4,6 +4,13 @@
-define(HASH_TABLE, <<"dinerl-unit-test-table-hash">>).
-define(RANGE_TABLE, <<"dinerl-unit-test-table-range">>).
+start_app(App) ->
+ case application:start(App) of
+ ok -> ok;
+ {error, {already_started, App}} -> ok;
+ Other -> throw(Other)
+ end.
+
dinerl_test_() ->
case file:consult(filename:join([code:priv_dir(dinerl), "aws_credentials.term"])) of
{ok, Config} ->
@@ -14,10 +21,11 @@ dinerl_test_() ->
Config),
inets:start(),
- application:start(crypto),
- application:start(public_key),
- application:start(ssl),
- application:start(lhttpc),
+ start_app(crypto),
+ start_app(asn1),
+ start_app(public_key),
+ start_app(ssl),
+ start_app(lhttpc),
dinerl:setup(AccessKey, SecretAccessKey, "us-east-1a"),
%% Create tables if necessary
@@ -42,23 +50,25 @@ create_tables() ->
{ok, {[{<<"TableNames">>, Tables}]}} = dinerl:list_tables(),
Config = [{?HASH_TABLE,
- {[{<<"HashKeyElement">>, {[{<<"AttributeName">>, <<"key">>},
- {<<"AttributeType">>, <<"S">>}]}}]}},
+ [{[{<<"AttributeName">>, <<"key">>}, {<<"KeyType">>, <<"HASH">>}]}],
+ [{[{<<"AttributeName">>, <<"key">>}, {<<"AttributeType">>, <<"S">>}]}]
+ },
{?RANGE_TABLE,
- {[{<<"HashKeyElement">>, {[{<<"AttributeName">>, <<"hash">>},
- {<<"AttributeType">>, <<"S">>}]}},
- {<<"RangeKeyElement">>, {[{<<"AttributeName">>, <<"range">>},
- {<<"AttributeType">>, <<"N">>}]}}]}}
+ [{[{<<"AttributeName">>, <<"key">>}, {<<"KeyType">>, <<"HASH">>}]},
+ {[{<<"AttributeName">>, <<"range">>}, {<<"KeyType">>, <<"RANGE">>}]}],
+ [{[{<<"AttributeName">>, <<"key">>}, {<<"AttributeType">>, <<"S">>}]},
+ {[{<<"AttributeName">>, <<"range">>}, {<<"AttributeType">>, <<"N">>}]}]
+ }
],
lists:foreach(
- fun ({Name, Key}) ->
+ fun ({Name, KeySchema, AttrDefs}) ->
case lists:member(Name, Tables) of
true ->
wait_for_active(Name),
ok;
false ->
- case dinerl:create_table(Name, Key, 10, 5) of
+ case dinerl:create_table(Name, KeySchema, AttrDefs, 10, 5) of
{ok, _} ->
wait_for_active(Name),
ok;
Please sign in to comment.
Something went wrong with that request. Please try again.