我在Dynamodb中创建了包含以下详细信息的表
class OrderStatusIndex(GlobalSecondaryIndex):
class Meta:
index_name = 'OrderStatusIndex'
read_capacity_units = 2
write_capacity_units = 1
projection = AllProjection()
order_status = NumberAttribute(hash_key=True)
created_on = UnicodeAttribute(range_key=True)
class Order(Model):
class Meta:
table_name = 'order'
host = 'http://localhost:8000'
read_capacity_units = 2
write_capacity_units = 1
order_id = NumberAttribute(hash_key=True)
order_status = NumberAttribute(hash_key=True)
created_on = UnicodeAttribute(range_key=True)
order_status_index = OrderStatusIndex()
现在我想根据在特定日期获得的订单状态进行查询,如果我执行mysql查询,结果将如下所示
select *from order where order_status = 0 and created_on >= start_date and created_on <=end_date
有没有什么方法可以用pynamodb在Dynamodb中实现同样的功能
发布于 2018-03-29 07:00:19
试试这个:
for order_item in Order.scan(Order.order_status == 0 & (Order.created_on >= start_date) & (Order.created_on <= end_date)):
print(order_item)
指向pynamodb
API文档的链接:
http://pynamodb.readthedocs.io/en/latest/api.html#pynamodb.models.Model.scan
您可以参考以下链接,了解如何在pynamodb
查询上使用条件表达式。
https://pynamodb.readthedocs.io/en/latest/batch.html#query-filters
https://pynamodb.readthedocs.io/en/latest/conditional.html#condition-expressions
希望这能有所帮助。
https://stackoverflow.com/questions/49447794
复制相似问题