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

Results of primitives #893

Merged
merged 8 commits into from
Oct 26, 2022
Merged

Results of primitives #893

merged 8 commits into from
Oct 26, 2022

Conversation

nielsenko
Copy link
Contributor

@nielsenko nielsenko commented Sep 9, 2022

Resolves #162

@cla-bot cla-bot bot added the cla: yes label Sep 9, 2022
@nielsenko nielsenko self-assigned this Sep 11, 2022
@coveralls
Copy link

coveralls commented Sep 11, 2022

Pull Request Test Coverage Report for Build 3322498460

  • 33 of 37 (89.19%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.6%) to 88.884%

Changes Missing Coverage Covered Lines Changed/Added Lines %
lib/src/list.dart 8 12 66.67%
Totals Coverage Status
Change from base Build 3322331710: -0.6%
Covered Lines: 2199
Relevant Lines: 2474

💛 - Coveralls

@nielsenko nielsenko force-pushed the kn/results-of-primitives branch 2 times, most recently from 2aaea08 to d5c2af3 Compare September 13, 2022 09:59
@nielsenko nielsenko changed the base branch from master to kn/indexes September 13, 2022 12:20
@nielsenko nielsenko force-pushed the kn/indexes branch 2 times, most recently from 18a009d to e72bd4f Compare September 14, 2022 17:17
@nielsenko nielsenko force-pushed the kn/results-of-primitives branch 3 times, most recently from f1fe4c0 to c093026 Compare September 14, 2022 19:38
@nielsenko nielsenko linked an issue Sep 15, 2022 that may be closed by this pull request
@nielsenko nielsenko force-pushed the kn/results-of-primitives branch 2 times, most recently from 523cd5d to 4ea3988 Compare September 23, 2022 11:42
@nielsenko nielsenko force-pushed the kn/indexes branch 2 times, most recently from c7125a4 to 81beb39 Compare September 26, 2022 09:17
Copy link
Contributor

@blagoev blagoev left a comment

Choose a reason for hiding this comment

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

I have some suggestions

lib/src/list.dart Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
lib/src/list.dart Outdated Show resolved Hide resolved
lib/src/list.dart Outdated Show resolved Hide resolved
RealmResults<T> query(String query, [List<Object> args = const []]) {
final handle = realmCore.queryResults(this, query, args);
return RealmResultsInternal.create<T>(handle, realm, _metadata);
final meta = _metadata;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not check if T is RealmObjectBase which is the real marker if this can create objects or it is a results of primitives.

Copy link
Member

Choose a reason for hiding this comment

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

We can check either one, but we should assert on the other - i.e. if we get a RealmObjectBase with no meta or meta with a non-RealmObjectBase generic, that would be a bug in the SDK.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree we can assert the metadata, but I think we should only check the type is RealmObjectBase since this is the real marker.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have reworked this to check on type instead. Assert on _meta != null is implicit in:

      final handle = realmCore.resultsGetObjectAt(this, index);
      final accessor = RealmCoreAccessor(metadata, realm.isInMigration);

I expect the first line to fail, and otherwise metadata => _metadata! will.

CHANGELOG.md Outdated Show resolved Hide resolved
Comment on lines +883 to +891
Object? resultsGetElementAt(RealmResults results, int index) {
return using((Arena arena) {
final realm_value = arena<realm_value_t>();
_realmLib.invokeGetBool(() => _realmLib.realm_results_get(results.handle._pointer, index, realm_value));
return realm_value.toDartValue(results.realm);
});
}

RealmObjectHandle resultsGetObjectAt(RealmResults results, int index) {
Copy link
Member

Choose a reason for hiding this comment

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

Why are those different?

Copy link
Contributor

Choose a reason for hiding this comment

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

one is returning a RealmObject while the other is returning a realm_value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct

Copy link
Member

Choose a reason for hiding this comment

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

I can see that. Since realm_value can hold objects, why not use the same method for both?

Copy link
Contributor Author

@nielsenko nielsenko Oct 25, 2022

Choose a reason for hiding this comment

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

You still need to convert the handle (toDartValue don't/can't), and the later is less efficient.

lib/src/results.dart Outdated Show resolved Hide resolved
lib/src/results.dart Outdated Show resolved Hide resolved
lib/src/results.dart Outdated Show resolved Hide resolved
lib/src/list.dart Outdated Show resolved Hide resolved
@nielsenko nielsenko force-pushed the kn/results-of-primitives branch 6 times, most recently from 3f1449e to bb15f26 Compare October 25, 2022 14:01
@@ -4,6 +4,8 @@

### Enhancements
* Added `MutableSubscriptionSet.removeByType` for removing subscriptions by their realm object type. (Issue [#317](https://github.com/realm/realm-dart/issues/317))
* Support results of primitives, ie. `RealmResult<int>`. (Issue [#162](https://github.com/realm/realm-dart/issues/162))
* Support notifications on all managed realm lists, including list of primitives, ie. `RealmList<int>.changes` is supported. ([#893](https://github.com/realm/realm-dart/pull/893))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Support notifications on all managed realm lists, including list of primitives, ie. `RealmList<int>.changes` is supported. ([#893](https://github.com/realm/realm-dart/pull/893))
* Support notifications on all managed `RealmList`s, including list of primitive types, for example: `RealmList<int>.changes` is supported. ([#893](https://github.com/realm/realm-dart/pull/893))

lib/src/results.dart Show resolved Hide resolved
@nielsenko nielsenko merged commit eba2e31 into master Oct 26, 2022
@nielsenko nielsenko deleted the kn/results-of-primitives branch October 26, 2022 15:45
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support results of primitives
5 participants