objectbox / objectbox-dart

Flutter database for super-fast Dart object persistence
https://docs.objectbox.io/getting-started
Apache License 2.0
927 stars 115 forks source link

Support annotations for getter/setter properties #392

Closed khainke closed 3 months ago

khainke commented 2 years ago

Currently, the @Property Annotation is only available for fields, that are defined as such in the @Entity.

Describe the solution you'd like

It would be nice to be able to add the @Property Annotation also to a getter (assuming a matching setter exists). This would just have the same effect on the property defined by the getter / setter pair as if it would have, would the annotation be attached to an equivalent field.

greenrobot-team commented 2 years ago

Thanks! It's odd that this doesn't work already. Also @Transient on a getter does not appear to get recognized.

Edit: an internal issue for this exists.

greenrobot-team commented 1 year ago

Same for @Index, reported originally in #528.

greenrobot-team commented 7 months ago

Also freezed classes with non-required properties are affected by this, see #565.

greenrobot-team commented 3 months ago

Annotating getters will be possible with the next release.

You will be able to do something like this:

  @Property(type: PropertyType.date)
  @Index()
  DateTime get date => TODO;
  set date(DateTime value) => TODO;

  @Transient()
  int get computedValue => TODO;
  set computedValue(int value) => TODO;