Module erlcloud_ddb_util

Helpers for using DynamoDB from Erlang.

Authors: Ransom Richardson (ransom@ransomr.net).

Description

Helpers for using DynamoDB from Erlang.

This is a higher layer API that augments the operations supported by erlcloud_ddb2. The functions in this file do not map directly to DynamoDB operations. Instead they will perform multiple operations in order to implement functionality that isn't available directly using the DynamoDB API.

Data Types

batch_read_ddb_opt()

batch_read_ddb_opt() = typed_out() | erlcloud_ddb2:out_opt()

batch_read_ddb_opts()

batch_read_ddb_opts() = [batch_read_ddb_opt()]

conditions()

conditions() = erlcloud_ddb2:conditions()

ddb_opts()

ddb_opts() = erlcloud_ddb2:ddb_opts()

expression()

expression() = erlcloud_ddb2:expression()

get_all_opts()

get_all_opts() = erlcloud_ddb2:batch_get_item_request_item_opts()

hash_key()

hash_key() = erlcloud_ddb2:in_attr()

in_item()

in_item() = erlcloud_ddb2:in_item()

items_return()

items_return() = {ok, [out_item()]} | {ok, non_neg_integer()} | {error, term()}

key()

key() = erlcloud_ddb2:key()

out_item()

out_item() = erlcloud_ddb2:out_item()

q_all_opts()

q_all_opts() = [erlcloud_ddb2:q_opt() | batch_read_ddb_opt()]

range_key_name()

range_key_name() = erlcloud_ddb2:range_key_name()

scan_all_opts()

scan_all_opts() = [erlcloud_ddb2:scan_opt() | batch_read_ddb_opt()]

table_name()

table_name() = erlcloud_ddb2:table_name()

typed_out()

typed_out() = {typed_out, boolean()}

write_all_item()

write_all_item() = erlcloud_ddb2:batch_write_item_request()

Function Index

delete_all/2
delete_all/3
delete_all/4.
delete_hash_key/3
delete_hash_key/4
delete_hash_key/5.
get_all/2
get_all/3
get_all/4
list_tables_all/0
list_tables_all/1
put_all/2
put_all/3
put_all/4.
q_all/2
q_all/3
q_all/4.
scan_all/1
scan_all/2
scan_all/3.
set_out_opt/1
wait_for_table_active/1
wait_for_table_active/2
wait_for_table_active/3
wait_for_table_active/4 wait until table_status==active.
write_all/2
write_all/3
write_all/4.

Function Details

delete_all/2

delete_all(Table::table_name(), Keys::[key()]) -> ok | {error, term()}

delete_all/3

delete_all(Table::table_name(), Keys::[key()], Opts::ddb_opts()) -> ok | {error, term()}

delete_all/4

delete_all(Table::table_name(), Keys::[key()], Opts::ddb_opts(), Config::aws_config()) -> ok | {error, term()}

Perform one or more BatchWriteItem operations to delete all items. Operations are performed in parallel. Writing to only one table is supported.

Example

ok = erlcloud_ddb_util:delete_all( [{<<"Forum">>, [{<<"Name">>, {s, <<"Amazon DynamoDB">>}}, {<<"Name">>, {s, <<"Amazon RDS">>}}, {<<"Name">>, {s, <<"Amazon Redshift">>}}, {<<"Name">>, {s, <<"Amazon ElastiCache">>}} ]}]),

delete_hash_key/3

delete_hash_key(Table::table_name(), HashKey::hash_key(), RangeKeyName::range_key_name()) -> ok | {error, term()}

delete_hash_key/4

delete_hash_key(Table::table_name(), HashKey::hash_key(), RangeKeyName::range_key_name(), Opts::ddb_opts()) -> ok | {error, term()}

delete_hash_key/5

delete_hash_key(Table::table_name(), HashKey::hash_key(), RangeKeyName::range_key_name(), Opts::ddb_opts(), Config::aws_config()) -> ok | {error, term()}

Delete all items with the specified table. Table must be a hash-and-range primary key table. Opts is currently ignored and is provided for future enhancements. This method is not transacted.

Example

ok = erlcloud_ddb_util:delete_hash_key(<<"tn">>, {<<"hash-key-name">>, <<"hash-key-value">>}, <<"range-key-name">>, [])),

get_all/2

get_all(Table::table_name(), Keys::[key()]) -> items_return()

get_all/3

get_all(Table::table_name(), Keys::[key()], Opts::get_all_opts()) -> items_return()

get_all/4

get_all(Table::table_name(), Keys::[key()], Opts::get_all_opts(), Config::aws_config() | batch_read_ddb_opts()) -> items_return()

list_tables_all/0

list_tables_all() -> any()

list_tables_all/1

