realm-kotlin
realm-kotlin copied to clipboard
Support default schema creation
Currently, we have to pass in a class annotated with RealmModule which captures some or all the models that we would like to participate in the Realm scheam. This works fines for modules and library but adds an extra step to open a Realm of you want the default behaviour that consist of using all the annotated RealmObject classes
Things we need to tackle:
- How to locate all classes implementing
RealmObject? This should also work with incremental compilation steps. - How to handle that model classes might be defined in multiple modules. Relying on autogenerated code can be problematic if multiple modules write to the same location.
Some background from Realm Java
- The annotation processor there allows us to find all Realm model classes.
- We write these model classes to a
DefaultMediatorclass, which was looked up using reflection at runtime. - Libraries are required to create a class annotated with
@RealmModule. This disables the generation of aDefaultMediatorand also requires that people define aRealmConfiguration.modules(...)as a way to set the schema.
This approach means that app projects work out of the box, while library modules require extra work. So far, this seems to have been a sensible tradeoff, but it is unclear if the same would work for Multiplatform where Realm primarily is used within a library module.
Also bear in mind the following compiler constraints expressed in https://github.com/realm/realm-kotlin/pull/156#issue-610868385
Maybe some ideas for doing this can be found here: https://kotlinlang.slack.com/archives/C7L3JB43G/p1634316429144100?thread_ts=1634306190.142200&cid=C7L3JB43G