### Deleting records with custom primary keys

In addition to deleting by the model type (or `Predicates.ALL`), a record with a custom primary key can be deleted the following ways:


With a predicate:

#### Custom Primary Key

<BlockSwitcher>
<Block name="Java">

```java
Amplify.DataStore.query(Book.class, Where.identifier(Book.class,
                                                      Where.identifier(Book.class, "12345")),
    matches -> {
        if (matches.hasNext()) {
            Book book = matches.next();
            Amplify.DataStore.delete(book,
                    deleted -> Log.i("MyAmplifyApp", "Deleted a book."),
                    failure -> Log.e("MyAmplifyApp", "Delete failed.", failure)
            );
        }
    },
    failure -> Log.e("MyAmplifyApp", "Query failed.", failure));

```

</Block>
<Block name="Kotlin - Callbacks">

```kotlin
Amplify.DataStore.query(Book::class.java, Where.identifier(Book::class.java, "12345"),
    { matches ->
        if (matches.hasNext()) {
            val post = matches.next()
            Amplify.DataStore.delete(post,
                { Log.i("MyAmplifyApp", "Deleted a book.") },
                { Log.e("MyAmplifyApp", "Delete failed.", it) }
            )
        }
    },
    { Log.e("MyAmplifyApp", "Query failed.", it) }
)
```

</Block>
<Block name="Kotlin - Coroutines (Beta)">

```kotlin
Amplify.DataStore.query(Book::class, Where.identifier(Book::class.java, "12345"))
    .catch { Log.e("MyAmplifyApp", "Query failed", it) }
    .onEach { Amplify.DataStore.delete(it) }
    .catch { Log.e("MyAmplifyApp", "Delete failed", it) }
    .collect { Log.i("MyAmplifyApp", "Deleted a book") }
```

</Block>
<Block name="RxJava">

```java
RxAmplify.DataStore.query(Book.class, Where.identifier(Book::class.java, "12345"))
    .flatMapCompletable(RxAmplify.DataStore::delete)
    .subscribe(
        () -> Log.i("MyAmplifyApp", "Deleted a book."),
        failure -> Log.e("MyAmplifyApp", "Delete failed.", failure)
    );
```

</Block>
</BlockSwitcher>


#### Composite Key

<BlockSwitcher>
<Block name="Java">

```java
Amplify.DataStore.query(Book.class, Where.identifier(Book.class, Where.identifier(Book::class.java,
                                                      new BookIdentifier( "12345", "My Title")),
    matches -> {
        if (matches.hasNext()) {
            Book book = matches.next();
            Amplify.DataStore.delete(book,
              deleted -> Log.i("MyAmplifyApp", "Deleted a book."),
              failure -> Log.e("MyAmplifyApp", "Delete failed.", failure)
            );
        }
    },
    failure -> Log.e("MyAmplifyApp", "Query failed.", failure));

```

</Block>
<Block name="Kotlin - Callbacks">

```kotlin
Amplify.DataStore.query(Book::class.java, Where.identifier(Book::class.java,
                                                 BookIdentifier( "12345", "My Title")),
    { matches ->
        if (matches.hasNext()) {
            val post = matches.next()
            Amplify.DataStore.delete(post,
                { Log.i("MyAmplifyApp", "Deleted a book.") },
                { Log.e("MyAmplifyApp", "Delete failed.", it) }
            )
        }
    },
    { Log.e("MyAmplifyApp", "Query failed.", it) }
)
```

</Block>
<Block name="Kotlin - Coroutines (Beta)">

```kotlin
Amplify.DataStore.query(Book::class, Where.identifier(Book::class.java,
                                               BookIdentifier( "12345", "My Title")))
    .catch { Log.e("MyAmplifyApp", "Query failed", it) }
    .onEach { Amplify.DataStore.delete(it) }
    .catch { Log.e("MyAmplifyApp", "Delete failed", it) }
    .collect { Log.i("MyAmplifyApp", "Deleted a book") }
```

</Block>
<Block name="RxJava">

```java
RxAmplify.DataStore.query(Book.class, Where.identifier(Book::class.java,
                                       new BookIdentifier( "12345", "My Title")))
    .flatMapCompletable(RxAmplify.DataStore::delete)
    .subscribe(
        () -> Log.i("MyAmplifyApp", "Deleted a book."),
        failure -> Log.e("MyAmplifyApp", "Delete failed.", failure)
    );
```

</Block>
</BlockSwitcher>


