# RoomDatabase.Builder

Artifact: [androidx.room:room-runtime](https://developer.android.com/jetpack/androidx/releases/room) [View Source](https://cs.android.com/search?q=file:androidx/room/RoomDatabase.+class:androidx.room.RoomDatabase.Builder) Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0)

*** ** * ** ***


```
public final class RoomDatabase.Builder<T extends RoomDatabase>
```

<br />

*** ** * ** ***

Builder for `https://developer.android.com/reference/androidx/room/RoomDatabase`.

| Parameters |
|---|---|
| `<T extends https://developer.android.com/reference/androidx/room/RoomDatabase>` | The type of the abstract database class. |

## Summary

| ### Public methods |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#addAutoMigrationSpec(androidx.room.migration.AutoMigrationSpec)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/migration/AutoMigrationSpec autoMigrationSpec)` Adds an auto migration spec instance to the builder. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#addCallback(androidx.room.RoomDatabase.Callback)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Callback callback)` Adds a `https://developer.android.com/reference/androidx/room/RoomDatabase.Callback` to this database. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#addMigrations(kotlin.Array)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/migration/Migration... migrations)` Adds a migration to the builder. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#addTypeConverter(kotlin.Any)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Object.html typeConverter)` Adds a type converter instance to the builder. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#allowMainThreadQueries()()` Disables the main thread query check for Room. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull T` | `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#build()()` Creates the database and initializes it. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#createFromAsset(kotlin.String)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html databaseFilePath)` Configures Room to create and open the database using a pre-packaged database located in the application 'assets/' folder. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#createFromAsset(kotlin.String,androidx.room.RoomDatabase.PrepackagedDatabaseCallback)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html databaseFilePath, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.PrepackagedDatabaseCallback callback )` Configures Room to create and open the database using a pre-packaged database located in the application 'assets/' folder. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#createFromFile(java.io.File)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/io/File.html databaseFile)` Configures Room to create and open the database using a pre-packaged database file. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#createFromFile(java.io.File,androidx.room.RoomDatabase.PrepackagedDatabaseCallback)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/io/File.html databaseFile, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.PrepackagedDatabaseCallback callback )` Configures Room to create and open the database using a pre-packaged database file. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#createFromInputStream(java.util.concurrent.Callable)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Callable.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/io/InputStream.html> inputStreamCallable )` Configures Room to create and open the database using a pre-packaged database via an `https://developer.android.com/reference/java/io/InputStream.html`. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#createFromInputStream(java.util.concurrent.Callable,androidx.room.RoomDatabase.PrepackagedDatabaseCallback)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Callable.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/io/InputStream.html> inputStreamCallable, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.PrepackagedDatabaseCallback callback )` Configures Room to create and open the database using a pre-packaged database via an `https://developer.android.com/reference/java/io/InputStream.html`. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#enableMultiInstanceInvalidation()()` Sets whether table invalidation in this instance of `https://developer.android.com/reference/androidx/room/RoomDatabase` should be broadcast and synchronized with other instances of the same `https://developer.android.com/reference/androidx/room/RoomDatabase`, including those in a separate process. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `[fallbackToDestructiveMigration](https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#fallbackToDestructiveMigration())()` **This method is deprecated.** Replace by overloaded version with parameter to indicate if all tables should be dropped or not. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#fallbackToDestructiveMigration(kotlin.Boolean)(boolean dropAllTables)` Allows Room to destructively recreate database tables if `https://developer.android.com/reference/androidx/room/migration/Migration`s that would migrate old database schemas to the latest schema version are not found. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `[fallbackToDestructiveMigrationFrom](https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#fallbackToDestructiveMigrationFrom(kotlin.IntArray))(int... startVersions)` **This method is deprecated.** Replace by overloaded version with parameter to indicate if all tables should be dropped or not. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#fallbackToDestructiveMigrationFrom(kotlin.Boolean,kotlin.IntArray)( boolean dropAllTables, int... startVersions )` Informs Room that it is allowed to destructively recreate database tables from specific starting schema versions. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `[fallbackToDestructiveMigrationOnDowngrade](https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#fallbackToDestructiveMigrationOnDowngrade())()` **This method is deprecated.** Replace by overloaded version with parameter to indicate if all tables should be dropped or not. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#fallbackToDestructiveMigrationOnDowngrade(kotlin.Boolean)(boolean dropAllTables)` Allows Room to destructively recreate database tables if `https://developer.android.com/reference/androidx/room/migration/Migration`s are not available when downgrading to old schema versions. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#openHelperFactory(androidx.sqlite.db.SupportSQLiteOpenHelper.Factory)(https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteOpenHelper.Factory factory)` Sets the database factory. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `@https://developer.android.com/reference/androidx/room/ExperimentalRoomApi https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#setAutoCloseTimeout(kotlin.Long,java.util.concurrent.TimeUnit)( @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) long autoCloseTimeout, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/TimeUnit.html autoCloseTimeUnit )` Enables auto-closing for the database to free up unused resources. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#setDriver(androidx.sqlite.SQLiteDriver)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/sqlite/SQLiteDriver driver)` Sets the `https://developer.android.com/reference/androidx/sqlite/SQLiteDriver` implementation to be used by Room to open database connections. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `@https://developer.android.com/reference/androidx/room/ExperimentalRoomApi https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#setInMemoryTrackingMode(kotlin.Boolean)(boolean inMemory)` Sets whether Room will use an in-memory table or a persisted table to track invalidation. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#setJournalMode(androidx.room.RoomDatabase.JournalMode)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.JournalMode journalMode)` Sets the journal mode for this database. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `@https://developer.android.com/reference/androidx/room/ExperimentalRoomApi https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#setMultiInstanceInvalidationServiceIntent(android.content.Intent)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Intent.html invalidationServiceIntent )` Sets whether table invalidation in this instance of `https://developer.android.com/reference/androidx/room/RoomDatabase` should be broadcast and synchronized with other instances of the same `https://developer.android.com/reference/androidx/room/RoomDatabase`, including those in a separate process. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#setQueryCallback(kotlin.coroutines.CoroutineContext,androidx.room.RoomDatabase.QueryCallback)( @https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html context, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.QueryCallback queryCallback )` Sets a `https://developer.android.com/reference/androidx/room/RoomDatabase.QueryCallback` to be invoked when queries are executed. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#setQueryCallback(androidx.room.RoomDatabase.QueryCallback,java.util.concurrent.Executor)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.QueryCallback queryCallback, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor )` Sets a `https://developer.android.com/reference/androidx/room/RoomDatabase.QueryCallback` to be invoked when queries are executed. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#setQueryCoroutineContext(kotlin.coroutines.CoroutineContext)(@https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html context)` Sets the `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html` that will be used to execute all asynchronous queries and tasks, such as `Flow` emissions and `https://developer.android.com/reference/androidx/room/InvalidationTracker` notifications. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#setQueryExecutor(java.util.concurrent.Executor)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor)` Sets the `https://developer.android.com/reference/java/util/concurrent/Executor.html` that will be used to execute all non-blocking asynchronous queries and tasks, including `LiveData` invalidation, `Flowable` scheduling and `ListenableFuture` tasks. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#setTransactionExecutor(java.util.concurrent.Executor)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor)` Sets the `https://developer.android.com/reference/java/util/concurrent/Executor.html` that will be used to execute all non-blocking asynchronous transaction queries and tasks, including `LiveData` invalidation, `Flowable` scheduling and `ListenableFuture` tasks. |

## Public methods

### addAutoMigrationSpec

Added in [2.4.0](https://developer.android.com/jetpack/androidx/releases/room#2.4.0)

```
public @NonNull RoomDatabase.Builder<@NonNull T> addAutoMigrationSpec(@NonNull AutoMigrationSpec autoMigrationSpec)
```

Adds an auto migration spec instance to the builder.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/migration/AutoMigrationSpec autoMigrationSpec` | The auto migration object that is annotated with `https://developer.android.com/reference/androidx/room/ProvidedAutoMigrationSpec` and is declared in an `https://developer.android.com/reference/androidx/room/AutoMigration` annotation. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

### addCallback

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0)

```
public @NonNull RoomDatabase.Builder<@NonNull T> addCallback(@NonNull RoomDatabase.Callback callback)
```

Adds a `https://developer.android.com/reference/androidx/room/RoomDatabase.Callback` to this database.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Callback callback` | The callback. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

### addMigrations

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0)

```
public @NonNull RoomDatabase.Builder<@NonNull T> addMigrations(@NonNull Migration... migrations)
```

Adds a migration to the builder.

Each `https://developer.android.com/reference/androidx/room/migration/Migration` has a start and end versions and Room runs these migrations to bring the database to the latest version.

A migration can handle more than 1 version (e.g. if you have a faster path to choose when going from version 3 to 5 without going to version 4). If Room opens a database at version 3 and latest version is \>= 5, Room will use the migration object that can migrate from 3 to 5 instead of 3 to 4 and 4 to 5.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/migration/Migration... migrations` | The migration objects that modify the database schema with the necessary changes for a version change. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

### addTypeConverter

Added in [2.3.0](https://developer.android.com/jetpack/androidx/releases/room#2.3.0)

```
public @NonNull RoomDatabase.Builder<@NonNull T> addTypeConverter(@NonNull Object typeConverter)
```

Adds a type converter instance to the builder.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Object.html typeConverter` | The converter instance that is annotated with `https://developer.android.com/reference/androidx/room/ProvidedTypeConverter`. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

### allowMainThreadQueries

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0)

