Skip to content

Commit

Permalink
GitBook: [develop] 30 pages modified
Browse files Browse the repository at this point in the history
  • Loading branch information
agrosner authored and gitbook-bot committed Feb 17, 2021
1 parent 52b75d2 commit e6690f3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
Binary file modified usage2/5.0-migration-guide.md
Binary file not shown.
6 changes: 3 additions & 3 deletions usage2/advanced-usage/multiplemodules.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ From previous sample code, we recommend initializing the specific module inside

```kotlin
fun initialize(context: Context) {
FlowManager.init(FlowConfig.builder(context)
.addDatabaseHolder(SomeUniqueModuleNameGeneratedDatabaseHolder::class)
.build())
FlowManager.init(context) {
databaseHolder<SomeUniqueModuleNameGeneratedDatabaseHolder>()
}
}
```

52 changes: 37 additions & 15 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 \(&lt; 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 @@ -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 e6690f3

Please sign in to comment.