diff --git a/db/c.cc b/db/c.cc index 77b33d5..7756ea3 100644 --- a/db/c.cc +++ b/db/c.cc @@ -359,7 +359,7 @@ void leveldb_writebatch_delete( } void leveldb_writebatch_iterate( - leveldb_writebatch_t* b, + const leveldb_writebatch_t* b, void* state, void (*put)(void*, const char* k, size_t klen, const char* v, size_t vlen), void (*deleted)(void*, const char* k, size_t klen)) { @@ -382,6 +382,11 @@ void leveldb_writebatch_iterate( b->rep.Iterate(&handler); } +void leveldb_writebatch_append(leveldb_writebatch_t *destination, + const leveldb_writebatch_t *source) { + destination->rep.Append(source->rep); +} + leveldb_options_t* leveldb_options_create() { return new leveldb_options_t; } diff --git a/db/c_test.c b/db/c_test.c index 7284de5..ae14b99 100644 --- a/db/c_test.c +++ b/db/c_test.c @@ -228,12 +228,18 @@ int main(int argc, char** argv) { leveldb_writebatch_clear(wb); leveldb_writebatch_put(wb, "bar", 3, "b", 1); leveldb_writebatch_put(wb, "box", 3, "c", 1); - leveldb_writebatch_delete(wb, "bar", 3); + + leveldb_writebatch_t* wb2 = leveldb_writebatch_create(); + leveldb_writebatch_delete(wb2, "bar", 3); + leveldb_writebatch_append(wb, wb2); + leveldb_writebatch_destroy(wb2); + leveldb_write(db, woptions, wb, &err); CheckNoError(err); CheckGet(db, roptions, "foo", "hello"); CheckGet(db, roptions, "bar", NULL); CheckGet(db, roptions, "box", "c"); + int pos = 0; leveldb_writebatch_iterate(wb, &pos, CheckPut, CheckDel); CheckCondition(pos == 3); diff --git a/include/leveldb/c.h b/include/leveldb/c.h index 1124153..d8aab5b 100644 --- a/include/leveldb/c.h +++ b/include/leveldb/c.h @@ -155,9 +155,11 @@ LEVELDB_EXPORT void leveldb_writebatch_put(leveldb_writebatch_t*, LEVELDB_EXPORT void leveldb_writebatch_delete(leveldb_writebatch_t*, const char* key, size_t klen); LEVELDB_EXPORT void leveldb_writebatch_iterate( - leveldb_writebatch_t*, void* state, + const leveldb_writebatch_t*, void* state, void (*put)(void*, const char* k, size_t klen, const char* v, size_t vlen), void (*deleted)(void*, const char* k, size_t klen)); +LEVELDB_EXPORT void leveldb_writebatch_append( + leveldb_writebatch_t* destination, const leveldb_writebatch_t* source); /* Options */