SQLiteDatabase和ContentResolver的漂亮API:storio
StorIO — modern API for SQLiteDatabase and ContentResolver
Overview:
- Powerful & Simple set of Operations:Put,Get,Delete
- API for Humans: Type Safety, Immutability & Thread-Safety
- Convenient builders with compile-time guarantees for required params. Forget about 6-7nullin queries
- Optional Type-Safe Object Mapping, if you don't want to work withCursorandContentValuesyou don't have to
- No reflection in Operations and no annotations in the core, alsoStorIOis not ORM
- Every Operation overStorIOcan be executed as blocking call or asrx.Observable
- RxJavaas first class citizen, but it's not required dependency!
- Reactive:rx.ObservablefromGetOperation can observe changes inStorIOand receive updates automatically
- StorIOis replacements forSQLiteDatabaseandContentResolverAPIs
- StorIO+RxJavais replacement forLoadersAPI
- We are working onMockStorIO(similar to MockWebServer) for easy unit testing </ul>
- Open Source -> less bugs
- Documentation, Sample app and Design tests -> less bugs
- StorIOhas unit and integration tests -> less bugs
- Simple concept of just three main Operations:Put,Get,Delete-> less bugs
- Almost everything is immutable and thread-safe -> less bugs
- Builders for everything make code much, much more readable and obvious -> less bugs
- Less bugs -> less bugs </ul>
Why StorIO?
Some examples
Get list of objects from SQLiteDatabase
List<Tweet> tweets = storIOSQLite .get() .listOfObjects(Tweet.class) // Type safety .withQuery(Query.builder() // Query builder .table("tweets") .where("author = ?") .whereArgs("artem_zin") // Varargs Object..., no more new String[] {"I", "am", "tired", "of", "this", "shit"} .build()) // Query is immutable — you can save it and share without worries .prepare() // Operation builder .executeAsBlocking(); // Control flow is readable from top to bottom, just like with RxJava
Put something to SQLiteDatabase
storIOSQLite .put() // Insert or Update .objects(someTweets) // Type mapping! .prepare() .executeAsBlocking();
Delete something from SQLiteDatabase
storIOSQLite .delete() .byQuery(DeleteQuery.builder() .table("tweets") .where("timestamp <= ?") .whereArgs(System.currentTimeMillis() - 86400) // No need to write String.valueOf() .build()) .prepare() .executeAsBlocking();
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!