-
Notifications
You must be signed in to change notification settings - Fork 422
Support object mapping of query result rows #1
Comments
how about something like this - @Mapper
public interface Mapper {
@Column.Mapper(0) long getId(Cursor c);
@Column.Mapper(1) String getText(Cursor c);
@Column.Mapper(2) Date getWhen(Cursor c);
} one good thing about this is it works even for joins (since it's just a numeric position) - the unfortunate piece is that working with column numbers is problematic. unfortunately, the alternative of this is also not great and is problematic due to the bug about not being able to use @Mapper
public interface Mapper {
@Column.Mapper("notes._id") long getId(Cursor c);
@Column.Mapper("notes.text") String getText(Cursor c);
@Column.Mapper("todos.whence") Date getWhen(Cursor c);
} thoughts? |
In my opinion, It would be best if we could come up with a solution where the model can define the table structure, builders and mappings (preferably most of the boiler plating done by an annotation processor). As a user(developer), I don't want to have to define a ton of interfaces, builders, abstract classes just to get some models out of the database. This is one of my concerns I have as I watch this library mature through its infancy. |
I agree with Kevin that we want to reduce boilerplate as much as possible, #16 is actually a great start on that. One thing we have to keep in mind is that we need something that works for every type of |
Would it be possible to add an optional parameter like the following to the create method and call it later in the Query.run method? /** Convert the query Cursor to the user model */
public interface CursorModel<T>{
T convertToModel(Cursor c);
} This would not reduce the boilerplate but just move the cursor mapping out of the observable flow/subscribe methods implementation. |
@ahmedre that's just perfect, now we need to generate those Mappers from SQL strings, and look for type hints: initial creation script + all the migrations or assist the IDE plugin by hand the second option is at least achieveable |
@ahmedre and what's the bug with |
@adelnizamutdinov |
A few months ago I put together https://github.com/madebyatomicrobot/vinyl to start to address some accumulated internal project pains with Cursors and mapping rows into objects. Not sure if something like that is what you would like to see in SQLBrite. |
There is also sqlbrite dao |
Our solution to this is https://github.com/square/sqldelight and efforts around object mapping will be focused there. |
Nobody wants to work with a
Query
andCursor
. Add support for mapping rows to objects. This should support both table-based and custom view-based objects.The text was updated successfully, but these errors were encountered: