So i decided to play with SQLBrite regarding the phony Tinder app

Never doing the latest application over the years along with had its pros: A short time immediately after Valentine’s the inventors over at rectangular (exactly who else?) discover acquired SQLBrite and therefore is apparently the new databases covering I are thinking regarding: It’s a lightweight wrapper up to SQLiteOpenHelper and you may ContentResolver, it does not mask SQLite or SQL API, supporting transactions and you may multithreading and you will last but not least it raises reactive load semantics in order to questions. Specifically, the latter a person is worth mentioning: Just in case a-row out of a sql database dining table will get updated, registered or removed SQLBrite causes an alerts to share with requests, which are signed up to possess dining table dataset changes.

Within this fake Tinder software you can unlock ChatActivity and that displays a listing queried on local SQLite databases. Once the already mentioned prior to I prefer GCM to send and you can found talk messages. If the application obtains good GCM Force notice which includes a speak message, the brand new software places the new ChatMessage on the local databases. The major advantageous asset of playing with SQLBrite is that by the inserting a brand new ChatMessage on regional database ChatActivity will get updated instantly since the provided ChatActivity is not lost the initial query executed in the ChatActivity.onCreate() to recover Checklist is still signed up (inquire is Rx Customer) on hidden database table (database desk are Rx Observable). However the great procedure is you have that improve apparatus at no cost. It’s not necessary to add one collection of code. SQLBrite and RxJava “magically” accomplish that. Zero EventBus first off a lso are-query manually, absolute activated programming energy. So as soon as the software gets a great GCM push notification who has a beneficial ChatMessage it places so it ChatMessage with the local SQLite database. In the event the ChatActivity try unlock when you’re getting new GCM push notice SQLBrite tend to immediately deliver the databases change so you can ChatActivity. It’s that easy to keep ChatActivity state of the art. This Craft try not to need a tow-to-rejuvenate apparatus such a beneficial SwipeRefreshLayout as the status is actually pressed out of SQLBrite automatically. For this reason, there’s no reasoning to apply a tow system.

SQLBrite Dao

SQLBrite is still during the it is start (Variation 0.step 1.0 whenever you are creating this web site blog post). Because currently told you the main focus out of SQLBrite is decided into the getting a beneficial wrapper arround SQLite. No ORM and no particular-secure ask process are supplied. So by using SQLBrite you have got to work with Cursor and you can ContentValues. That has been a little bit annoying while development the fresh phony Tinder software. Hence, I thought i’d make an enthusiastic annotation chip having “easy” object mapping and you can DAO (Research Access Object) near the top of SQLBrite. SQLBrite Dao is obtainable towards the Github.

Object mapping

Please be aware this particular isn’t a keen ORM. The only thing it can is need good Cursor and study the line on model classification pojo. Just primitives are allowed, no affairs including 1:n (step one Talk has some ChatMessages) can not be modeled and resolved. It’s a lot more like deserializing analysis than object mapping. You have got to annotate your design category having therefore the wanted industries with on milfaholic website reviews desk line label (String) because the factor:

An enthusiastic annotation chip (maybe not reflections) following builds ChatMessageMapper classification. One to made class (fresh annotated group identity + “Mapper” suffix) looks like so it:

Since you discover a great Func1 MAPPER might be produced. You will observe in a few minutes how this MAPPER can be used which will make ChatMessage** era away from an excellent **Cursor**. You may have also pointed out that there can be a great **ContentValuesBuilder** which can be used since the variety of-safer builder for **ContentValues** in this way:

Help make your individual Research Availableness Target (DAO) where you determine ways to shape otherwise ask your database desk. Dao provides SQL grammar you don’t need to package you to far that have Sequence concatenation and can use IDE’s car conclusion so you can make your sql comments. Usually a beneficial DAO represents a databases dining table since the following the: