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)
Esempio n. 2
0
def main():
    db = Database('/tmp/tut1')
    db.create()
    for x in range(100):
        print(db.insert(dict(x=x)))
    for curr in db.all('id'):
        print(curr)
Esempio n. 3
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(10000):
            l.append(db.insert(dict(x=x))['_id'])

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

        assert l == []
Esempio n. 4
0
def migrate(source, destination):
    """
    Very basic for now
    """
    dbs = Database(source)
    dbt = Database(destination)
    dbs.open()
    dbt.create()
    dbt.close()
    for curr in os.listdir(os.path.join(dbs.path, '_indexes')):
        if curr != '00id.py':
            shutil.copyfile(os.path.join(dbs.path, '_indexes', curr),
                            os.path.join(dbt.path, '_indexes', curr))
    dbt.open()
    for c in dbs.all('id'):
        del c['_rev']
        dbt.insert(c)
    return True