```
public @NonNull RoomDatabase.Builder<@NonNull T> allowMainThreadQueries()
```

Disables the main thread query check for Room.

Room ensures that Database is never accessed on the main thread because it may lock the main thread and trigger an ANR. If you need to access the database from the main thread, you should always use async alternatives or manually move the call to a background thread.

You may want to turn this check off for testing.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

### build

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0)

```
public @NonNull T build()
```

Creates the database and initializes it.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull T` | A new database instance. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if the builder was misconfigured. |

### createFromAsset

Added in [2.2.0](https://developer.android.com/jetpack/androidx/releases/room#2.2.0)

```
public @NonNull RoomDatabase.Builder<@NonNull T> createFromAsset(@NonNull String databaseFilePath)
```

Configures Room to create and open the database using a pre-packaged database located in the application 'assets/' folder.

Room does not open the pre-packaged database, instead it copies it into the internal app database folder and then opens it. The pre-packaged database file must be located in the "assets/" folder of your application. For example, the path for a file located in "assets/databases/products.db" would be "databases/products.db".

The pre-packaged database schema will be validated. It might be best to create your pre-packaged database schema utilizing the exported schema files generated when `https://developer.android.com/reference/androidx/room/Database#exportSchema()` is enabled.

This method is not supported for an in memory database `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html databaseFilePath` | The file path within the 'assets/' directory of where the database file is located. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

