### Perform database reads and writes Source: https://rocksdb.org/docs Use Get, Put, and Delete methods to manipulate key-value pairs. ```cpp std::string value; rocksdb::Status s = db->Get(rocksdb::ReadOptions(), key1, &value); if (s.ok()) s = db->Put(rocksdb::WriteOptions(), key2, value); if (s.ok()) s = db->Delete(rocksdb::WriteOptions(), key1); ``` -------------------------------- ### Open a RocksDB database Source: https://rocksdb.org/docs Initialize a database connection and create the directory if it does not exist. ```cpp #include #include "rocksdb/db.h" rocksdb::DB* db; rocksdb::Options options; options.create_if_missing = true; rocksdb::Status status = rocksdb::DB::Open(options, "/tmp/testdb", &db); assert(status.ok()); ... ``` -------------------------------- ### Configure database error on existence Source: https://rocksdb.org/docs Set the options to trigger an error if the database directory already exists. ```cpp options.error_if_exists = true; ``` -------------------------------- ### Handle RocksDB status Source: https://rocksdb.org/docs Check the result of a database operation and output error messages if the operation fails. ```cpp rocksdb::Status s = ...; if (!s.ok()) cerr << s.ToString() << endl; ``` -------------------------------- ### Close a RocksDB database Source: https://rocksdb.org/docs Release database resources by deleting the database object. ```cpp /* open the db as described above */ /* do something with db */ delete db; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.