-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. Please check the return status
|
||
// retrieve entry | ||
std::string value; | ||
db->Get(ReadOptions(), "key", &value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. Please check the return status
std::cout << value << std::endl; | ||
|
||
// close DB | ||
db->Close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. Please check the return status
db->Put(WriteOptions(), key, val); | ||
|
||
// retrieve entry | ||
std::string value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really being petty here, but put_val / get_value (inconsistent)
|
||
int main() { | ||
// Open the storage | ||
DB* db; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's good practice to always explicitly init variables so I would init to nullptr
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done for all
|
||
// retrieve entry | ||
std::string get_value; | ||
s = db->Get(ReadOptions(), "key_1", &get_value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)