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

Adding an example of querying in C++ README #33

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,26 @@ realm.write([&car](){
});
```

## Construct a Simple Query

Realm offers an expressive and intuitive way for querying data. Here's a simple example of querying for all `Person` objects and filtering the result based on age.

```cpp
int main() {
auto realm = realm::open<Person, Dog>({.path=path});
auto results = realm.objects<Person>().where("age > $0", {17});

for (const auto& person : results) {
std::string name = person.get_property<std::string>("name");
int age = person.get_property<int>("age");
std::string dogPurchasePower = (age >= 18) ? "can legally buy a dog in California" : "cannot legally buy a dog in California";
std::cout << "Customer " << name << " is " << age << " and " << dogPurchasePower << std::endl;
}

return 0;
}
```

## Building Realm

In case you don't want to use the precompiled version, you can build Realm yourself from source.
Expand Down