From ea7d0b943a07ee54bba826e30d022927376c6f77 Mon Sep 17 00:00:00 2001 From: alabid Date: Tue, 27 Jan 2015 19:37:36 -0500 Subject: [PATCH] Added WriteBatch block to simple_example.cc --- examples/simple_example.cc | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/examples/simple_example.cc b/examples/simple_example.cc index 20e7faa4b..28a7c9e8b 100644 --- a/examples/simple_example.cc +++ b/examples/simple_example.cc @@ -27,14 +27,28 @@ int main() { assert(s.ok()); // Put key-value - s = db->Put(WriteOptions(), "key", "value"); + s = db->Put(WriteOptions(), "key1", "value"); assert(s.ok()); std::string value; // get value - s = db->Get(ReadOptions(), "key", &value); + s = db->Get(ReadOptions(), "key1", &value); assert(s.ok()); assert(value == "value"); + // atomically apply a set of updates + { + WriteBatch batch; + batch.Delete("key1"); + batch.Put("key2", value); + s = db->Write(WriteOptions(), &batch); + } + + s = db->Get(ReadOptions(), "key1", &value); + assert(s.IsNotFound()); + + db->Get(ReadOptions(), "key2", &value); + assert(value == "value"); + delete db; return 0;