Opening A Database
A rocksdb
database has a name which corresponds to a
file system directory. All of the contents of database are stored in
this directory. The following example shows how to open a database,
creating it if necessary:
#include <assert> #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()); ...
If you want to raise an error if the database already exists, add
the following line before the rocksdb::DB::Open
call:
options.error_if_exists = true;