Conversation
|
@cmelchior Thanks for the detailed proposal, I would almost say that option B is better as it's more concise if the import is done directly one the Realm database object. A few suggestions though:
Also, still an open question for me is how to guarantee the order of execution of the annotation processors involved. We need to somehow make sure that the proxy classes get generated first, so the import/export processor can add its code to it. |
I also like a enum a lot more, but it makes the API less flexible since you are then constrained to the types we define. I'm not sure it is a problem in practise though as |
I could define flatbuffer or something ridiculous like flatbuffers
I have this wild guess that the right direction would be something like the Retrofit2 Converter.Factory approach. |
Retrofit has the luxury of making the users define the interface, so they can annotate their API with |
uh... isn't that why the converter factory gets a list of annotations which can be used to determine if it's for |
|
Yes, and that is a great idea, but users doesn't control the Realm API, so they cannot annotate the import method. |
|
They can annotate RealmObjects though. Maybe that changes things? The key here is "automating" batch insertion, or so I would think. Although I do wonder how relationships would be handled, or custom serialization like for RealmList of RealmInts. This is a difficult issue, I'll try to think about it; although my wild guess is that you'll come up with something even better than any idea I'd have. :D /sleeptime |
| @@ -0,0 +1,243 @@ | |||
| # Import / Export API | |||
|
|
|||
| This document describe a possible new Import/Export API that is more generalized | |||
|
|
||
| So instead of just keep piling features onto our JSON support we would much | ||
| rather look at this from a broader perspective of getting data in and out of | ||
| Realm through a more generalized Import/Export API. Such a API should be flexible |
There was a problem hiding this comment.
Such a API -> Such an API?
|
|
||
| ## Use cases - Already supported | ||
|
|
||
| Realm already have `copyToRealm()/copyFromRealm()` methods that uses in-memory |
There was a problem hiding this comment.
Realm already have -> Realm already has?
that uses -> that use?
| - Move towards a opt-in plugin-type architecture. | ||
|
|
||
| **Disadvantages** | ||
| - Methods will crash if no plugin is installed. |
There was a problem hiding this comment.
This disadvantage is really really minor ... I wouldn't say it is a disadvantage, it is just a bug needs to be fixed when it happens.
| ## Open questions: | ||
|
|
||
| * Can we enumerate possible input formats (XML, JSON, CSV), or does it need to | ||
| be flexible? |
There was a problem hiding this comment.
I would like make it flexible
| be flexible? | ||
|
|
||
| * A more radical solution could also be to just remove our JSON support | ||
| completely and completely delegate it to 3rd party libraries? |
There was a problem hiding this comment.
The converter has to call APIs in io.realm.internal for speed concerns. I am not quite sure we have all the checks for every internal API (but ideally we should have all checks inside the internal APIs)
|
I like @Zhuinden idea of a retrofit-esque solution. Define an interface in realm for importing data, create a library with implementations using popular 3rd party libraries (gson, Moshi, something for XML, etc...), and let the user pass an instance of that implementation to the import method. |
Spinoff from #1470
This RFC tries to describe two possible approaches to the problem, but perhaps I am missing something even better.
What do you think @realm/java @TR4Android