# RoomDatabase.Builder

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

*** ** * ** ***


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

<br />

*** ** * ** ***

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

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

## Summary

| ### Public methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder#addAutoMigrationSpec(androidx.room3.migration.AutoMigrationSpec)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/migration/AutoMigrationSpec autoMigrationSpec)` Adds an auto migration spec instance to the builder. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder#addCallback(androidx.room3.RoomDatabase.Callback)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/RoomDatabase.Callback callback)` Adds a `https://developer.android.com/reference/androidx/room3/RoomDatabase.Callback` to this database. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder#addColumnTypeConverter(kotlin.Any)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Object.html typeConverter)` Adds a column type converter instance to the builder. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder#addDaoReturnTypeConverter(kotlin.Any)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Object.html daoReturnTypeConverter)` Adds a DAO return type converter instance to the builder. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder#addMigrations(kotlin.Array)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/migration/Migration... migrations)` Adds a migration to the builder. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder#allowDataLossOnRecovery(kotlin.Boolean)(boolean allowDataLossOnRecovery)` Sets whether Room is allowed to delete and recreate the database file during corruption recovery. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder#allowMainThreadQueries()()` Disables the main thread query check for Room. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull T` | `https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder#build()()` Creates the database and initializes it. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room3/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. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder#createFromAsset(kotlin.String,androidx.room3.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/room3/RoomDatabase.PrepackagedDatabaseCallback callback )` Configures Room to create and open the database using a pre-packaged database located in the application 'assets/' folder. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room3/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. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder#createFromFile(java.io.File,androidx.room3.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/room3/RoomDatabase.PrepackagedDatabaseCallback callback )` Configures Room to create and open the database using a pre-packaged database file. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room3/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`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder#createFromInputStream(java.util.concurrent.Callable,androidx.room3.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/room3/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`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder#enableMultiInstanceInvalidation()()` Sets whether table invalidation in this instance of `https://developer.android.com/reference/androidx/room3/RoomDatabase` should be broadcast and synchronized with other instances of the same `https://developer.android.com/reference/androidx/room3/RoomDatabase`, including those in a separate process. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder#fallbackToDestructiveMigration(kotlin.Boolean)(boolean dropAllTables)` Allows Room to destructively recreate database tables if `https://developer.android.com/reference/androidx/room3/migration/Migration`s that would migrate old database schemas to the latest schema version are not found. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room3/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. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder#fallbackToDestructiveMigrationOnDowngrade(kotlin.Boolean)(boolean dropAllTables)` Allows Room to destructively recreate database tables if `https://developer.android.com/reference/androidx/room3/migration/Migration`s are not available when downgrading to old schema versions. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `@https://developer.android.com/reference/androidx/room3/ExperimentalRoomApi https://developer.android.com/reference/androidx/room3/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/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder#setConnectionPoolTimeout(kotlin.time.Duration)(@https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.time/-duration/index.html timeout)` Sets the timeout `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.time/-duration/index.html` to wait when acquiring a connection from the before timing out and throwing an `https://developer.android.com/reference/androidx/sqlite/SQLiteException`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room3/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/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `@https://developer.android.com/reference/androidx/room3/ExperimentalRoomApi https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder#setInMemoryTrackingMode(kotlin.Boolean)(boolean inMemory)` Sets whether Room will use an in-memory table or a persisted table to track invalidation. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder#setJournalMode(androidx.room3.RoomDatabase.JournalMode)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/RoomDatabase.JournalMode journalMode)` Sets the journal mode for this database. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `@https://developer.android.com/reference/androidx/room3/ExperimentalRoomApi https://developer.android.com/reference/androidx/room3/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/room3/RoomDatabase` should be broadcast and synchronized with other instances of the same `https://developer.android.com/reference/androidx/room3/RoomDatabase`, including those in a separate process. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder#setMultipleConnectionPool(kotlin.Int,kotlin.Int)(int maxNumOfReaders, int maxNumOfWriters)` Sets the database connection pool to use multiple connections, separating readers and writers. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `@https://developer.android.com/reference/androidx/room3/ExperimentalRoomApi https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder#setPreparedStatementCacheSize(kotlin.Int)(@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int maxCacheSize)` Sets the maximum number of prepared statements cached per database connection. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room3/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/room3/InvalidationTracker` notifications. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder#setSingleConnectionPool()()` Sets the database connection pool to use a single connection for both reading and writing. |