list_tables_all(Config::aws_config()) -> {ok, [table_name()]} | {error, any()}

put_all/2

put_all(Table::table_name(), Items::[in_item()]) -> ok | {error, term()}

put_all/3

put_all(Table::table_name(), Items::[in_item()], Opts::ddb_opts()) -> ok | {error, term()}

put_all/4

put_all(Table::table_name(), Items::[in_item()], Opts::ddb_opts(), Config::aws_config()) -> ok | {error, term()}

Perform one or more BatchWriteItem operations to put all items. Operations are performed in parallel. Writing to only one table is supported.

Example

ok = erlcloud_ddb_util:put_all( [{<<"Forum">>, [[{<<"Name">>, {s, <<"Amazon DynamoDB">>}}, {<<"Category">>, {s, <<"Amazon Web Services">>}}], [{<<"Name">>, {s, <<"Amazon RDS">>}}, {<<"Category">>, {s, <<"Amazon Web Services">>}}], [{<<"Name">>, {s, <<"Amazon Redshift">>}}, {<<"Category">>, {s, <<"Amazon Web Services">>}}], [{<<"Name">>, {s, <<"Amazon ElastiCache">>}}, {<<"Category">>, {s, <<"Amazon Web Services">>}}] ]}]),

q_all/2

q_all(Table::table_name(), KeyConditionsOrExpression::conditions() | expression()) -> items_return()

q_all/3

q_all(Table::table_name(), KeyConditionsOrExpression::conditions() | expression(), Opts::q_all_opts()) -> items_return()

q_all/4

q_all(Table::table_name(), KeyConditionsOrExpression::conditions() | expression(), Opts::q_all_opts(), Config::aws_config()) -> items_return()

Perform one or more Query operations to get all matching items.

Example

{ok, Items} = erlcloud_ddb_util:q_all( <<"Thread">>, <<"ForumName = :n AND LastPostDateTime BETWEEN :t1 AND :t2">>, [{expression_attribute_values, [{<<":n">>, <<"Amazon DynamoDB">>}, {<<":t1">>, <<"20130101">>}, {<<":t2">>, <<"20130115">>}]}, {index_name, <<"LastPostIndex">>}, {select, all_attributes}, {consistent_read, true}, {typed_out, true}]),

scan_all/1

scan_all(Table::table_name()) -> items_return()

scan_all/2

scan_all(Table::table_name(), Opts::scan_all_opts()) -> items_return()

scan_all/3

scan_all(Table::table_name(), Opts::scan_all_opts(), Config::aws_config()) -> items_return()

Perform one or more Scan operations to get all matching items.

Example

{ok, Items} = erlcloud_ddb_util:scan_all( <<"Thread">>, [{segment, 0}, {total_segments, 4}, {typed_out, true}]),

set_out_opt/1

set_out_opt(Opts::batch_read_ddb_opts()) -> ddb_opts()

wait_for_table_active/1

wait_for_table_active(Table) -> any()

wait_for_table_active/2

wait_for_table_active(Table, AWSCfg) -> any()

wait_for_table_active/3

wait_for_table_active(Table, Interval, RetryTimes) -> any()

wait_for_table_active/4

wait_for_table_active(Table::table_name(), Interval::pos_integer() | infinity, RetryTimes::non_neg_integer() | infinity, Config::aws_config()) -> ok | {error, deleting | retry_threshold_exceeded | any()}

wait until table_status==active.

Example

erlcloud_ddb2:wait_for_table_active(<<"TableName">>, 3000, 40, Config)

write_all/2

write_all(Table::table_name(), Items::[write_all_item()]) -> ok | {error, term()}

write_all/3

write_all(Table::table_name(), Items::[write_all_item()], Opts::ddb_opts()) -> ok | {error, term()}

write_all/4

write_all(Table::table_name(), Items::[write_all_item()], Opts::ddb_opts(), Config::aws_config()) -> ok | {error, term()}

Perform one or more BatchWriteItem operations to put or delete all items. Operations are performed in parallel. Writing to only one table is supported.

Example

ok = erlcloud_ddb_util:write_all( [{<<"Forum">>, [{put, [{<<"Name">>, {s, <<"Amazon DynamoDB">>}}, {<<"Category">>, {s, <<"Amazon Web Services">>}}]}, {put, [{<<"Name">>, {s, <<"Amazon RDS">>}}, {<<"Category">>, {s, <<"Amazon Web Services">>}}]}, {put, [{<<"Name">>, {s, <<"Amazon Redshift">>}}, {<<"Category">>, {s, <<"Amazon Web Services">>}}]}, {put, [{<<"Name">>, {s, <<"Amazon ElastiCache">>}}, {<<"Category">>, {s, <<"Amazon Web Services">>}}]} ]}]),


Generated by EDoc