本文整理汇总了Python中boto.dynamodb2.layer1.DynamoDBConnection.query方法的典型用法代码示例。如果您正苦于以下问题:Python DynamoDBConnection.query方法的具体用法?Python DynamoDBConnection.query怎么用?Python DynamoDBConnection.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boto.dynamodb2.layer1.DynamoDBConnection
的用法示例。
在下文中一共展示了DynamoDBConnection.query方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Table
# 需要导入模块: from boto.dynamodb2.layer1 import DynamoDBConnection [as 别名]
# 或者: from boto.dynamodb2.layer1.DynamoDBConnection import query [as 别名]
#.........这里部分代码省略.........
out & build the high-level Python objects that represent them.
"""
indexes = []
for field in raw_indexes:
index_klass = AllIndex
kwargs = {"parts": []}
if field["Projection"]["ProjectionType"] == "ALL":
index_klass = AllIndex
elif field["Projection"]["ProjectionType"] == "KEYS_ONLY":
index_klass = KeysOnlyIndex
elif field["Projection"]["ProjectionType"] == "INCLUDE":
index_klass = IncludeIndex
kwargs["includes"] = field["Projection"]["NonKeyAttributes"]
else:
raise exceptions.UnknownIndexFieldError(
"%s was seen, but is unknown. Please report this at "
"https://github.com/boto/boto/issues." % field["Projection"]["ProjectionType"]
)
name = field["IndexName"]
kwargs["parts"] = self._introspect_schema(field["KeySchema"])
indexes.append(index_klass(name, **kwargs))
return indexes
def describe(self):
"""
Describes the current structure of the table in DynamoDB.
This information will be used to update the ``schema``, ``indexes``
and ``throughput`` information on the ``Table``. Some calls, such as
those involving creating keys or querying, will require this
information to be populated.
It also returns the full raw datastructure from DynamoDB, in the
event you'd like to parse out additional information (such as the
``ItemCount`` or usage information).
Example::
>>> users.describe()
{
# Lots of keys here...
}
>>> len(users.schema)
2
"""
result = self.connection.describe_table(self.table_name)
# Blindly update throughput, since what's on DynamoDB's end is likely
# more correct.
raw_throughput = result["Table"]["ProvisionedThroughput"]
self.throughput["read"] = int(raw_throughput["ReadCapacityUnits"])
self.throughput["write"] = int(raw_throughput["WriteCapacityUnits"])
if not self.schema:
# Since we have the data, build the schema.
raw_schema = result["Table"].get("KeySchema", [])
self.schema = self._introspect_schema(raw_schema)
if not self.indexes:
# Build the index information as well.
raw_indexes = result["Table"].get("LocalSecondaryIndexes", [])
示例2: DynamoDBv2Layer1Test
# 需要导入模块: from boto.dynamodb2.layer1 import DynamoDBConnection [as 别名]
# 或者: from boto.dynamodb2.layer1.DynamoDBConnection import query [as 别名]
#.........这里部分代码省略.........
}
r1_result = self.dynamodb.put_item(self.table_name, record_1_data)
# Get the data.
record_1 = self.dynamodb.get_item(self.table_name, key={
'username': {'S': 'johndoe'},
'date_joined': {'N': '1366056668'},
}, consistent_read=True)
self.assertEqual(record_1['Item']['username']['S'], 'johndoe')
self.assertEqual(record_1['Item']['first_name']['S'], 'John')
self.assertEqual(record_1['Item']['friends']['SS'], [
'alice', 'bob', 'jane'
])
# Now in a batch.
self.dynamodb.batch_write_item({
self.table_name: [
{
'PutRequest': {
'Item': {
'username': {'S': 'jane'},
'first_name': {'S': 'Jane'},
'last_name': {'S': 'Doe'},
'date_joined': {'N': '1366056789'},
'friend_count': {'N': '1'},
'friends': {'SS': ['johndoe']},
},
},
},
]
})
# Now a query.
lsi_results = self.dynamodb.query(
self.table_name,
index_name='MostRecentIndex',
key_conditions={
'username': {
'AttributeValueList': [
{'S': 'johndoe'},
],
'ComparisonOperator': 'EQ',
},
},
consistent_read=True
)
self.assertEqual(lsi_results['Count'], 1)
results = self.dynamodb.query(self.table_name, key_conditions={
'username': {
'AttributeValueList': [
{'S': 'jane'},
],
'ComparisonOperator': 'EQ',
},
'date_joined': {
'AttributeValueList': [
{'N': '1366050000'}
],
'ComparisonOperator': 'GT',
}
}, consistent_read=True)
self.assertEqual(results['Count'], 1)
# Now a scan.
results = self.dynamodb.scan(self.table_name)
示例3: Table
# 需要导入模块: from boto.dynamodb2.layer1 import DynamoDBConnection [as 别名]
# 或者: from boto.dynamodb2.layer1.DynamoDBConnection import query [as 别名]
#.........这里部分代码省略.........
for field in raw_indexes:
index_klass = AllIndex
kwargs = {
'parts': []
}
if field['Projection']['ProjectionType'] == 'ALL':
index_klass = AllIndex
elif field['Projection']['ProjectionType'] == 'KEYS_ONLY':
index_klass = KeysOnlyIndex
elif field['Projection']['ProjectionType'] == 'INCLUDE':
index_klass = IncludeIndex
kwargs['includes'] = field['Projection']['NonKeyAttributes']
else:
raise exceptions.UnknownIndexFieldError(
"%s was seen, but is unknown. Please report this at "
"https://github.com/boto/boto/issues." % \
field['Projection']['ProjectionType']
)
name = field['IndexName']
kwargs['parts'] = self._introspect_schema(field['KeySchema'], None)
indexes.append(index_klass(name, **kwargs))
return indexes
def describe(self):
"""
Describes the current structure of the table in DynamoDB.
This information will be used to update the ``schema``, ``indexes``
and ``throughput`` information on the ``Table``. Some calls, such as
those involving creating keys or querying, will require this
information to be populated.
It also returns the full raw datastructure from DynamoDB, in the
event you'd like to parse out additional information (such as the
``ItemCount`` or usage information).
Example::
>>> users.describe()
{
# Lots of keys here...
}
>>> len(users.schema)
2
"""
result = self.connection.describe_table(self.table_name)
# Blindly update throughput, since what's on DynamoDB's end is likely
# more correct.
raw_throughput = result['Table']['ProvisionedThroughput']
self.throughput['read'] = int(raw_throughput['ReadCapacityUnits'])
self.throughput['write'] = int(raw_throughput['WriteCapacityUnits'])
if not self.schema:
# Since we have the data, build the schema.
raw_schema = result['Table'].get('KeySchema', [])
raw_attributes = result['Table'].get('AttributeDefinitions', [])
self.schema = self._introspect_schema(raw_schema, raw_attributes)
if not self.indexes:
# Build the index information as well.