[Kimchi-devel] [PATCH] [Wok] Implement update methods for object store

Lucio Correia luciojhc at linux.vnet.ibm.com
Thu Apr 7 17:38:00 UTC 2016


On 07-04-2016 14:28, Jose Ricardo Ziviani wrote:
>   - 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()
I see that store() could be used to update existent entries as well, 
because it first removes the entry and then adds it again with same id.
Is there any difference here?


> +
> +    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:
>
>
>
> _______________________________________________
> Kimchi-devel mailing list
> Kimchi-devel at ovirt.org
> http://lists.ovirt.org/mailman/listinfo/kimchi-devel
>


-- 
Lucio Correia
Software Engineer
IBM LTC Brazil




More information about the Kimchi-devel mailing list