2014-12-30 17:25:09 -05:00
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
class DynamoDB
|
|
|
|
class Real
|
|
|
|
# Query DynamoDB items
|
|
|
|
#
|
|
|
|
# ==== Parameters
|
|
|
|
# * 'table_name'<~String> - name of table to query
|
|
|
|
# * options<~Hash>:
|
|
|
|
# * 'AttributesToGet'<~Array> - Array of attributes to get for each item, defaults to all
|
|
|
|
# * 'ConsistentRead'<~Boolean> - Whether to wait for consistency, defaults to false
|
|
|
|
# * 'Count'<~Boolean> - If true, returns only a count of such items rather than items themselves, defaults to false
|
|
|
|
# * 'Limit'<~Integer> - limit of total items to return
|
2015-12-19 10:08:53 -05:00
|
|
|
# * 'KeyConditionExpression'<~String> - the condition elements need to match
|
|
|
|
# * 'ExpressionAttributeValues'<~Hash> - values to be used in the key condition expression
|
2014-12-30 17:25:09 -05:00
|
|
|
# * 'ScanIndexForward'<~Boolean>: Whether to scan from start or end of index, defaults to start
|
|
|
|
# * 'ExclusiveStartKey'<~Hash>: Key to start listing from, can be taken from LastEvaluatedKey in response
|
|
|
|
#
|
|
|
|
# ==== Returns
|
|
|
|
# * response<~Excon::Response>:
|
|
|
|
# * body<~Hash>:
|
|
|
|
# * 'ConsumedCapacityUnits'<~Integer> - number of capacity units used for query
|
|
|
|
# * 'Count'<~Integer> - number of items in response
|
|
|
|
# * 'Items'<~Array> - array of items returned
|
|
|
|
# * 'LastEvaluatedKey'<~Hash> - last key scanned, can be passed to ExclusiveStartKey for pagination
|
2015-12-19 10:08:53 -05:00
|
|
|
#
|
|
|
|
# See DynamoDB Documentation: http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Query.html
|
|
|
|
#
|
2015-12-23 10:24:02 -05:00
|
|
|
def query(table_name, options = {}, hash_key_deprecated = nil)
|
|
|
|
if hash_key_deprecated || (options.keys.length == 1 && [:S, :N, :B].include?(options.keys.first.to_sym))
|
|
|
|
Fog::Logger.deprecation("The `20111205` API version is deprecated. You need to use `KeyConditionExpression` instead of `HashKey`.")
|
|
|
|
apiVersion = '20111205'
|
|
|
|
hash_key = options
|
|
|
|
options = hash_key_deprecated
|
|
|
|
end
|
|
|
|
|
2014-12-30 17:25:09 -05:00
|
|
|
body = {
|
2015-12-23 10:24:02 -05:00
|
|
|
'TableName' => table_name,
|
|
|
|
'HashKeyValue' => hash_key
|
2014-12-30 17:25:09 -05:00
|
|
|
}.merge(options)
|
|
|
|
|
|
|
|
request(
|
|
|
|
:body => Fog::JSON.encode(body),
|
2015-12-23 10:24:02 -05:00
|
|
|
:headers => {'x-amz-target' => "DynamoDB_#{apiVersion || '20120810'}.Query"}
|
2014-12-30 17:25:09 -05:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|