From 8c86eaa78f052be9d1990f637c8f50da287f7095 Mon Sep 17 00:00:00 2001 From: Andrew Grosner Date: Sat, 13 Mar 2021 10:16:28 -0500 Subject: [PATCH] [Docs] fix changes --- usage2/rxjavasupport.md | 10 ++++---- usage2/usage/databases.md | 54 +++++++++++++++++++++++++++------------ 2 files changed, 43 insertions(+), 21 deletions(-) diff --git a/usage2/rxjavasupport.md b/usage2/rxjavasupport.md index cabe060aa..e4b9b6bd6 100644 --- a/usage2/rxjavasupport.md +++ b/usage2/rxjavasupport.md @@ -1,14 +1,14 @@ # RXJavaSupport -RXJava support in DBFlow is an _incubating_ feature and likely to change over time. We support RXJava3 only and have made the extensions + DBFlow compatibility almost identical - save for the changes and where it makes sense in each version. +RXJava support in DBFlow is an _incubating_ feature and likely to change over time. We support both RX1 and RX2 and have made the extensions + DBFlow compatibility almost identical - save for the changes and where it makes sense in each version. -Currently it supports +Currently it supports -1. Any `ModelQueriable` can be wrapped in a `Single`, `Maybe`, or `Flowable` \(to continuously observe changes\). +1. Any `ModelQueriable` can be wrapped in a `Single`, `Maybe`, or `Flowable` \(to continuously observe changes\). -2. Single + `List` model `save()`, `insert()`, `update()`, and `delete()`. +2. Single + `List` model `save()`, `insert()`, `update()`, and `delete()`. -3. Streaming a set of results from a query +3. Streaming a set of results from a query 4. Observing on table changes for specific `ModelQueriable` and providing ability to query from that set repeatedly as needed. diff --git a/usage2/usage/databases.md b/usage2/usage/databases.md index a6eaaa351..c37e927a0 100644 --- a/usage2/usage/databases.md +++ b/usage2/usage/databases.md @@ -34,11 +34,11 @@ val db = FlowManager.getDatabase(AppDatabase::class.java) To specify a custom **name** to the database, in previous versions of DBFlow \(< 4.1.0\), you had to specify it in the `@Database` annotation. As of 5.0 now you pass it in the initialization of the `FlowManager`: ```kotlin -FlowManager.init(FlowConfig.builder() - .database(DatabaseConfig.builder(AppDatabase::class) - .databaseName("AppDatabase") - .build()) - .build()) +FlowManager.init(context) { + database { + databaseName("AppDatabase") + } + } ``` To dynamically change the database name, call: @@ -47,7 +47,7 @@ To dynamically change the database name, call: database() .reopen(DatabaseConfig.builder(AppDatabase::class) .databaseName("AppDatabase-2") - .build())] + .build()) ``` This will close the open DB, reopen the DB, and replace previous `DatabaseConfig` with this new one. Ensure that you persist the changes to the `DatabaseConfig` somewhere as next time app is launched and DBFlow is initialized, the new config would get overwritten. @@ -57,11 +57,11 @@ This will close the open DB, reopen the DB, and replace previous `DatabaseConfig As with **name**, in previous versions of DBFlow \(< 5.0\), you specified `inMemory` in the `@Database` annotation. Starting with 5.0 that is replaced with: ```kotlin -FlowManager.init(FlowConfig.builder() - .database(DatabaseConfig.inMemoryBuilder(AppDatabase::class.java) - .databaseName("AppDatabase") - .build()) - .build()) +FlowManager.init(context) { + inMemoryDatabase { + databaseName("AppDatabase") + } +} ``` This will allow you to use in-memory databases in your tests, while writing to disk in your apps. Also if your device the app is running on is low on memory, you could also swap the DB into memory by calling `reopen(DatabaseConfig)` as explained above. @@ -122,10 +122,32 @@ class CustomFlowSQliteOpenHelper(context: Contect, databaseDefinition: DatabaseD Then in your `DatabaseConfig`: ```kotlin -FlowManager.init(FlowConfig.builder(context) - .database(DatabaseConfig.Builder(CipherDatabase::class.java) - .openHelper(::CustomFlowSQliteOpenHelper) - .build()) - .build()) +FlowManager.init(context) { + database { + openHelper(::CustomFlowSQliteOpenHelper) + } +} +``` + +### Database Configuration DSL + +As of 5.0.0-alpha2, you can configure a database via a DSL rather than use the `FlowConfig.Builder` , `DatabaseConfig.Builder`, and `TableConfig.Builder`. This allows more readable, expressive syntax. + +**Initializing DBFlow:** + +```kotlin +FlowManager.init(context) { + // this is FlowConfig.Builder + database { + // this is DatabaseConfig.Builder + table { + // this is TableConfig.Builder + } + } + // other module dbs + databaseHolder() +} ``` +By utilizing Kotlin DSL, this code is more straightforward, concise, and readable. +