### createFromAsset

Added in [2.3.0](https://developer.android.com/jetpack/androidx/releases/room#2.3.0)

```
public @NonNull RoomDatabase.Builder<@NonNull T> createFromAsset(
    @NonNull String databaseFilePath,
    @NonNull RoomDatabase.PrepackagedDatabaseCallback callback
)
```

Configures Room to create and open the database using a pre-packaged database located in the application 'assets/' folder.

Room does not open the pre-packaged database, instead it copies it into the internal app database folder and then opens it. The pre-packaged database file must be located in the "assets/" folder of your application. For example, the path for a file located in "assets/databases/products.db" would be "databases/products.db".

The pre-packaged database schema will be validated. It might be best to create your pre-packaged database schema utilizing the exported schema files generated when `https://developer.android.com/reference/androidx/room/Database#exportSchema()` is enabled.

This method is not supported for an in memory database `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html databaseFilePath` | The file path within the 'assets/' directory of where the database file is located. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.PrepackagedDatabaseCallback callback` | The pre-packaged callback. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

### createFromFile

Added in [2.2.0](https://developer.android.com/jetpack/androidx/releases/room#2.2.0)

```
public @NonNull RoomDatabase.Builder<@NonNull T> createFromFile(@NonNull File databaseFile)
```

Configures Room to create and open the database using a pre-packaged database file.

Room does not open the pre-packaged database, instead it copies it into the internal app database folder and then opens it. The given file must be accessible and the right permissions must be granted for Room to copy the file.

The pre-packaged database schema will be validated. It might be best to create your pre-packaged database schema utilizing the exported schema files generated when `https://developer.android.com/reference/androidx/room/Database#exportSchema()` is enabled.

The `https://developer.android.com/reference/androidx/room/RoomDatabase.Callback#onOpen(androidx.sqlite.db.SupportSQLiteDatabase)` method can be used as an indicator that the pre-packaged database was successfully opened by Room and can be cleaned up.

This method is not supported for an in memory database `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/io/File.html databaseFile` | The database file. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

### createFromFile

Added in [2.3.0](https://developer.android.com/jetpack/androidx/releases/room#2.3.0)

```
public @NonNull RoomDatabase.Builder<@NonNull T> createFromFile(
    @NonNull File databaseFile,
    @NonNull RoomDatabase.PrepackagedDatabaseCallback callback
)
```

Configures Room to create and open the database using a pre-packaged database file.

Room does not open the pre-packaged database, instead it copies it into the internal app database folder and then opens it. The given file must be accessible and the right permissions must be granted for Room to copy the file.

The pre-packaged database schema will be validated. It might be best to create your pre-packaged database schema utilizing the exported schema files generated when `https://developer.android.com/reference/androidx/room/Database#exportSchema()` is enabled.

The `https://developer.android.com/reference/androidx/room/RoomDatabase.Callback#onOpen(androidx.sqlite.db.SupportSQLiteDatabase)` method can be used as an indicator that the pre-packaged database was successfully opened by Room and can be cleaned up.

This method is not supported for an in memory database `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/io/File.html databaseFile` | The database file. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.PrepackagedDatabaseCallback callback` | The pre-packaged callback. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

### createFromInputStream

Added in [2.3.0](https://developer.android.com/jetpack/androidx/releases/room#2.3.0)

```
public @NonNull RoomDatabase.Builder<@NonNull T> createFromInputStream(
    @NonNull Callable<@NonNull InputStream> inputStreamCallable
)
```

Configures Room to create and open the database using a pre-packaged database via an `https://developer.android.com/reference/java/io/InputStream.html`.

This is useful for processing compressed database files. Room does not open the pre-packaged database, instead it copies it into the internal app database folder, and then open it. The `https://developer.android.com/reference/java/io/InputStream.html` will be closed once Room is done consuming it.

The pre-packaged database schema will be validated. It might be best to create your pre-packaged database schema utilizing the exported schema files generated when `https://developer.android.com/reference/androidx/room/Database#exportSchema()` is enabled.

The `https://developer.android.com/reference/androidx/room/RoomDatabase.Callback#onOpen(androidx.sqlite.db.SupportSQLiteDatabase)` method can be used as an indicator that the pre-packaged database was successfully opened by Room and can be cleaned up.

This method is not supported for an in memory database `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Callable.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/io/InputStream.html> inputStreamCallable` | A callable that returns an InputStream from which to copy the database. The callable will be invoked in a thread from the Executor set via `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#setQueryExecutor(java.util.concurrent.Executor)`. The callable is only invoked if Room needs to create and open the database from the pre-package database, usually the first time it is created or during a destructive migration. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

### createFromInputStream

Added in [2.3.0](https://developer.android.com/jetpack/androidx/releases/room#2.3.0)

```
public @NonNull RoomDatabase.Builder<@NonNull T> createFromInputStream(
    @NonNull Callable<@NonNull InputStream> inputStreamCallable,
    @NonNull RoomDatabase.PrepackagedDatabaseCallback callback
)
```

Configures Room to create and open the database using a pre-packaged database via an `https://developer.android.com/reference/java/io/InputStream.html`.

This is useful for processing compressed database files. Room does not open the pre-packaged database, instead it copies it into the internal app database folder, and then open it. The `https://developer.android.com/reference/java/io/InputStream.html` will be closed once Room is done consuming it.

The pre-packaged database schema will be validated. It might be best to create your pre-packaged database schema utilizing the exported schema files generated when `https://developer.android.com/reference/androidx/room/Database#exportSchema()` is enabled.

The `https://developer.android.com/reference/androidx/room/RoomDatabase.Callback#onOpen(androidx.sqlite.db.SupportSQLiteDatabase)` method can be used as an indicator that the pre-packaged database was successfully opened by Room and can be cleaned up.

This method is not supported for an in memory database `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Callable.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/io/InputStream.html> inputStreamCallable` | A callable that returns an InputStream from which to copy the database. The callable will be invoked in a thread from the Executor set via `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#setQueryExecutor(java.util.concurrent.Executor)`. The callable is only invoked if Room needs to create and open the database from the pre-package database, usually the first time it is created or during a destructive migration. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.PrepackagedDatabaseCallback callback` | The pre-packaged callback. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

### enableMultiInstanceInvalidation

Added in [2.1.0](https://developer.android.com/jetpack/androidx/releases/room#2.1.0)

```
public @NonNull RoomDatabase.Builder<@NonNull T> enableMultiInstanceInvalidation()
```

Sets whether table invalidation in this instance of `https://developer.android.com/reference/androidx/room/RoomDatabase` should be broadcast and synchronized with other instances of the same `https://developer.android.com/reference/androidx/room/RoomDatabase`, including those in a separate process. In order to enable multi-instance invalidation, this has to be turned on both ends.

This is not enabled by default.

This does not work for in-memory databases. This does not work between database instances targeting different database files.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

### fallbackToDestructiveMigration

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0) Deprecated in [2.7.0](https://developer.android.com/jetpack/androidx/releases/room#2.7.0)

```
public @NonNull RoomDatabase.Builder<@NonNull T> [fallbackToDestructiveMigration](https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#fallbackToDestructiveMigration())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Replace by overloaded version with parameter to indicate if all tables should be dropped or not, use this instead:
>
> ```
> fallbackToDestructiveMigration(false)
> ```

Allows Room to destructively recreate database tables if `https://developer.android.com/reference/androidx/room/migration/Migration`s that would migrate old database schemas to the latest schema version are not found.

When the database version on the device does not match the latest schema version, Room runs necessary `https://developer.android.com/reference/androidx/room/migration/Migration`s on the database.

If it cannot find the set of `https://developer.android.com/reference/androidx/room/migration/Migration`s that will bring the database to the current version, it will throw an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html`.

You can call this method to change this behavior to re-create the database tables instead of crashing.

If the database was create from an asset or a file then Room will try to use the same file to re-create the database, otherwise this will delete all of the data in the database tables managed by Room.

To let Room fallback to destructive migration only during a schema downgrade then use `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#fallbackToDestructiveMigrationOnDowngrade()`.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

### fallbackToDestructiveMigration

Added in [2.7.0](https://developer.android.com/jetpack/androidx/releases/room#2.7.0)

```
public final @NonNull RoomDatabase.Builder<@NonNull T> fallbackToDestructiveMigration(boolean dropAllTables)
```

Allows Room to destructively recreate database tables if `https://developer.android.com/reference/androidx/room/migration/Migration`s that would migrate old database schemas to the latest schema version are not found.

When the database version on the device does not match the latest schema version, Room runs necessary `https://developer.android.com/reference/androidx/room/migration/Migration`s on the database. If it cannot find the set of `https://developer.android.com/reference/androidx/room/migration/Migration`s that will bring the database to the current version, it will throw an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html`. You can call this method to change this behavior to re-create the database tables instead of crashing.

To let Room fallback to destructive migration only during a schema downgrade then use `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#fallbackToDestructiveMigrationOnDowngrade(kotlin.Boolean)`.

| Parameters |
|---|---|
| `boolean dropAllTables` | Set to `true` if all tables should be dropped during destructive migration including those not managed by Room. Recommended value is `true` as otherwise Room could leave obsolete data when table names or existence changes between versions. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

### fallbackToDestructiveMigrationFrom

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0) Deprecated in [2.7.0](https://developer.android.com/jetpack/androidx/releases/room#2.7.0)

```
public @NonNull RoomDatabase.Builder<@NonNull T> [fallbackToDestructiveMigrationFrom](https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#fallbackToDestructiveMigrationFrom(kotlin.IntArray))(int... startVersions)
```

> [!CAUTION]
> **This method is deprecated.**   
> Replace by overloaded version with parameter to indicate if all tables should be dropped or not, use this instead:
>
> ```
> fallbackToDestructiveMigrationFrom(false, startVersions)
> ```

Informs Room that it is allowed to destructively recreate database tables from specific starting schema versions.

This functionality is the same as that provided by `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#fallbackToDestructiveMigration()`, except that this method allows the specification of a set of schema versions for which destructive recreation is allowed.

Using this method is preferable to `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#fallbackToDestructiveMigration()` if you want to allow destructive migrations from some schema versions while still taking advantage of exceptions being thrown due to unintentionally missing migrations.

Note: No versions passed to this method may also exist as either starting or ending versions in the `https://developer.android.com/reference/androidx/room/migration/Migration`s provided to `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#addMigrations(kotlin.Array)`. If a version passed to this method is found as a starting or ending version in a Migration, an exception will be thrown.

| Parameters |
|---|---|
| `int... startVersions` | The set of schema versions from which Room should use a destructive migration. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

### fallbackToDestructiveMigrationFrom

Added in [2.7.0](https://developer.android.com/jetpack/androidx/releases/room#2.7.0)

```
public @NonNull RoomDatabase.Builder<@NonNull T> fallbackToDestructiveMigrationFrom(
    boolean dropAllTables,
    int... startVersions
)
```

Informs Room that it is allowed to destructively recreate database tables from specific starting schema versions.

This functionality is the same `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#fallbackToDestructiveMigration(kotlin.Boolean)`, except that this method allows the specification of a set of schema versions for which destructive recreation is allowed.

Using this method is preferable to `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#fallbackToDestructiveMigration(kotlin.Boolean)` if you want to allow destructive migrations from some schema versions while still taking advantage of exceptions being thrown due to unintentionally missing migrations.

Note: No versions passed to this method may also exist as either starting or ending versions in the `https://developer.android.com/reference/androidx/room/migration/Migration`s provided via `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#addMigrations(kotlin.Array)`. If a version passed to this method is found as a starting or ending version in a Migration, an exception will be thrown.

| Parameters |
|---|---|
| `boolean dropAllTables` | Set to `true` if all tables should be dropped during destructive migration including those not managed by Room. Recommended value is `true` as otherwise Room could leave obsolete data when table names or existence changes between versions. |
| `int... startVersions` | The set of schema versions from which Room should use a destructive migration. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

### fallbackToDestructiveMigrationOnDowngrade

Added in [2.1.0](https://developer.android.com/jetpack/androidx/releases/room#2.1.0) Deprecated in [2.7.0](https://developer.android.com/jetpack/androidx/releases/room#2.7.0)

```
public @NonNull RoomDatabase.Builder<@NonNull T> [fallbackToDestructiveMigrationOnDowngrade](https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#fallbackToDestructiveMigrationOnDowngrade())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Replace by overloaded version with parameter to indicate if all tables should be dropped or not, use this instead:
>
> ```
> fallbackToDestructiveMigrationOnDowngrade(false)
> ```

Allows Room to destructively recreate database tables if `https://developer.android.com/reference/androidx/room/migration/Migration`s are not available when downgrading to old schema versions.

For details, see `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#fallbackToDestructiveMigration()`.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

### fallbackToDestructiveMigrationOnDowngrade

Added in [2.7.0](https://developer.android.com/jetpack/androidx/releases/room#2.7.0)

```
public final @NonNull RoomDatabase.Builder<@NonNull T> fallbackToDestructiveMigrationOnDowngrade(boolean dropAllTables)
```

Allows Room to destructively recreate database tables if `https://developer.android.com/reference/androidx/room/migration/Migration`s are not available when downgrading to old schema versions.

For details, see `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#fallbackToDestructiveMigration(kotlin.Boolean)`.

| Parameters |
|---|---|
| `boolean dropAllTables` | Set to `true` if all tables should be dropped during destructive migration including those not managed by Room. Recommended value is `true` as otherwise Room could leave obsolete data when table names or existence changes between versions. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

### openHelperFactory

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0)

```
public @NonNull RoomDatabase.Builder<@NonNull T> openHelperFactory(SupportSQLiteOpenHelper.Factory factory)
```

Sets the database factory. If not set, it defaults to `https://developer.android.com/reference/androidx/sqlite/db/framework/FrameworkSQLiteOpenHelperFactory`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteOpenHelper.Factory factory` | The factory to use to access the database. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

### setAutoCloseTimeout

Added in [2.3.0](https://developer.android.com/jetpack/androidx/releases/room#2.3.0)

```
@ExperimentalRoomApi
public @NonNull RoomDatabase.Builder<@NonNull T> setAutoCloseTimeout(
    @IntRange(from = 0) long autoCloseTimeout,
    @NonNull TimeUnit autoCloseTimeUnit
)
```

Enables auto-closing for the database to free up unused resources. The underlying database will be closed after it's last use after the specified `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#setAutoCloseTimeout(kotlin.Long,java.util.concurrent.TimeUnit)` has elapsed since its last usage. The database will be automatically re-opened the next time it is accessed.

Auto-closing is not compatible with in-memory databases since the data will be lost when the database is auto-closed.

Also, temp tables and temp triggers will be cleared each time the database is auto-closed. If you need to use them, please include them in your callback `https://developer.android.com/reference/androidx/room/RoomDatabase.Callback#onOpen(androidx.sqlite.db.SupportSQLiteDatabase)`.

All configuration should happen in your `https://developer.android.com/reference/androidx/room/RoomDatabase.Callback#onOpen(androidx.sqlite.db.SupportSQLiteDatabase)` callback so it is re-applied every time the database is re-opened. Note that the `https://developer.android.com/reference/androidx/room/RoomDatabase.Callback#onOpen(androidx.sqlite.db.SupportSQLiteDatabase)` will be called every time the database is re-opened.

The auto-closing database operation runs on the query executor.

The database will not be re-opened if the RoomDatabase or the SupportSqliteOpenHelper is closed manually (by calling `https://developer.android.com/reference/androidx/room/RoomDatabase#close()` or `https://developer.android.com/reference/androidx/sqlite/db/SupportSQLiteOpenHelper#close()`. If the database is closed manually, you must create a new database using `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#build()`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) long autoCloseTimeout` | the amount of time after the last usage before closing the database. Must greater or equal to zero. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/TimeUnit.html autoCloseTimeUnit` | the timeunit for autoCloseTimeout. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

### setDriver

Added in [2.7.0](https://developer.android.com/jetpack/androidx/releases/room#2.7.0)

```
public final @NonNull RoomDatabase.Builder<@NonNull T> setDriver(@NonNull SQLiteDriver driver)
```

Sets the `https://developer.android.com/reference/androidx/sqlite/SQLiteDriver` implementation to be used by Room to open database connections.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/sqlite/SQLiteDriver driver` | The driver |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

### setInMemoryTrackingMode

Added in [2.7.0](https://developer.android.com/jetpack/androidx/releases/room#2.7.0)

```
@ExperimentalRoomApi
public final @NonNull RoomDatabase.Builder<@NonNull T> setInMemoryTrackingMode(boolean inMemory)
```

Sets whether Room will use an in-memory table or a persisted table to track invalidation.

An in-memory table is used by default. Using an in-memory tables is more performant, reduces the journal file size but has an increased memory footprint, where as using a real table has the opposite effect.

| Parameters |
|---|---|
| `boolean inMemory` | True if in-memory tables should be used, false otherwise. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder` instance |

### setJournalMode

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0)

```
public @NonNull RoomDatabase.Builder<@NonNull T> setJournalMode(@NonNull RoomDatabase.JournalMode journalMode)
```

Sets the journal mode for this database.

The value is ignored if the builder is for an 'in-memory database'. The journal mode should be consistent across multiple instances of `https://developer.android.com/reference/androidx/room/RoomDatabase` for a single SQLite database file.

The default value is `https://developer.android.com/reference/androidx/room/RoomDatabase.JournalMode#WRITE_AHEAD_LOGGING`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.JournalMode journalMode` | The journal mode. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

### setMultiInstanceInvalidationServiceIntent

Added in [2.4.0](https://developer.android.com/jetpack/androidx/releases/room#2.4.0)

```
@ExperimentalRoomApi
public @NonNull RoomDatabase.Builder<@NonNull T> setMultiInstanceInvalidationServiceIntent(
    @NonNull Intent invalidationServiceIntent
)
```

Sets whether table invalidation in this instance of `https://developer.android.com/reference/androidx/room/RoomDatabase` should be broadcast and synchronized with other instances of the same `https://developer.android.com/reference/androidx/room/RoomDatabase`, including those in a separate process. In order to enable multi-instance invalidation, this has to be turned on both ends and need to point to the same `https://developer.android.com/reference/androidx/room/MultiInstanceInvalidationService`.

This is not enabled by default.

This does not work for in-memory databases. This does not work between database instances targeting different database files.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Intent.html invalidationServiceIntent` | Intent to bind to the `https://developer.android.com/reference/androidx/room/MultiInstanceInvalidationService`. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

### setQueryCallback

Added in [2.7.0](https://developer.android.com/jetpack/androidx/releases/room#2.7.0)

```
public final @NonNull RoomDatabase.Builder<@NonNull T> setQueryCallback(
    @NonNull CoroutineContext context,
    @NonNull RoomDatabase.QueryCallback queryCallback
)
```

Sets a `https://developer.android.com/reference/androidx/room/RoomDatabase.QueryCallback` to be invoked when queries are executed.

The callback is invoked whenever a query is executed, note that adding this callback has a small cost and should be avoided in production builds unless needed.

A use case for providing a callback is to allow logging executed queries. When the callback implementation simply logs then it is recommended to use `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-unconfined.html`.

If a previous callback was set with `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#setQueryCallback(kotlin.coroutines.CoroutineContext,androidx.room.RoomDatabase.QueryCallback)` then this call will override it, including removing the executor previously set, if any.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html context` | The coroutine context on which the query callback will be invoked. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.QueryCallback queryCallback` | The query callback. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

### setQueryCallback

Added in [2.3.0](https://developer.android.com/jetpack/androidx/releases/room#2.3.0)

```
public @NonNull RoomDatabase.Builder<@NonNull T> setQueryCallback(
    @NonNull RoomDatabase.QueryCallback queryCallback,
    @NonNull Executor executor
)
```

Sets a `https://developer.android.com/reference/androidx/room/RoomDatabase.QueryCallback` to be invoked when queries are executed.

The callback is invoked whenever a query is executed, note that adding this callback has a small cost and should be avoided in production builds unless needed.

A use case for providing a callback is to allow logging executed queries. When the callback implementation logs then it is recommended to use an immediate executor.

If a previous callback was set with `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#setQueryCallback(androidx.room.RoomDatabase.QueryCallback,java.util.concurrent.Executor)` then this call will override it, including removing the Coroutine context previously set, if any.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.QueryCallback queryCallback` | The query callback. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor` | The executor on which the query callback will be invoked. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

### setQueryCoroutineContext

Added in [2.7.0](https://developer.android.com/jetpack/androidx/releases/room#2.7.0)

```
public final @NonNull RoomDatabase.Builder<@NonNull T> setQueryCoroutineContext(@NonNull CoroutineContext context)
```

Sets the `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html` that will be used to execute all asynchronous queries and tasks, such as `Flow` emissions and `https://developer.android.com/reference/androidx/room/InvalidationTracker` notifications.

If no `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html` is present in the `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#setQueryCoroutineContext(kotlin.coroutines.CoroutineContext)` then this function will throw an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html`

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html context` | The context |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder` instance |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if the `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#setQueryCoroutineContext(kotlin.coroutines.CoroutineContext)` has no `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html` |

### setQueryExecutor

Added in [2.0.0](https://developer.android.com/jetpack/androidx/releases/room#2.0.0)

```
public @NonNull RoomDatabase.Builder<@NonNull T> setQueryExecutor(@NonNull Executor executor)
```

Sets the `https://developer.android.com/reference/java/util/concurrent/Executor.html` that will be used to execute all non-blocking asynchronous queries and tasks, including `LiveData` invalidation, `Flowable` scheduling and `ListenableFuture` tasks.

When both the query executor and transaction executor are unset, then a default `Executor` will be used. The default `Executor` allocates and shares threads amongst Architecture Components libraries. If the query executor is unset but a transaction executor was set via `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#setTransactionExecutor(java.util.concurrent.Executor)`, then the same `Executor` will be used for queries.

For best performance the given `Executor` should be bounded (max number of threads is limited).

The input `Executor` cannot run tasks on the UI thread.

If either `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#setQueryCoroutineContext(kotlin.coroutines.CoroutineContext)` has been called, then this function will throw an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html`.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if this builder was already configured with a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html`. |

### setTransactionExecutor

Added in [2.1.0](https://developer.android.com/jetpack/androidx/releases/room#2.1.0)

```
public @NonNull RoomDatabase.Builder<@NonNull T> setTransactionExecutor(@NonNull Executor executor)
```

Sets the `https://developer.android.com/reference/java/util/concurrent/Executor.html` that will be used to execute all non-blocking asynchronous transaction queries and tasks, including `LiveData` invalidation, `Flowable` scheduling and `ListenableFuture` tasks.

When both the transaction executor and query executor are unset, then a default `Executor` will be used. The default `Executor` allocates and shares threads amongst Architecture Components libraries. If the transaction executor is unset but a query executor was set using `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#setQueryExecutor(java.util.concurrent.Executor)`, then the same `Executor` will be used for transactions.

If the given `Executor` is shared then it should be unbounded to avoid the possibility of a deadlock. Room will not use more than one thread at a time from this executor since only one transaction at a time can be executed, other transactions will be queued on a first come, first serve order.

The input `Executor` cannot run tasks on the UI thread.

If either `https://developer.android.com/reference/androidx/room/RoomDatabase.Builder#setQueryCoroutineContext(kotlin.coroutines.CoroutineContext)` has been called, then this function will throw an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html`.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if this builder was already configured with a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html`. |