Skip to content

Automatically generate IDs and UIDs for entities and properties #18

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

Closed
nalenz-objectbox opened this issue Sep 11, 2019 · 5 comments
Closed

Comments

@nalenz-objectbox
Copy link
Contributor

nalenz-objectbox commented Sep 11, 2019

  • when writing an entity class, it should be enough to specify the respective annotation without any parameters, i.e. @Entity() class MyEntity { ... } should suffice
  • all instance variables of the entity class shall be incorporated into the final model and only those with special properties (e.g. @Id()) need to be annotated
  • all IDs and UIDs need to be generated by objectbox_model_generator, together with these rules on how to resolve changes and conflicts
  • in contrast to the current situation, this means that the existing generated file (specifically the _MyEntity_OBXModel object) needs to be parsed beforehand in order to detect changes
@vaind
Copy link
Contributor

vaind commented Sep 12, 2019

Have a look at https://github.com/objectbox/objectbox-go/tree/master/internal/generator as a reference implementation.

  • binding.go analyzes source code and prepares binding structs
  • package modelinfo handles reading and writing objectbox-model.json files (not in scope of this issue but will be necessary in the future)
  • merge.go takes model information from the binding.go and updates modelinfo, also updating binding information, especially ID/UIDs

@nalenz-objectbox
Copy link
Contributor Author

nalenz-objectbox commented Sep 24, 2019

The branch 18-automatic-id-generation now contains the following changes:

  • a file called objectbox-models.json is generated with a structure similar to ObjectBox Java
    • only merging entity properties is supported right now, indexes and relations are still completely missing
    • the overall file structure of the new generator is heavily influenced by the Go source you provided the link to
  • unannotated fields in an @Entity() class now behave just like those annotated with @Property()
  • upgraded Flutter demo with these new features

@vaind
Copy link
Contributor

vaind commented Sep 24, 2019

Oh, it's huge already. Please create a pull request (18-... to dev) so that I can review properly. And restrain yourself :) from adding more stuff (if you planned to do so) unless necessary for this issue - it's going to be hard to review as it is now. Thanks

@Buggaboo
Copy link
Contributor

Buggaboo commented Oct 2, 2019

At the risk of increasing the lines of code here, are there plans to support other types other than String and int? Currently my query tests are failing because things like bool and double are not supported.

@vaind
Copy link
Contributor

vaind commented Oct 3, 2019

At the risk of increasing the lines of code here, are there plans to support other types other than String and int? Currently my query tests are failing because things like bool and double are not supported.

It's not really related to the original goal of this ticket and should rather be covered by #11 - so that we can merge this PR ASAP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants