add speedb is awesome example to support new getting started instruct… - #382
Conversation
26eda9e to
f6d558f
Compare
| DB::Open(options, kDBPath, &db); | ||
|
|
||
| // append new entry | ||
| std::string key = "key"; |
There was a problem hiding this comment.
It may be preferable to have the value of the key some other string as it may confuse beginners. Just pick any string other than "key".
There was a problem hiding this comment.
string was changed
| // create the DB if it's not already present | ||
| options.create_if_missing = true; | ||
|
|
||
| DB::Open(options, kDBPath, &db); |
There was a problem hiding this comment.
DB::Open() returns a status and may fail. It is definitely recommended to check the status and act accordingly.
There was a problem hiding this comment.
Status is now checked (for all places)
| // append new entry | ||
| std::string key = "key"; | ||
| std::string val = "Speedb is awesome!"; | ||
| db->Put(WriteOptions(), key, val); |
There was a problem hiding this comment.
Same here. Please check the return status
|
|
||
| // retrieve entry | ||
| std::string value; | ||
| db->Get(ReadOptions(), "key", &value); |
There was a problem hiding this comment.
Same here. Please check the return status
| std::cout << value << std::endl; | ||
|
|
||
| // close DB | ||
| db->Close(); |
There was a problem hiding this comment.
Same here. Please check the return status
| db->Put(WriteOptions(), key, val); | ||
|
|
||
| // retrieve entry | ||
| std::string value; |
There was a problem hiding this comment.
It may be preferable to have names such as put_value / read_value to the 2 variables (rather than val / value) to emphasize their role.
There was a problem hiding this comment.
names were changed
43b7edc to
929b721
Compare
| std::string get_value; | ||
| s = db->Get(ReadOptions(), "key_1", &get_value); | ||
| assert(s.ok()); | ||
| assert(get_value == put_val); |
There was a problem hiding this comment.
Really being petty here, but put_val / get_value (inconsistent)
|
|
||
| int main() { | ||
| // Open the storage | ||
| DB* db; |
There was a problem hiding this comment.
It's good practice to always explicitly init variables so I would init to nullptr.
|
|
||
| // retrieve entry | ||
| std::string get_value; | ||
| s = db->Get(ReadOptions(), "key_1", &get_value); |
There was a problem hiding this comment.
Why aren't you using put_key instead of the literal "key_1"?
| assert(s.ok()); | ||
|
|
||
| // append new entry | ||
| std::string put_key = "key_1"; |
There was a problem hiding this comment.
Better call put_key just key as it it used (should be used) for both put & get.
|
@RoyBenMoshe - Please sqaush the commits into a single commit and insert a space before the (#378): |
6d50d6c to
2603cab
Compare
…ions(#378)