Skip to content

add speedb is awesome example to support new getting started instruct… - #382

Merged
Yuval-Ariel merged 1 commit into
mainfrom
378-add-hello-world-example
Feb 5, 2023
Merged

add speedb is awesome example to support new getting started instruct…#382
Yuval-Ariel merged 1 commit into
mainfrom
378-add-hello-world-example

Conversation

@RoyBenMoshe

Copy link
Copy Markdown
Contributor

…ions(#378)

@RoyBenMoshe RoyBenMoshe linked an issue Jan 31, 2023 that may be closed by this pull request
@RoyBenMoshe
RoyBenMoshe force-pushed the 378-add-hello-world-example branch from 26eda9e to f6d558f Compare January 31, 2023 14:42
Comment thread examples/Makefile
Comment thread examples/speedb_is_awesome_example.cc Outdated
Comment thread examples/speedb_is_awesome_example.cc Outdated
DB::Open(options, kDBPath, &db);

// append new entry
std::string key = "key";

Copy link
Copy Markdown
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
Copy Markdown
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

Comment thread examples/speedb_is_awesome_example.cc Outdated
// create the DB if it's not already present
options.create_if_missing = true;

DB::Open(options, kDBPath, &db);

Copy link
Copy Markdown
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
Copy Markdown
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)

Comment thread examples/speedb_is_awesome_example.cc Outdated
// append new entry
std::string key = "key";
std::string val = "Speedb is awesome!";
db->Put(WriteOptions(), key, val);

Copy link
Copy Markdown
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

Comment thread examples/speedb_is_awesome_example.cc Outdated

// retrieve entry
std::string value;
db->Get(ReadOptions(), "key", &value);

Copy link
Copy Markdown
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

Comment thread examples/speedb_is_awesome_example.cc Outdated
std::cout << value << std::endl;

// close DB
db->Close();

Copy link
Copy Markdown
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

Comment thread examples/speedb_is_awesome_example.cc Outdated
db->Put(WriteOptions(), key, val);

// retrieve entry
std::string value;

Copy link
Copy Markdown
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
Copy Markdown
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

@RoyBenMoshe
RoyBenMoshe force-pushed the 378-add-hello-world-example branch from 43b7edc to 929b721 Compare January 31, 2023 18:08
Comment thread examples/speedb_is_awesome_example.cc Outdated
std::string get_value;
s = db->Get(ReadOptions(), "key_1", &get_value);
assert(s.ok());
assert(get_value == put_val);

Copy link
Copy Markdown
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)

Comment thread examples/speedb_is_awesome_example.cc Outdated

int main() {
// Open the storage
DB* db;

Copy link
Copy Markdown
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
Copy Markdown
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

Comment thread examples/speedb_is_awesome_example.cc Outdated

// retrieve entry
std::string get_value;
s = db->Get(ReadOptions(), "key_1", &get_value);

Copy link
Copy Markdown
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"?

Comment thread examples/speedb_is_awesome_example.cc Outdated
assert(s.ok());

// append new entry
std::string put_key = "key_1";

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

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

@RoyBenMoshe
RoyBenMoshe force-pushed the 378-add-hello-world-example branch from 6d50d6c to 2603cab Compare February 1, 2023 14:50
@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