Kagome
Polkadot Runtime Engine in C++17
rocksdb_batch.cpp
Go to the documentation of this file.
1 
7 
10 
11 namespace kagome::storage {
12 
13  RocksDB::Batch::Batch(RocksDB &db) : db_(db) {}
14 
15  outcome::result<void> RocksDB::Batch::put(const BufferView &key,
16  const Buffer &value) {
17  batch_.Put(make_slice(key), make_slice(value));
18  return outcome::success();
19  }
20 
21  outcome::result<void> RocksDB::Batch::put(const BufferView &key,
22  Buffer &&value) {
23  return put(key, static_cast<const Buffer &>(value));
24  }
25 
26  outcome::result<void> RocksDB::Batch::remove(const BufferView &key) {
27  batch_.Delete(make_slice(key));
28  return outcome::success();
29  }
30 
31  outcome::result<void> RocksDB::Batch::commit() {
32  auto status = db_.db_->Write(db_.wo_, &batch_);
33  if (status.ok()) {
34  return outcome::success();
35  }
36 
37  return status_as_error(status);
38  }
39 
41  batch_.Clear();
42  }
43 } // namespace kagome::storage
Class represents arbitrary (including empty) byte buffer.
Definition: buffer.hpp:29
rocksdb::WriteOptions wo_
Definition: rocksdb.hpp:67
outcome::result< void > remove(const BufferView &key) override
void clear() override
Clear batch.
DatabaseError status_as_error(const rocksdb::Status &s)
rocksdb::Slice make_slice(const common::BufferView &buf)
std::unique_ptr< rocksdb::DB > db_
Definition: rocksdb.hpp:65
outcome::result< void > commit() override
Writes batch.
outcome::result< void > put(const BufferView &key, const Buffer &value) override