# 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)

*** ** * ** ***

Common/AllAndroid/JVMNative/C/iOSJavaScript
- Cmn

  ```
  class RoomDatabase.Builder<T : RoomDatabase>
  ```
- android

  ```
  open class RoomDatabase.Builder<T : RoomDatabase>
  ```

*** ** * ** ***

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

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

## Summary

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

## Public functions

### addAutoMigrationSpec

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

```
fun addAutoMigrationSpec(autoMigrationSpec: AutoMigrationSpec): RoomDatabase.Builder<T>
```

Adds an auto migration spec instance to the builder.

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

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

### addCallback

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

```
fun addCallback(callback: RoomDatabase.Callback): RoomDatabase.Builder<T>
```

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

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

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

### addMigrations

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

```
fun addMigrations(vararg migrations: Migration): RoomDatabase.Builder<T>
```

Adds a migration to the builder.

Each `https://developer.android.com/reference/kotlin/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 |
|---|---|
| `vararg migrations: https://developer.android.com/reference/kotlin/androidx/room/migration/Migration` | The migration objects that modify the database schema with the necessary changes for a version change. |

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

### addTypeConverter

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

```
fun addTypeConverter(typeConverter: Any): RoomDatabase.Builder<T>
```

Adds a type converter instance to the builder.

| Parameters |
|---|---|
| `typeConverter: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html` | The converter instance that is annotated with `https://developer.android.com/reference/kotlin/androidx/room/ProvidedTypeConverter`. |

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

### allowMainThreadQueries

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

```
open fun allowMainThreadQueries(): RoomDatabase.Builder<T>
```

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/kotlin/androidx/room/RoomDatabase.Builder<T>` | This builder instance. |

### build

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

```
fun build(): T
```

Creates the database and initializes it.

| Returns |
|---|---|
| `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

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

```
open fun createFromAsset(databaseFilePath: String): RoomDatabase.Builder<T>
```

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/kotlin/androidx/room/Database#exportSchema()` is enabled.

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

| Parameters |
|---|---|
| `databaseFilePath: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The file path within the 'assets/' directory of where the database file is located. |

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

### createFromAsset

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

```
open fun createFromAsset(
    databaseFilePath: String,
    callback: RoomDatabase.PrepackagedDatabaseCallback
): RoomDatabase.Builder<T>
```

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/kotlin/androidx/room/Database#exportSchema()` is enabled.

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

| Parameters |
|---|---|
| `databaseFilePath: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The file path within the 'assets/' directory of where the database file is located. |
| `callback: https://developer.android.com/reference/kotlin/androidx/room/RoomDatabase.PrepackagedDatabaseCallback` | The pre-packaged callback. |

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

### createFromFile

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

```
open fun createFromFile(databaseFile: File): RoomDatabase.Builder<T>
```

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/kotlin/androidx/room/Database#exportSchema()` is enabled.

The `https://developer.android.com/reference/kotlin/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/kotlin/androidx/room/RoomDatabase.Builder`.

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

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

### createFromFile

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

```
open fun createFromFile(
    databaseFile: File,
    callback: RoomDatabase.PrepackagedDatabaseCallback
): RoomDatabase.Builder<T>
```

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/kotlin/androidx/room/Database#exportSchema()` is enabled.

The `https://developer.android.com/reference/kotlin/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/kotlin/androidx/room/RoomDatabase.Builder`.

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

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

### createFromInputStream

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

```
open fun createFromInputStream(inputStreamCallable: Callable<InputStream>): RoomDatabase.Builder<T>
```

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/kotlin/androidx/room/Database#exportSchema()` is enabled.

The `https://developer.android.com/reference/kotlin/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/kotlin/androidx/room/RoomDatabase.Builder`.

| Parameters |
|---|---|
| `inputStreamCallable: https://developer.android.com/reference/java/util/concurrent/Callable.html<https://developer.android.com/reference/java/io/InputStream.html>` | 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/kotlin/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/kotlin/androidx/room/RoomDatabase.Builder<T>` | This builder instance. |

### createFromInputStream

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

```
open fun createFromInputStream(
    inputStreamCallable: Callable<InputStream>,
    callback: RoomDatabase.PrepackagedDatabaseCallback
): RoomDatabase.Builder<T>
```

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/kotlin/androidx/room/Database#exportSchema()` is enabled.

