Skip to content
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

Merged
merged 1 commit into from
Feb 5, 2023

Conversation

RoyBenMoshe
Copy link
Contributor

…ions(#378)

@RoyBenMoshe RoyBenMoshe linked an issue Jan 31, 2023 that may be closed by this pull request
examples/Makefile Show resolved Hide resolved
examples/speedb_is_awesome_example.cc Outdated Show resolved Hide resolved
DB::Open(options, kDBPath, &db);

// append new entry
std::string key = "key";
Copy link
Contributor

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".

Copy link
Contributor Author

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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);
Copy link
Contributor

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);
Copy link
Contributor

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();
Copy link
Contributor

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;
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

names were changed

std::string get_value;
s = db->Get(ReadOptions(), "key_1", &get_value);
assert(s.ok());
assert(get_value == put_val);
Copy link
Contributor

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;
Copy link
Contributor

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.

Copy link
Contributor Author

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);
Copy link
Contributor

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";
Copy link
Contributor

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.

@udi-speedb
Copy link
Contributor

@RoyBenMoshe - Please sqaush the commits into a single commit and insert a space before the (#378):
instructions(#378)
Thanks

@Yuval-Ariel Yuval-Ariel merged commit 38b4ac1 into main Feb 5, 2023
@Yuval-Ariel Yuval-Ariel deleted the 378-add-hello-world-example branch May 11, 2023 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add "Speedb is awesome!" example
3 participants