Skip to content

Commit 8c86eaa

Browse files
committed
[Docs] fix changes
1 parent bd59874 commit 8c86eaa

File tree

2 files changed

+43
-21
lines changed

2 files changed

+43
-21
lines changed

usage2/rxjavasupport.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# RXJavaSupport
22

3-
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.
3+
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.
44

5-
Currently it supports
5+
Currently it supports
66

7-
1. Any `ModelQueriable` can be wrapped in a `Single`, `Maybe`, or `Flowable` \(to continuously observe changes\).
7+
1. Any `ModelQueriable` can be wrapped in a `Single`, `Maybe`, or `Flowable` \(to continuously observe changes\).
88

9-
2. Single + `List` model `save()`, `insert()`, `update()`, and `delete()`.
9+
2. Single + `List` model `save()`, `insert()`, `update()`, and `delete()`.
1010

11-
3. Streaming a set of results from a query
11+
3. Streaming a set of results from a query
1212

1313
4. Observing on table changes for specific `ModelQueriable` and providing ability to query from that set repeatedly as needed.
1414

usage2/usage/databases.md

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ val db = FlowManager.getDatabase(AppDatabase::class.java)
3434
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`:
3535

3636
```kotlin
37-
FlowManager.init(FlowConfig.builder()
38-
.database(DatabaseConfig.builder(AppDatabase::class)
39-
.databaseName("AppDatabase")
40-
.build())
41-
.build())
37+
FlowManager.init(context) {
38+
database<AppDatabase> {
39+
databaseName("AppDatabase")
40+
}
41+
}
4242
```
4343

4444
To dynamically change the database name, call:
@@ -47,7 +47,7 @@ To dynamically change the database name, call:
4747
database<AppDatabase>()
4848
.reopen(DatabaseConfig.builder(AppDatabase::class)
4949
.databaseName("AppDatabase-2")
50-
.build())]
50+
.build())
5151
```
5252

5353
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
5757
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:
5858

5959
```kotlin
60-
FlowManager.init(FlowConfig.builder()
61-
.database(DatabaseConfig.inMemoryBuilder(AppDatabase::class.java)
62-
.databaseName("AppDatabase")
63-
.build())
64-
.build())
60+
FlowManager.init(context) {
61+
inMemoryDatabase<AppDatabase> {
62+
databaseName("AppDatabase")
63+
}
64+
}
6565
```
6666

6767
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
122122
Then in your `DatabaseConfig`:
123123

124124
```kotlin
125-
FlowManager.init(FlowConfig.builder(context)
126-
.database(DatabaseConfig.Builder(CipherDatabase::class.java)
127-
.openHelper(::CustomFlowSQliteOpenHelper)
128-
.build())
129-
.build())
125+
FlowManager.init(context) {
126+
database<CipherDatabase> {
127+
openHelper(::CustomFlowSQliteOpenHelper)
128+
}
129+
}
130+
```
131+
132+
### Database Configuration DSL
133+
134+
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.
135+
136+
**Initializing DBFlow:**
137+
138+
```kotlin
139+
FlowManager.init(context) {
140+
// this is FlowConfig.Builder
141+
database<AppDatabase> {
142+
// this is DatabaseConfig.Builder
143+
table<MyTable> {
144+
// this is TableConfig.Builder
145+
}
146+
}
147+
// other module dbs
148+
databaseHolder<MyGeneratedDatabaseHolder>()
149+
}
130150
```
131151

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

0 commit comments

Comments
 (0)