8000 expose `results.get_query()` in the c-api by nicola-cab · Pull Request #6568 · realm/realm-core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

expose results.get_query() in the c-api #6568

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

Merged
merged 3 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Enhancements
* <New feature description> (PR [#????](https://github.com/realm/realm-core/pull/????))
* New notifiers can now be registered in write transactions until changes have actually been made in the write transaction. This makes it so that new notifications can be registered inside change notifications triggered by beginning a write transaction (unless a previous callback performed writes).
* Expose `Results::get_query()` in the C-API. (PR [#6568](https://github.com/realm/realm-core/pull/6568))

### Fixed
* <How do the end-user experience this issue? what was the impact?> ([#????](https://github.com/realm/realm-core/issues/????), since v?.?.?)
Expand Down
8 changes: 8 additions & 0 deletions src/realm.h
Original file line number Diff line number Diff line change
Expand Up @@ -2574,6 +2574,14 @@ RLM_API bool realm_results_find(realm_results_t*, realm_value_t* value, size_t*
*/
RLM_API realm_object_t* realm_results_get_object(realm_results_t*, size_t index);

/**
* Return the query associated to the results passed as argument.
*
* @param results the ptr to a valid results object.
* @return a valid ptr to realm_query_t if no error has occured
*/
RLM_API realm_query_t* realm_results_get_query(realm_results_t* results);

/**
* Find the index for the realm object passed as parameter inside realm results pointer passed a input parameter.
* @param value the value to find inside the realm results
Expand Down
10 changes: 10 additions & 0 deletions src/realm/object-store/c_api/query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,16 @@ RLM_API realm_object_t* realm_results_get_object(realm_results_t* results, size_
});
}

RLM_API realm_query_t* realm_results_get_query(realm_results_t* results)
{
return wrap_err([&]() {
auto query = results->get_query();
auto shared_realm = results->get_realm();
auto ordering = query.get_ordering();
return new realm_query_t{std::move(query), std::move(ordering), shared_realm};
});
}

RLM_API bool realm_results_find_object(realm_results_t* results, realm_object_t* value, size_t* out_index,
bool* out_found)
{
Expand Down
13 changes: 13 additions & 0 deletions test/object-store/c_api/c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2591,6 +2591,19 @@ TEST_CASE("C API", "[c_api]") {
CHECK(found == false);
}

SECTION("realm_results_get_query()") {
auto q2 = cptr_checked(realm_query_parse(realm, class_foo.key, "int == 123", 0, nullptr));
auto r2 = cptr_checked(realm_results_filter(r.get(), q2.get()));
size_t count;
CHECK(checked(realm_results_count(r2.get(), &count)));
CHECK(count == 1);
auto results_query = cptr_checked(realm_results_get_query(r2.get()));
auto result = cptr_checked(realm_query_find_all(results_query.get()));
size_t count1 = 0;
CHECK(checked(realm_results_count(result.get(), &count1)));
CHECK(count == count1);
}

SECTION("realm_results_get_object()") {
auto p = cptr_checked(realm_results_get_object(r.get(), 0));
CHECK(p.get());
Expand Down
0