Skip to content

Instantly share code, notes, and snippets.

@sourabhv
Last active May 26, 2017 05:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sourabhv/afb90845d7494f3c3f8678a4c2e95116 to your computer and use it in GitHub Desktop.
Save sourabhv/afb90845d7494f3c3f8678a4c2e95116 to your computer and use it in GitHub Desktop.
Repository Design Pattern in Android using RxJava, Retrofit, SQLBrite and SQLDelight Raw
SqlBrite sqlBrite = new SqlBrite.Builder().build();
BriteDatabase database = sqlBrite.wrapDatabaseHelper(openHelper, Schedulers.io());
// Insert transaction
Transaction transaction = database.newTransaction();
Address.InsertRow insertRow = new Address.InsertRow(database.getWritableDatabase());
try {
insertRow.bind(1, "Home", "House No. 42", "Foo Lane", null, "Gurgaon", "India", 123456);
database.executeInsert(Address.TABLE_NAME, insertRow.program);
insertRow.bind(1, "Office", "A-83", null, "DTDC", "Okhla", "India", 123654);
database.executeInsert(Address.TABLE_NAME, insertRow.program);
transaction.markSuccessful();
} finally {
transaction.end();
}
// Query operation
Observable<List<Address>> addressesObservable = database
.createQuery(Address.TABLE_NAME, Address.FACTORY.selectAll().statement)
.mapToList(Address.MAPPER);
.subscribe(addresses -> {
// Your code here
}, throwable -> {
// report error here
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment