- This commit implements two new methods for object store, update_data
and update_id. Now it's possible to update an existing data
instead of delete/create.
Signed-off-by: Jose Ricardo Ziviani <joserz(a)linux.vnet.ibm.com>
---
src/wok/objectstore.py | 13 +++++++++++++
tests/test_objectstore.py | 11 +++++++++++
2 files changed, 24 insertions(+)
diff --git a/src/wok/objectstore.py b/src/wok/objectstore.py
index ff3796c..5ec87eb 100644
--- a/src/wok/objectstore.py
+++ b/src/wok/objectstore.py
@@ -94,6 +94,19 @@ class ObjectStoreSession(object):
(ident, obj_type, jsonstr, version))
self.conn.commit()
+ def update_data(self, obj_type, ident, data):
+ jsonstr = json.dumps(data)
+ c = self.conn.cursor()
+ c.execute('UPDATE objects SET json=? WHERE id=? AND type=?',
+ (jsonstr, ident, obj_type))
+ self.conn.commit()
+
+ def update_id(self, obj_type, ident, new_ident):
+ c = self.conn.cursor()
+ c.execute('UPDATE objects SET id=? WHERE id=? AND type=?',
+ (new_ident, ident, obj_type))
+ self.conn.commit()
+
class ObjectStore(object):
def __init__(self, location=None):
diff --git a/tests/test_objectstore.py b/tests/test_objectstore.py
index 3ea7b70..d6ea434 100644
--- a/tests/test_objectstore.py
+++ b/tests/test_objectstore.py
@@ -82,6 +82,17 @@ class ObjectStoreTests(unittest.TestCase):
item = session.get_object_version('f����', 't��st1')
self.assertEquals(get_version().split('-')[0], item[0])
+ # test update data
+ session.update_data('f����', 't��st1', {'��': 5})
+ item = session.get('f����', 't��st1')
+ self.assertEquals(5, item[u'��'])
+
+ # test update id
+ session.update_id('f����', 't��st1', 't��st2')
+ item = session.get('f����', 't��st2')
+ self.assertEquals(5, item[u'��'])
+
+
def test_object_store_threaded(self):
def worker(ident):
with store as session:
--
1.9.1