Beispiel #1
0
def post(_id):
    db = Tree.from_file()
    if _id in db:
        return jsonify(error=('This key already exists in the database, use '
                              'PUT to update the key')), 500

    return add_request_to_db(db, _id)
Beispiel #2
0
def delete(_id):
    db = Tree.from_file()
    try:
        del db[_id]
    except KeyError:
        return jsonify(error='No data was found for this id'), 404

    db.commit()

    return jsonify(succes='deleted')
Beispiel #3
0
def main():
    for j in range(30):
        tree = Tree(max_size=3)
        for i in range(j + 1):
            tree[i] = i**2

        fancy_print(tree)

        print(tree)
        print('COMMMMIITTTTTT')
        tree.commit()
        print('IMPORRRTTTTT')
        new_tree = Tree.from_file()
        print(new_tree)
        print('IMUPPORRTTAANTT', new_tree)
        fancy_print(new_tree)
        new_tree[2] = 20
        fancy_print(new_tree)
        print('IMUPPORRTTAANTT', new_tree)
        fancy_print(new_tree)
        new_tree[3] = 30
        print('IMUPPORRTTAANTT', new_tree)
        fancy_print(new_tree)
        del new_tree[0]
        fancy_print(new_tree)
        print('IMUPPORRTTAANTT', new_tree)

        fancy_print(new_tree)
        print(getsize(new_tree.filename))
        print('COOOOMMMPPPAAACCCTTT')
        new_tree.compact()
        print(getsize(new_tree.filename))
        print('IMPORT COOOOMMMPPPAAACCCTTT')
        new_tree = Tree.from_file()
        new_tree[2] = 30
        print("PRRRRRINIINNT 11111")
        fancy_print(new_tree)
        del new_tree[3]
        print("PRRRRRINIINNT 2222222")
        fancy_print(new_tree)
        print()
        print()
Beispiel #4
0
def map():
    script = Script()
    tree = Tree.from_file()
    temp_tree = Tree(filename='map.db')
    temp_tree.compact()

    script.add_string(request.get_data())
    data = []
    for k, v in tree:
        temp_tree[k] = script.invoke('mapper', k, v)
    data = script.invoke('reducer', temp_tree.__iter__())

    return jsonify(result=data)
Beispiel #5
0
def post():
    db = Tree.from_file()
    _id = uuid.uuid4()
    return add_request_to_db(db, _id)
Beispiel #6
0
def delete():
    db = Tree.from_file()
    db.root = db._create_leaf()
    db.commit()
    db.compact()
    return jsonify()
Beispiel #7
0
def get():
    db = Tree.from_file()
    l = []
    for k, v in db:
        l.append({'id': k, 'data': v})
    return jsonify(items=l)
Beispiel #8
0
def compact():
    Tree.from_file().compact()
    return jsonify(success='compacted')
Beispiel #9
0
def get(_id):
    db = Tree.from_file()
    try:
        return jsonify(data=db[_id])
    except KeyError:
        return jsonify(error='No data was found for this id'), 404
Beispiel #10
0
def put(_id):
    db = Tree.from_file()
    if _id not in db:
        return jsonify(error=('No data was found for this id, use POST if'
                              ' you want to add a new document')), 404
    return add_request_to_db(db, _id)