[Kimchi-devel] [PATCH] [Wok] Implement update methods for object store
Jose Ricardo Ziviani
joserz at linux.vnet.ibm.com
Thu Apr 7 17:28:07 UTC 2016
- 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 at 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
More information about the Kimchi-devel
mailing list