question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Generic interface for Marshal/Factory like RowMapper

See original GitHub issue

It 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:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

1reaction
Philipp91commented, Apr 12, 2017

a .bind(@NonNull FooModel object) could be generated which would use the getter methods of the interface to fill in the insert or update call

INSERT INTO users VALUES ?;

+1 on these. Can I help implement that?

Related/duplicate: https://github.com/square/sqldelight/issues/572

1reaction
yasirmhdcommented, Dec 5, 2016

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).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found