So i made a decision to fool around with SQLBrite throughout the bogus Tinder app

Try not to completing the fresh app as time passes along with got the professionals: A short time immediately after Romantic days celebration the inventors over at square (whom otherwise?) open acquired SQLBrite and this appears to be the fresh database layer We have always been thinking of: It’s a portable wrapper as much as SQLiteOpenHelper and you will ContentResolver, it does not cover up SQLite or SQL API, aids deals and multithreading and finally it raises reactive load semantics to help you issues. Specifically, the second you’re worthy of bringing up: And if a row of a sql databases table gets current, registered or removed SQLBrite trigger a notification to share with issues, which happen to be subscribed getting dining table dataset alter.

Contained in this fake Tinder app you could unlock ChatActivity hence screens an inventory queried on local SQLite database. Once the stated previously in advance of I personally use GCM to send and you may discovered cam messages. After app get a good GCM Force notice which includes a speak content, the newest application places the latest ChatMessage to your regional database. The big advantage of having fun with SQLBrite would be the fact by the staying a good the newest ChatMessage on regional databases ChatActivity gets up-to-date immediately as the for as long as ChatActivity isn’t shed the first query done within the ChatActivity.onCreate() so you’re able to recover Number remains registered (inquire is actually Rx Customer) into the root databases dining table (database table is actually Rx Observable). But the awesome topic is that you have that inform method at no cost. You don’t need to incorporate just one type of password. SQLBrite and you will RxJava “magically” do this. Zero EventBus to begin with a lso are-query manually, absolute reactive coding electricity. Very as soon as the software get an excellent GCM push notice that features good ChatMessage they stores that it ChatMessage with the local SQLite databases. In the event that ChatActivity was unlock if you find yourself researching the brand new GCM force alerts SQLBrite usually immediately deliver the database change to ChatActivity. It’s so easy to store ChatActivity cutting edge. Which Activity you should never have a tow-to-rejuvenate device for example a great SwipeRefreshLayout since reputation try pressed out-of SQLBrite immediately. Ergo, there’s absolutely no need to apply a tow process.

SQLBrite Dao

SQLBrite is still for the it’s beginning (Version 0.step 1.0 when you find yourself composing this blog blog post). While the currently said the main focus away from SQLBrite is determined into providing a beneficial wrapper arround SQLite. No ORM with no particular-secure inquire method are supplied. So that with SQLBrite you have got to focus on Cursor and you will ContentValues. Which had been a bit annoying when you’re developing this new phony Tinder app. Ergo, I decided to build an annotation processor chip to possess “simple” target mapping and DAO (Study Accessibility Object) near the top of SQLBrite. SQLBrite Dao exists towards the Github.

Object mapping

Please be aware this particular is not an enthusiastic ORM. The single thing it does is actually get a beneficial Cursor and study the newest column into design classification pojo. Simply primitives are permitted, zero affairs such as for example 1:letter (1 Chat has some ChatMessages) can’t be modeled and you can fixed. It is more like deserializing analysis than just target mapping. You must annotate their design group that have as well as the need sphere which have to the table column term (String) since the parameter:

An annotation processor chip (perhaps not reflections) after that stimulates ChatMessageMapper category. You to definitely produced group (totally new annotated class label + “Mapper” suffix) turns out it:

Since you select a beneficial Func1 MAPPER would be generated. You will see ina moment just how which MAPPER is employed to help make ChatMessage** times of a **Cursor**. You really have and additionally pointed out that there is a good **ContentValuesBuilder** which can be used because the sorts of-safer creator for **ContentValues** similar to this:

Build your very own Research Access Target (DAO) for which you identify solutions to affect or ask their databases table. Dao brings SQL grammar you don’t have to offer that much having Sequence concatenation and will explore IDE’s auto conclusion to make your sql statements. Always a great DAO represents a database desk since ferzu following: