Generic interface for Marshal/Factory like RowMapper
See original GitHub issueIt is convenient to have RowMapper<T>
, because it lets you create generic code that reads from a database (e.g. a helper function that reads all rows into a List<T>
, a GUI to display things, etc.).
It would be great to have the same generic interface for the “write” direction, i.e. for the Marshal and/or the Factory.
It could look something like this:
interface MarshalInterface<T> {
ContentValues asContentValues();
}
interface FactoryInterface<T> {
MarshalInterface<T> marshal();
MarshalInterface<T> marshal(T copy);
RowMapper<T> select_allMapper();
}
and would be usable like this:
class Inserter<T> {
SQLiteOpenHelper openHelper;
FactoryInterface<T> factory;
String tableName;
public void insert(T item) {
db.insert(tableName, null, factory.marshal(item).asContentValues();
}
}
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:6
Top Results From Across the Web
Generic interface for Marshal/Factory like RowMapper #505
It is convenient to have RowMapper , because it lets you create generic code that reads from a database (e.g. a helper function...
Read more >Implementing interface with generic type - java - Stack Overflow
If a row maps to a User, then it should be a RowMapper<User>. ie: public class UserMapper implements RowMapper<User> { public User ...
Read more >Implementing RowMapper in Spring with Example
Spring provides a RowMapper interface for mapping a single row of a ResultSet to an object. It can be used for both single...
Read more >Spring RowMapper Example - Javatpoint
RowMapper interface allows to map a row of the relations with the instance of user-defined class. It iterates the ResultSet internally and adds...
Read more >Spring - RowMapper Interface with Example - GeeksforGeeks
This framework uses various new techniques such as Aspect-Oriented Programming (AOP), Plain Old Java Object (POJO), and dependency injection (DI) ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
+1 on these. Can I help implement that?
Related/duplicate: https://github.com/square/sqldelight/issues/572
We use content providers for all our DB operations. We use the SQLDelight created models on top of the cursors in the UX code. We would also like to use this for persisting the data into the Content Provider.
To do that we will need to get the content values. If this is exposed then it will be helpful for the application code to work with content providers as well instead of working directly with the DB (multiple rows to be inserted/updated along with transaction support).