Skip to content

Commit

Permalink
[Docs] fix changes
Browse files Browse the repository at this point in the history
  • Loading branch information
agrosner committed Mar 13, 2021
1 parent bd59874 commit 8c86eaa
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 21 deletions.
10 changes: 5 additions & 5 deletions usage2/rxjavasupport.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
54 changes: 38 additions & 16 deletions usage2/usage/databases.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<AppDatabase> {
databaseName("AppDatabase")
}
}
```

To dynamically change the database name, call:
Expand All @@ -47,7 +47,7 @@ To dynamically change the database name, call:
database<AppDatabase>()
.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.
Expand All @@ -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 \(&lt; 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<AppDatabase> {
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.
Expand Down Expand Up @@ -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<CipherDatabase> {
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<AppDatabase> {
// this is DatabaseConfig.Builder
table<MyTable> {
// this is TableConfig.Builder
}
}
// other module dbs
databaseHolder<MyGeneratedDatabaseHolder>()
}
```

By utilizing Kotlin DSL, this code is more straightforward, concise, and readable.

0 comments on commit 8c86eaa

Please sign in to comment.