The `https://developer.android.com/reference/kotlin/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/kotlin/androidx/room/RoomDatabase.Builder`.

| Parameters |
|---|---|
| `inputStreamCallable: https://developer.android.com/reference/java/util/concurrent/Callable.html<https://developer.android.com/reference/java/io/InputStream.html>` | 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/kotlin/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. |
| `callback: https://developer.android.com/reference/kotlin/androidx/room/RoomDatabase.PrepackagedDatabaseCallback` | The pre-packaged callback. |

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

### enableMultiInstanceInvalidation

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

```
open fun enableMultiInstanceInvalidation(): RoomDatabase.Builder<T>
```

Sets whether table invalidation in this instance of `https://developer.android.com/reference/kotlin/androidx/room/RoomDatabase` should be broadcast and synchronized with other instances of the same `https://developer.android.com/reference/kotlin/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/kotlin/androidx/room/RoomDatabase.Builder<T>` | This builder instance. |

### fallbackToDestructiveMigration

android 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)

```
open fun [fallbackToDestructiveMigration](https://developer.android.com/reference/kotlin/androidx/room/RoomDatabase.Builder#fallbackToDestructiveMigration())(): RoomDatabase.Builder<T>
```

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

Allows Room to destructively recreate database tables if `https://developer.android.com/reference/kotlin/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/kotlin/androidx/room/migration/Migration`s on the database.

If it cannot find the set of `https://developer.android.com/reference/kotlin/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/kotlin/androidx/room/RoomDatabase.Builder#fallbackToDestructiveMigrationOnDowngrade()`.

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

### fallbackToDestructiveMigration

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

```
fun fallbackToDestructiveMigration(dropAllTables: Boolean): RoomDatabase.Builder<T>
```

Allows Room to destructively recreate database tables if `https://developer.android.com/reference/kotlin/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/kotlin/androidx/room/migration/Migration`s on the database. If it cannot find the set of `https://developer.android.com/reference/kotlin/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/kotlin/androidx/room/RoomDatabase.Builder#fallbackToDestructiveMigrationOnDowngrade(kotlin.Boolean)`.

| Parameters |
|---|---|
| `dropAllTables: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | 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/kotlin/androidx/room/RoomDatabase.Builder<T>` | This builder instance. |

### fallbackToDestructiveMigrationFrom

android 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)

```
open fun [fallbackToDestructiveMigrationFrom](https://developer.android.com/reference/kotlin/androidx/room/RoomDatabase.Builder#fallbackToDestructiveMigrationFrom(kotlin.IntArray))(vararg startVersions: Int): RoomDatabase.Builder<T>
```

> [!CAUTION]
> **This function is deprecated.**   
> Replace by overloaded version with parameter to indicate if all tables should be dropped or not, use this instead:
>
> ```kotlin
> 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/kotlin/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/kotlin/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/kotlin/androidx/room/migration/Migration`s provided to `https://developer.android.com/reference/kotlin/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 |
|---|---|
| `vararg startVersions: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The set of schema versions from which Room should use a destructive migration. |

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

### fallbackToDestructiveMigrationFrom

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

```
fun fallbackToDestructiveMigrationFrom(
    dropAllTables: Boolean,
    vararg startVersions: Int
): RoomDatabase.Builder<T>
```

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/kotlin/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/kotlin/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/kotlin/androidx/room/migration/Migration`s provided via `https://developer.android.com/reference/kotlin/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 |
|---|---|
| `dropAllTables: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | 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. |
| `vararg startVersions: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The set of schema versions from which Room should use a destructive migration. |

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

### fallbackToDestructiveMigrationOnDowngrade

android 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)

```
open fun [fallbackToDestructiveMigrationOnDowngrade](https://developer.android.com/reference/kotlin/androidx/room/RoomDatabase.Builder#fallbackToDestructiveMigrationOnDowngrade())(): RoomDatabase.Builder<T>
```

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

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

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

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

### fallbackToDestructiveMigrationOnDowngrade

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

```
fun fallbackToDestructiveMigrationOnDowngrade(dropAllTables: Boolean): RoomDatabase.Builder<T>
```

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

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

| Parameters |
|---|---|
| `dropAllTables: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | 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/kotlin/androidx/room/RoomDatabase.Builder<T>` | This builder instance. |

