Exemplo n.º 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
Exemplo n.º 2
0
def main():

    # Crate database
    db = Database('/tmp/trafficDB')
    db.create()
    x_ind = WithXIndex(db.path, 'x')
    db.add_index(x_ind)

    # Import data from CSV files to database
    parser = ParserCSV()
    parser.get_csv_files()
    parser.db_import(db)

    # Display total number of records in database
    print db.count(db.all, 'id')
    print("--- %s seconds ---" % (time.time() - start_time))
Exemplo n.º 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 xrange(100):
            db.insert({'x': x})

        db.compact()
        assert db.count(db.all, 'id') == 100
Exemplo n.º 4
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 xrange(100):
            db.insert({'x': x})

        db.compact()
        assert db.count(db.all, 'id') == 100
Exemplo n.º 5
0
        return None

    def make_key(self, key):
        return key


arg = sys.argv[1]
ID = arg.split(".")[2]
db = Database('/codernity/sample_test')
#db.create()
db.open()
id_ind = WithXIndex(db.path, 'rsid')
#db.add_index(id_ind)

infile = open(arg, "r")
print db.count(db.all, 'id')

line = infile.readline()

count = 0
while line:
    if count != 0:
        tmp = line.split(",")
        sid = "s" + str(ID)
        #for cur in db.all('id'):
        #if cur['rsid'] == tmp[0]:
        #    cur['updated'] = True
        #    db.update(cur)
        if "rs" in tmp[0]:
            #try:
            cur = db.get('rsid', int(tmp[0].split("rs")[1]), with_doc=True)