Don’t finishing brand new application with time plus had their experts: A short time immediately following Valentine’s the inventors over at rectangular (who more?) unlock acquired SQLBrite which seems to be the newest database layer I was dreaming regarding: It’s a portable wrapper to SQLiteOpenHelper and you will ContentResolver, it generally does not cover up SQLite otherwise SQL API, supporting purchases and multithreading and you may ultimately they raises reactive weight semantics so you can question. Particularly, aforementioned a person is value mentioning: Assuming a-row away from good sql databases table will get updated, registered or eliminated SQLBrite trigger a notice to inform requests, being subscribed for dining table dataset transform.
Contained in this fake Tinder software you might discover ChatActivity which displays a list queried about local SQLite databases. Just like the mentioned previously ahead of I prefer GCM to deliver and you will receive cam texts. Whenever application get an excellent GCM Push alerts who has a chat message, the fresh software areas the new ChatMessage into local database. The top benefit of using SQLBrite would be the fact from the staying a great the ChatMessage toward local database ChatActivity will get current immediately because for as long as ChatActivity isn’t destroyed the first ask executed in ChatActivity.onCreate() in order to access Checklist remains subscribed (inquire is Rx Subscriber) on root database dining table (database dining table are Rx Observable). However the great topic is that you have that enhance device free of charge. You don’t need to create an individual collection of code. SQLBrite and you can RxJava “magically” do that. Zero EventBus to begin with a re also-query yourself, sheer reactive programming fuel. Very as soon as the application get an effective GCM push alerts that features good ChatMessage it locations that it ChatMessage into filipinocupid login local SQLite databases. If the ChatActivity try discover if you’re choosing brand new GCM push notification SQLBrite often instantly supply the databases transform to ChatActivity. It’s so easy to store ChatActivity up to date. It Craft do not even have a tow-to-refresh device particularly a good SwipeRefreshLayout because condition was pushed out of SQLBrite instantly. Therefore, there’s absolutely no cause to implement a tow system.
SQLBrite Dao
SQLBrite has been when you look at the it’s early days (Adaptation 0.1.0 if you find yourself writing this web site article). Given that already told you the focus out-of SQLBrite is set to the bringing an excellent wrapper arround SQLite. Zero ORM without method of-safe query system are supplied. Very that with SQLBrite you have got to work at Cursor and you may ContentValues. That was somewhat annoying while you are developing the fresh phony Tinder app. Thus, I thought i’d produce an annotation processor chip to own “very easy” target mapping and you may DAO (Studies Accessibility Target) at the top of SQLBrite. SQLBrite Dao is present towards Github.
Object mapping
Take note that the is not a keen ORM. The one and only thing it does try simply take a good Cursor and study the fresh column with the design category pojo. Simply primitives are allowed, zero connections for example step one:n (step one Speak has some ChatMessages) can not be modeled and resolved. It’s a lot more like deserializing analysis than simply object mapping. You have got to annotate your own model class with plus the desired industries which have with the dining table column title (String) because factor:
An enthusiastic annotation processor chip (perhaps not reflections) then produces ChatMessageMapper class. That generated class (totally new annotated classification label + “Mapper” suffix) turns out that it:
Because you get a hold of an excellent Func1 MAPPER could well be produced. You will observe in a minute exactly how that it MAPPER can be used to help make ChatMessage** instances away from a great **Cursor**. You have got together with noticed that discover a good **ContentValuesBuilder** that can be used once the variety of-safer builder to possess **ContentValues** like this:
Build your individual Data Availableness Object (DAO) for which you determine approaches to influence otherwise inquire your own database dining table. Dao will bring SQL sentence structure and that means you don’t need to price one much with String concatenation and certainly will explore IDE’s vehicles conclusion so you’re able to make your sql statements. Constantly a great DAO is short for a databases table once the following the: