Support custom type Mapper
Opened this issue · 2 comments
I think it would be really cool to have custom type mapper that are used during the annotation processing (for enum, etc ...)
Maybe add an annotation @Mapper
on top of a class that inherit from an interface Mapper<T, R>
where T
is the database type and R
is our custom type.
We could go even further if T
could be any of the basic handled types or a custom mapped type.
With this we could define a Mapper<String, BigNumber>
and a Mapper<BigNumber, SpecialNumber>
that would allow to directly map from String
to SpecialNumber
.
In case of multiple Mapper defined for the same type, we could throw an Ambiguous exception at compile time (yay Scala implicit system).
Hi, yes I have already thought about something like that.
Actually I have implemented such a "plugin mechanism" for other annotation processing based libraries of mine like FragmentArgs (see ArgsBundler section).It's not to hard to implement something like that. However, I'm not entirely sure if this makes sense in combination with SqlBrite, since you can specify RxJava Func1
to do the mapping.
So rather then writing a Mapper<String, BigNumber>
and integrate the Mapper
via annotation processing somehow, you can write directly a Func1<String, BigNumber>
and use that one directly.
Hey @sockeqwe
I will take a look at your library and how you did that this week-end =). I am not familiar with annotation processing in Android.
I did not give the whole definition of Mapper in my comment.
Of course I would keep RxJava Func1
, but a Mapper<T, R>
would be and interface for the Reader / Writer Func1
like so :
interface Mapper<T, R> {
Func1<T, R> reader();
Func1<R, T> writer();
}
It would also allow using Typed ContentValues
with Custom type. (Without mapping to Database type every time). Or maybe you have a suggestion for this one ?