Example #1
0
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 xrange(100):
        db.insert(dict(x=x))

    for y in xrange(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)
Example #2
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