## Public methods

### addAutoMigrationSpec

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

```
public final @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/room3/migration/AutoMigrationSpec autoMigrationSpec` | The auto migration object that is annotated with `https://developer.android.com/reference/androidx/room3/ProvidedAutoMigrationSpec` and is declared in an `https://developer.android.com/reference/androidx/room3/AutoMigration` annotation. |

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

### addCallback

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

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

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

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

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

### addColumnTypeConverter

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

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

Adds a column 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/room3/ProvidedColumnTypeConverter`. |

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

### addDaoReturnTypeConverter

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

```
public final @NonNull RoomDatabase.Builder<@NonNull T> addDaoReturnTypeConverter(@NonNull Object daoReturnTypeConverter)
```

Adds a DAO return type converter instance to the builder.

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

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

### addMigrations

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

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

Adds a migration to the builder.

Each `https://developer.android.com/reference/androidx/room3/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/room3/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/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

### allowDataLossOnRecovery

Added in [3.1.0-alpha03](https://developer.android.com/jetpack/androidx/releases/room3#3.1.0-alpha03)

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

Sets whether Room is allowed to delete and recreate the database file during corruption recovery.

During initialization, Room attempts to open and verify the database connection. If opening fails due to an `https://developer.android.com/reference/androidx/sqlite/SQLiteException` (such as file corruption) and cannot be resolved by an initial retry, Room enters a recovery flow:

- If `https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder#allowDataLossOnRecovery(kotlin.Boolean)` is `true`, Room deletes the corrupted database file along with any companion journal files (`-wal`, `-shm`, `-journal`) and recreates the database, resulting in data loss.

- If `https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder#allowDataLossOnRecovery(kotlin.Boolean)` is `false` (the default), Room rethrows the exception without attempting recovery.

| Parameters |
|---|---|
| `boolean allowDataLossOnRecovery` | whether database deletion and recreation is permitted on corruption |

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

### allowMainThreadQueries

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

```
public final @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/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

### build

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

```
public final @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 [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.0)

```
public final @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/room3/Database#exportSchema()` is enabled.

This method is not supported for an in memory database `https://developer.android.com/reference/androidx/room3/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/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

### createFromAsset

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

```
public final @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/room3/Database#exportSchema()` is enabled.

This method is not supported for an in memory database `https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder` and a `https://developer.android.com/reference/android/content/Context.html` is required during builder instantiation.

| 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/room3/RoomDatabase.PrepackagedDatabaseCallback callback` | The pre-packaged callback. |

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

### createFromFile

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

```
public final @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/room3/Database#exportSchema()` is enabled.

The `https://developer.android.com/reference/androidx/room3/RoomDatabase.Callback#onOpen(androidx.sqlite.SQLiteConnection)` 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/room3/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/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

### createFromFile

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

```
public final @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/room3/Database#exportSchema()` is enabled.

The `https://developer.android.com/reference/androidx/room3/RoomDatabase.Callback#onOpen(androidx.sqlite.SQLiteConnection)` 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/room3/RoomDatabase.Builder` and a `https://developer.android.com/reference/android/content/Context.html` is required during builder instantiation.

| 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/room3/RoomDatabase.PrepackagedDatabaseCallback callback` | The pre-packaged callback. |

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

### createFromInputStream

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

```
public final @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/room3/Database#exportSchema()` is enabled.

The `https://developer.android.com/reference/androidx/room3/RoomDatabase.Callback#onOpen(androidx.sqlite.SQLiteConnection)` 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/room3/RoomDatabase.Builder` and a `https://developer.android.com/reference/android/content/Context.html` is required during builder instantiation.

| 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 dispatcher set via `https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder#setQueryCoroutineContext(kotlin.coroutines.CoroutineContext)`. 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/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

### createFromInputStream

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

```
public final @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/room3/Database#exportSchema()` is enabled.

The `https://developer.android.com/reference/androidx/room3/RoomDatabase.Callback#onOpen(androidx.sqlite.SQLiteConnection)` 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/room3/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 dispatcher set via `https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder#setQueryCoroutineContext(kotlin.coroutines.CoroutineContext)`. 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/room3/RoomDatabase.PrepackagedDatabaseCallback callback` | The pre-packaged callback. |

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

### enableMultiInstanceInvalidation

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

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

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

### fallbackToDestructiveMigration

Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.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/room3/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/room3/migration/Migration`s on the database. If it cannot find the set of `https://developer.android.com/reference/androidx/room3/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/room3/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, otherwise only Room managed tables are dropped. Default 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/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

### fallbackToDestructiveMigrationFrom

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

```
public final @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/room3/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/room3/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/room3/migration/Migration`s provided via `https://developer.android.com/reference/androidx/room3/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, otherwise only Room managed tables are dropped. Default 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/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

### fallbackToDestructiveMigrationOnDowngrade

Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.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/room3/migration/Migration`s are not available when downgrading to old schema versions.

For details, see `https://developer.android.com/reference/androidx/room3/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, otherwise only Room managed tables are dropped. Default 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/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

### setAutoCloseTimeout

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

```
@ExperimentalRoomApi
public final @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/room3/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/room3/RoomDatabase.Callback#onOpen(androidx.sqlite.SQLiteConnection)`.

All configuration should happen in your `https://developer.android.com/reference/androidx/room3/RoomDatabase.Callback#onOpen(androidx.sqlite.SQLiteConnection)` callback so it is re-applied every time the database is re-opened. Note that the `https://developer.android.com/reference/androidx/room3/RoomDatabase.Callback#onOpen(androidx.sqlite.SQLiteConnection)` 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 is closed manually (by calling `https://developer.android.com/reference/androidx/room3/RoomDatabase#close()`). If the database is closed manually, you must create a new database using `https://developer.android.com/reference/androidx/room3/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/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

### setConnectionPoolTimeout

Added in [3.1.0-alpha03](https://developer.android.com/jetpack/androidx/releases/room3#3.1.0-alpha03)

```
public final @NonNull RoomDatabase.Builder<@NonNull T> setConnectionPoolTimeout(@NonNull Duration timeout)
```

Sets the timeout `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.time/-duration/index.html` to wait when acquiring a connection from the before timing out and throwing an `https://developer.android.com/reference/androidx/sqlite/SQLiteException`.

Defaults to `30.seconds`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.time/-duration/index.html timeout` | The maximum duration to wait for a connection. Must be positive. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/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 `https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder#setConnectionPoolTimeout(kotlin.time.Duration)` is not positive. |

### setDriver

Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.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/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This builder instance. |

### setInMemoryTrackingMode

Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.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/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This `https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder` instance |

### setJournalMode

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

```
public final @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/room3/RoomDatabase` for a single SQLite database file.

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

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

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

### setMultiInstanceInvalidationServiceIntent

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

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

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

This is not enabled by default and requires that a `https://developer.android.com/reference/android/content/Context.html` is used during builder instantiation.

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/room3/MultiInstanceInvalidationService`. |

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

### setMultipleConnectionPool

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

```
public final @NonNull RoomDatabase.Builder<@NonNull T> setMultipleConnectionPool(int maxNumOfReaders, int maxNumOfWriters)
```

Sets the database connection pool to use multiple connections, separating readers and writers.

A connection pool is only used if the supplied `https://developer.android.com/reference/androidx/sqlite/SQLiteDriver` has no internal pool, i.e. `https://developer.android.com/reference/androidx/sqlite/SQLiteDriver#hasConnectionPool()` returns `false`. If the configured driver has an internal pool then calling this function has no effect.

If the database being built is an in-memory database, then calling this function has no effect since a single connection will be used.

Calling this function overrides any previous setting. If neither this function or `https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder#setMultipleConnectionPool(kotlin.Int,kotlin.Int)` are called then Room will default to a connection pool configuration that is based on the `https://developer.android.com/reference/androidx/room3/RoomDatabase.JournalMode`. For `https://developer.android.com/reference/androidx/room3/RoomDatabase.JournalMode#TRUNCATE` a single connection is used, while for `https://developer.android.com/reference/androidx/room3/RoomDatabase.JournalMode#WRITE_AHEAD_LOGGING` multiple connections are used, four reader and one writer.

It is recommended to only use multiple connections when `https://developer.android.com/reference/androidx/room3/RoomDatabase.JournalMode#WRITE_AHEAD_LOGGING` is configured. Be aware that if multiple writers are used then database operations might fail with `SQLITE_BUSY` errors. These must be handled by the callers and might be mitigated by configuring the `busy_timeout`.

| Parameters |
|---|---|
| `int maxNumOfReaders` | The maximum number of reader connections. |
| `int maxNumOfWriters` | The maximum number of writer connections. |

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

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder#setSingleConnectionPool()` |   |

### setPreparedStatementCacheSize

Added in [3.1.0-alpha03](https://developer.android.com/jetpack/androidx/releases/room3#3.1.0-alpha03)

```
@ExperimentalRoomApi
public final @NonNull RoomDatabase.Builder<@NonNull T> setPreparedStatementCacheSize(@IntRange(from = 0) int maxCacheSize)
```

Sets the maximum number of prepared statements cached per database connection.

The statement cache is only used if the supplied `https://developer.android.com/reference/androidx/sqlite/SQLiteDriver` has no internal pool, i.e., `https://developer.android.com/reference/androidx/sqlite/SQLiteDriver#hasConnectionPool()` returns `false`. If the configured driver has an internal pool then calling this function has no effect.

Defaults to `25`. Setting `https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder#setPreparedStatementCacheSize(kotlin.Int)` to `0` disables the cache.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) int maxCacheSize` | The maximum number of prepared statements to cache per connection. Must be non-negative. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/room3/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 `https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder#setPreparedStatementCacheSize(kotlin.Int)` is negative. |

### setQueryCoroutineContext

Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/room3#3.0.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/room3/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/room3/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/room3/RoomDatabase.Builder<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | This `https://developer.android.com/reference/androidx/room3/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/room3/RoomDatabase.Builder#setQueryCoroutineContext(kotlin.coroutines.CoroutineContext)` has no `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html` |

### setSingleConnectionPool

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

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

Sets the database connection pool to use a single connection for both reading and writing.

A connection pool is only used if the supplied `https://developer.android.com/reference/androidx/sqlite/SQLiteDriver` has no internal pool, i.e. `https://developer.android.com/reference/androidx/sqlite/SQLiteDriver#hasConnectionPool()` returns `false`. If the configured driver has an internal pool then calling this function has no effect.

Calling this function overrides any previous setting.If neither this function or `https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder#setMultipleConnectionPool(kotlin.Int,kotlin.Int)` are called then Room will default to a connection pool configuration that is based on the `https://developer.android.com/reference/androidx/room3/RoomDatabase.JournalMode`. For `https://developer.android.com/reference/androidx/room3/RoomDatabase.JournalMode#TRUNCATE` a single connection is used, while for `https://developer.android.com/reference/androidx/room3/RoomDatabase.JournalMode#WRITE_AHEAD_LOGGING` multiple connections are used, four reader and one writer.

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

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/room3/RoomDatabase.Builder#setMultipleConnectionPool(kotlin.Int,kotlin.Int)` |   |