query_items.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:dynamodb-py 作者: gusibi 项目源码 文件源码
def query_with_limit_and_filter_by_boto3():
    table = dynamodb.Table('Movies')
    print("Movies from 1992 - titles A-L, with genres and lead actor")
    try:
        response = table.query(
            ProjectionExpression="#yr, title, info.genres, info.actors[0]",
            ExpressionAttributeNames={"#yr": "year"}, # Expression Attribute Names for Projection Expression only.
            KeyConditionExpression=Key('year').eq(1992) & Key('title').between('A', 'L'),
            FilterExpression=Attr('rating').lt(decimal.Decimal(str('7.0'))),
            Limit=10,
        )
    except ClientError as e:
        print(e.response['Error']['Message'])
    else:
        items = response['Items']
        for i in items:
            print(i['year'], ":", i['title'])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号