Merge pull request #476 from alabid/alabid/add-to-simple-example

Added WriteBatch block to simple_example.cc
This commit is contained in:
Igor Canadi 2015-01-27 18:12:44 -08:00
commit 551a41df37
3 changed files with 19 additions and 2 deletions

1
.gitignore vendored
View File

@ -20,6 +20,7 @@ make_config.mk
*.d-e
*.o-*
*.swp
*~
ldb
manifest_dump

2
examples/.gitignore vendored
View File

@ -1,2 +1,4 @@
column_families_example
simple_example
c_simple_example
compact_files_example

View File

@ -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;