def main():
    db = Database('/tmp/tut_update')
    db.create()
    x_ind = WithXIndex(db.path, 'x')
    db.add_index(x_ind)

    # full examples so we had to add first the data
    # the same code as in previous step

    for x in range(100):
        db.insert(dict(x=x))

    for y in range(100):
        db.insert(dict(y=y))

    # end of insert part

    print(db.count(db.all, 'x'))

    for curr in db.all('x', with_doc=True):
        doc = curr['doc']
        if curr['key'] % 7 == 0:
            db.delete(doc)
        elif curr['key'] % 5 == 0:
            doc['updated'] = True
            db.update(doc)

    print(db.count(db.all, 'x'))

    for curr in db.all('x', with_doc=True):
        print(curr)
Пример #2
0
 def test_to_many_shards(self, tmpdir):
     db = Database(str(tmpdir) + '/db')
     db.create(with_id_index=False)
     # it's ok to use sharded directly there
     with pytest.raises(IndexPreconditionsException):
         db.add_index(ShardedUniqueHashIndex(db.path, 'id', sh_nums=300))
     with pytest.raises(IndexPreconditionsException):
         db.add_index(ShardedUniqueHashIndex(db.path, 'id', sh_nums=256))
Пример #3
0
    def test_compact_shards(self, tmpdir):
        db = Database(str(tmpdir) + '/db')
        db.create(with_id_index=False)
        db.add_index(ShardedUniqueHashIndex5(db.path, 'id'))

        for x in range(100):
            db.insert({'x': x})

        db.compact()
        assert db.count(db.all, 'id') == 100
Пример #4
0
    def test_insert_get(self, tmpdir, sh_nums):
        db = Database(str(tmpdir) + '/db')
        db.create(with_id_index=False)
        n = globals()['ShardedUniqueHashIndex%d' % sh_nums]
        db.add_index(n(db.path, 'id'))
        l = []
        for x in range(10000):
            l.append(db.insert(dict(x=x))['_id'])

        for curr in l:
            assert db.get('id', curr)['_id'] == curr
Пример #5
0
def main():
    db = Database('/tmp/tut2')
    db.create()
    x_ind = WithXIndex(db.path, 'x')
    db.add_index(x_ind)

    for x in range(100):
        db.insert(dict(x=x))

    for y in range(100):
        db.insert(dict(y=y))

    print(db.get('x', 10, with_doc=True))
Пример #6
0
    def test_all(self, tmpdir, sh_nums):
        db = Database(str(tmpdir) + '/db')
        db.create(with_id_index=False)
        n = globals()['ShardedUniqueHashIndex%d' % sh_nums]
        db.add_index(n(db.path, 'id'))
        l = []
        for x in range(100):
            d = db.insert(dict(x=x))['_id']
            l.append(d)

        for curr in db.all('id'):
            d = curr['_id']
            l.remove(d)

        assert l == []
Пример #7
0
def main():
    db = Database('/tmp/tut4')
    db.create()
    x_ind = WithXIndex(db.path, 'x')
    db.add_index(x_ind)

    for x in range(11):
        db.insert(dict(x=x))

    for y in range(11):
        db.insert(dict(y=y))

    print(db.get('x', 10, with_doc=True))

    for curr in db.get_many('x', start=15, end=25, limit=-1, with_doc=True):
        print(curr)
def main():
    db = Database('/tmp/tut4')
    db.create()
    x_ind = WithXIndex(db.path, 'x')
    db.add_index(x_ind)

    for x in range(11):
        db.insert(dict(x=x))

    for y in range(11):
        db.insert(dict(y=y))

    print(db.get('x', 10, with_doc=True))

    for curr in db.get_many('x', start=15, end=25, limit=-1, with_doc=True):
        print(curr)
Пример #9
0
 def test_num_shards(self, tmpdir, sh_nums):
     db = Database(str(tmpdir) + '/db')
     db.create(with_id_index=False)
     n = globals()['ShardedUniqueHashIndex%d' % sh_nums]
     db.add_index(n(db.path, 'id'))
     assert db.id_ind.sh_nums == sh_nums
Пример #10
0
 def test_create(self, tmpdir):
     db = Database(str(tmpdir) + '/db')
     db.create(with_id_index=False)
     db.add_index(ShardedUniqueHashIndex(db.path, 'id', sh_nums=3))