### openHelperFactory

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

```
open fun openHelperFactory(factory: SupportSQLiteOpenHelper.Factory?): RoomDatabase.Builder<T>
```

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

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

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

### setAutoCloseTimeout

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

```
@ExperimentalRoomApi
open fun setAutoCloseTimeout(
    autoCloseTimeout: @IntRange(from = 0) Long,
    autoCloseTimeUnit: TimeUnit
): RoomDatabase.Builder<T>
```

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/kotlin/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/kotlin/androidx/room/RoomDatabase.Callback#onOpen(androidx.sqlite.db.SupportSQLiteDatabase)`.

All configuration should happen in your `https://developer.android.com/reference/kotlin/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/kotlin/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/kotlin/androidx/room/RoomDatabase#close()` or `https://developer.android.com/reference/kotlin/androidx/sqlite/db/SupportSQLiteOpenHelper#close()`. If the database is closed manually, you must create a new database using `https://developer.android.com/reference/kotlin/androidx/room/RoomDatabase.Builder#build()`.

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

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

### setDriver

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

```
fun setDriver(driver: SQLiteDriver): RoomDatabase.Builder<T>
```

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

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

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

### setInMemoryTrackingMode

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

```
@ExperimentalRoomApi
fun setInMemoryTrackingMode(inMemory: Boolean): RoomDatabase.Builder<T>
```

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 |
|---|---|
| `inMemory: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | True if in-memory tables should be used, false otherwise. |

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

### setJournalMode

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

```
fun setJournalMode(journalMode: RoomDatabase.JournalMode): RoomDatabase.Builder<T>
```

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/kotlin/androidx/room/RoomDatabase` for a single SQLite database file.

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

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

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

### setMultiInstanceInvalidationServiceIntent

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

```
@ExperimentalRoomApi
open fun setMultiInstanceInvalidationServiceIntent(
    invalidationServiceIntent: Intent
): RoomDatabase.Builder<T>
```

Sets whether table invalidation in this instance of `https://developer.android.com/reference/kotlin/androidx/room/RoomDatabase` should be broadcast and synchronized with other instances of the same `https://developer.android.com/reference/kotlin/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/kotlin/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 |
|---|---|
| `invalidationServiceIntent: https://developer.android.com/reference/android/content/Intent.html` | Intent to bind to the `https://developer.android.com/reference/kotlin/androidx/room/MultiInstanceInvalidationService`. |

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

### setQueryCallback

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

```
fun setQueryCallback(
    context: CoroutineContext,
    queryCallback: RoomDatabase.QueryCallback
): RoomDatabase.Builder<T>
```

Sets a `https://developer.android.com/reference/kotlin/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/kotlin/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 |
|---|---|
| `context: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html` | The coroutine context on which the query callback will be invoked. |
| `queryCallback: https://developer.android.com/reference/kotlin/androidx/room/RoomDatabase.QueryCallback` | The query callback. |

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

### setQueryCallback

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

```
open fun setQueryCallback(
    queryCallback: RoomDatabase.QueryCallback,
    executor: Executor
): RoomDatabase.Builder<T>
```

Sets a `https://developer.android.com/reference/kotlin/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/kotlin/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 |
|---|---|
| `queryCallback: https://developer.android.com/reference/kotlin/androidx/room/RoomDatabase.QueryCallback` | The query callback. |
| `executor: https://developer.android.com/reference/java/util/concurrent/Executor.html` | The executor on which the query callback will be invoked. |

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

### setQueryCoroutineContext

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

```
fun setQueryCoroutineContext(context: CoroutineContext): RoomDatabase.Builder<T>
```

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/kotlin/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/kotlin/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 |
|---|---|
| `context: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html` | The context |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/room/RoomDatabase.Builder<T>` | This `https://developer.android.com/reference/kotlin/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/kotlin/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

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

```
open fun setQueryExecutor(executor: Executor): RoomDatabase.Builder<T>
```

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/kotlin/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/kotlin/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/kotlin/androidx/room/RoomDatabase.Builder<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

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

```
open fun setTransactionExecutor(executor: Executor): RoomDatabase.Builder<T>
```

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/kotlin/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/kotlin/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/kotlin/androidx/room/RoomDatabase.Builder<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`. |