我在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中实现同样的目标
答案 0 :(得分:0)
试试这个:
private void getUserName(String startedBy, TextView textView) {
mProfileRef=database.getReference("Profile").child(startedBy).child("UserDetails").child("userName");
mProfileRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
userName = dataSnapshot.getValue(String.class);
textView.setText(userName);
Log.i(TAG, "onDataChange: "+userName);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
指向for order_item in Order.scan(Order.order_status == 0 & (Order.created_on >= start_date) & (Order.created_on <= end_date)):
print(order_item)
API doc的链接:
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
希望这有帮助。