test_model.py 文件源码

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

项目:dynamorm 作者: NerdWalletOSS 项目源码 文件源码
def test_sparse_indexes(dynamo_local):
    class MyModel(DynaModel):
        class Table:
            name = 'mymodel'
            hash_key = 'foo'
            read = 10
            write = 10

        class Index1(GlobalIndex):
            name = 'index1'
            hash_key = 'bar'
            read = 10
            write = 10
            projection = ProjectInclude('foo', 'bar')

        class Schema:
            foo = String(required=True)
            bar = String(required=True)
            baz = String(required=True)
            bbq = String(required=True)

    MyModel.Table.create_table()
    MyModel.put_batch(
        {'foo': '1', 'bar': '1', 'baz': '1', 'bbq': '1'},
        {'foo': '2', 'bar': '2', 'baz': '2', 'bbq': '2'},
    )

    items = list(MyModel.Index1.query(bar='2'))
    assert len(items) == 1
    assert items[0].foo == '2'
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号