# DataStore.Builder

Artifact: [androidx.datastore:datastore-core](https://developer.android.com/jetpack/androidx/releases/datastore) [View Source](https://cs.android.com/search?q=file:androidx/datastore/core/DataStore.+class:androidx.datastore.core.DataStore.Builder) Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/datastore#1.3.0)

*** ** * ** ***

Common/AllAndroid/JVMNative/C/iOSJavaScript
- Cmn

  ```
  class DataStore.Builder<T : Any?>
  ```

*** ** * ** ***

Builder for `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore`.

## Summary

| ### Public constructors |
|---|---|
| `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore.Builder#Builder(androidx.datastore.core.Storage,kotlin.coroutines.CoroutineContext)(storage: https://developer.android.com/reference/kotlin/androidx/datastore/core/Storage<T>, context: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html)` | Cmn android N JS |

| ### Public functions |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore.Builder<T>` | `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore.Builder#addMigrations(kotlin.collections.List)(migrations: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/datastore/core/DataMigration<T>>)` Adds `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataMigration`s to the DataStore. | Cmn android N JS |
| `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore<T>` | `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore.Builder#build()()` Validates the configuration and builds the `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore.Builder` instance. | Cmn android N JS |
| `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore.Builder<T>` | `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore.Builder#setCorruptionHandler(androidx.datastore.core.CorruptionHandler)(handler: https://developer.android.com/reference/kotlin/androidx/datastore/core/CorruptionHandler<T>)` Sets the `https://developer.android.com/reference/kotlin/androidx/datastore/core/CorruptionHandler` for the DataStore. | Cmn android N JS |
| `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore.Builder<T>` | `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore.Builder#setTracer(androidx.tracing.Tracer)(tracer: https://developer.android.com/reference/kotlin/androidx/tracing/Tracer)` Sets the `https://developer.android.com/reference/kotlin/androidx/tracing/Tracer` for Android. | android |

## Public constructors

### Builder

Cmn android N JS

```
<T : Any?> Builder(storage: Storage<T>, context: CoroutineContext)
```

## Public functions

### addMigrations

Cmn android N JS

```
fun addMigrations(migrations: List<DataMigration<T>>): DataStore.Builder<T>
```

Adds `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataMigration`s to the DataStore.

Migrations are run in the order they are added before any data is returned to the user.

| Parameters |
|---|---|
| `migrations: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/datastore/core/DataMigration<T>>` | the list of migrations. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore.Builder<T>` | this `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore.Builder` instance. |

### build

Cmn android N JS Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/datastore#1.3.0)

```
fun build(): DataStore<T>
```

Validates the configuration and builds the `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore.Builder` instance.

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore<T>` | a new DataStore instance. |

### setCorruptionHandler

Cmn android N JS Added in [1.3.0](https://developer.android.com/jetpack/androidx/releases/datastore#1.3.0)

```
fun setCorruptionHandler(handler: CorruptionHandler<T>): DataStore.Builder<T>
```

Sets the `https://developer.android.com/reference/kotlin/androidx/datastore/core/CorruptionHandler` for the DataStore.

This handler is invoked if the `https://developer.android.com/reference/kotlin/androidx/datastore/core/Storage` layer throws a `https://developer.android.com/reference/kotlin/androidx/datastore/core/CorruptionException`. Defaults to `https://developer.android.com/reference/kotlin/androidx/datastore/core/handlers/ReThrowCorruptionHandler`.

| Parameters |
|---|---|
| `handler: https://developer.android.com/reference/kotlin/androidx/datastore/core/CorruptionHandler<T>` | the corruption handler. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore.Builder<T>` | this `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore.Builder` instance. |

### setTracer

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

```
fun setTracer(tracer: Tracer): DataStore.Builder<T>
```

Sets the `https://developer.android.com/reference/kotlin/androidx/tracing/Tracer` for Android.

| Parameters |
|---|---|
| `tracer: https://developer.android.com/reference/kotlin/androidx/tracing/Tracer` | The `https://developer.android.com/reference/kotlin/androidx/tracing/Tracer` to use. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore.Builder<T>` | this `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore.Builder` instance. |