From 510fb89da08235fd0d5f38d8d5257b01138961a8 Mon Sep 17 00:00:00 2001 From: marcussorealheis Date: Sat, 10 Dec 2022 21:15:12 -0800 Subject: [PATCH 1/2] Adding an example of querying in C++ README --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index cd80d9cf..b7513e49 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,19 @@ 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({.path=path}); + auto results = realm.objects().where("age > $0", {20}); + + return results.size(); +} +``` + ## Building Realm In case you don't want to use the precompiled version, you can build Realm yourself from source. From 7224fc891ff5d5b8206ecfd6ad70965220fc2272 Mon Sep 17 00:00:00 2001 From: marcussorealheis Date: Mon, 12 Dec 2022 14:28:39 -0800 Subject: [PATCH 2/2] adding some more data manipulation to the C++ query example. --- README.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b7513e49..69960b32 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,16 @@ Realm offers an expressive and intuitive way for querying data. Here's a simple ```cpp int main() { auto realm = realm::open({.path=path}); - auto results = realm.objects().where("age > $0", {20}); + auto results = realm.objects().where("age > $0", {17}); - return results.size(); + for (const auto& person : results) { + std::string name = person.get_property("name"); + int age = person.get_property("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; } ```