You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 17, 2020. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 17, 2020. It is now read-only.
Any way to reload the database and make all observables to re-query? #39
In my app I have a import/export functionality, by importing, the SQLite database file is replaced by one on the sdcard, so I need to reload the SQLiteOpenHelper and then notify all the Queries.
Something like the following method would be really handy!
publicvoidreloadDatabase(SQLiteOpenHelperhelper, Set<String> tables){
// Replace the SQLiteOpenHelpersynchronized (databaseLock) {
readableDatabase = null;
writeableDatabase = null;
this.helper.close();
this.helper = helper;
}
// Make all Queries to reloadsendTableTrigger(tables);
}
Or prehaps BriteDatabase can save a Set of tables, filled as we query them, to be notified on a potential database reload?
I guess I could make the user restart the app, but I rather not.
SQLBrite is amazing as it is very simple and allow us to get rid of loaders, and IMO notifying on tables is far better than the Uri system, thanks for creating SQLBrite!
Re-query only
Let's say my app is a calendar, I have an upcoming event list, starting by today's events.
In every event list I want to mark each yesterday's event as missed.
Then I need to reload event's Queries every day at 00:00.
In this particular case it would make sense to make the sendTableTrigger()public and call it every day.
I could also use a Observable.combineLatest with a Query and a PublishSubject and call this Subject every day to run the Query again, but since table triggers are managed the same way, it seems simple to switch sendTableTrigger() to public.
To support this idea; ContentResolver's notifyChange(Uri uri, null) is public.
As to the re-query case, you can run a query more than once so you can use something like combineLatest with another stream that emits a new dummy value every day at midnight.
In this instance midnightObservable could be a PublishSubject that sent out an item when an AlarmManager fires.
I'm not super sure about how widespread the use of reloading helpers is. One solution would just be to replace your BriteDatabase with an Observable<BriteDatabase> and switchMap to create the query observable.
Another idea is to provide an Observable<SQLiteOpenHelper> instead of the single SQLiteOpenHelper reference in SqlBrite.wrapDatabaseHelper, and put the switchMap logic inside BriteDatabase to avoid using it externally.
And SqlBrite.wrapDatabaseHelper(Observable<helper>) could even coexist with the original SqlBrite.wrapDatabaseHelper(helper).
About the re-query, I keep thinking making sendTableTriggerpublic is better than rewriting a PublishSubject to trigger a reload, but anyway you're the boss.
If you feel the issue is closed, then it's closed for me too.
Thank you!
It's actually not that easy to accept an Observable<SQLiteOpenHelper> in SqlBrite because of the synchronous APIs that it offers. I'll have to think about it more to see if there's anything we can do.
Activity
xMikeTx commentedon Aug 17, 2015
I needed the same thing, so I just exposed the triggers.
Would be great if this would be integrated in the main branch.
But I am not sure, whether this is is the smartest solution.
xMikeTx@baffb9c
JakeWharton commentedon Aug 21, 2015
As to the re-query case, you can run a query more than once so you can use something like
combineLatestwith another stream that emits a new dummy value every day at midnight.In this instance
midnightObservablecould be aPublishSubjectthat sent out an item when anAlarmManagerfires.I'm not super sure about how widespread the use of reloading helpers is. One solution would just be to replace your
BriteDatabasewith anObservable<BriteDatabase>andswitchMapto create the query observable.2buisson commentedon Aug 22, 2015
By using
Observable<BriteDatabase>instead of aBriteDatabaseI ended up duplicatingcreateQuery:Which is a fine solution, thank you.
Another idea is to provide an
Observable<SQLiteOpenHelper>instead of the singleSQLiteOpenHelperreference inSqlBrite.wrapDatabaseHelper, and put theswitchMaplogic insideBriteDatabaseto avoid using it externally.And
SqlBrite.wrapDatabaseHelper(Observable<helper>)could even coexist with the originalSqlBrite.wrapDatabaseHelper(helper).About the re-query, I keep thinking making
sendTableTriggerpublicis better than rewriting aPublishSubjectto trigger a reload, but anyway you're the boss.If you feel the issue is closed, then it's closed for me too.
Thank you!
JakeWharton commentedon Aug 23, 2015
It's actually not that easy to accept an
Observable<SQLiteOpenHelper>in SqlBrite because of the synchronous APIs that it offers. I'll have to think about it more to see if there's anything we can do.