Skip to content

Commit

Permalink
Update index.mdx
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbonifacio authored Apr 12, 2024
1 parent 3364772 commit ea78a8c
Showing 1 changed file with 19 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ You can optimize your list queries based on "secondary indexes". For example, if

A secondary index consists of a "hash key" and, optionally, a "sort key". Use the "hash key" to perform strict equality and the "sort key" for greater than (gt), greater than or equal to (ge), less than (lt), less than or equal to (le), equals (eq), begins with, and between operations.

```ts
```ts title="amplify/data/resource.ts"
export const schema = a.schema({
Customer: a
.model({
Expand All @@ -32,7 +32,7 @@ export const schema = a.schema({

The example client query below allows you to query for "Customer" records based on their `accountRepresentativeId`:

```ts
```ts title="src/App.tsx"
import { type Schema } from '../amplify/data/resource';
import { generateClient } from 'aws-amplify/data';

Expand Down Expand Up @@ -77,7 +77,7 @@ export const schema = a.schema({

On the client side, you should find a new `listBy...` query that's named after hash key and sort keys. For example, in this case: `listByAccountRepresentativeIdAndName`. You can supply the filter as part of this new list query:

```ts
```ts title="src/App.tsx"
const {
data,
errors
Expand Down Expand Up @@ -114,7 +114,7 @@ const schema = a.schema({

In your client app code, you'll see query updated under the Data client:

```ts
```ts title="src/App.tsx"
const {
data,
errors
Expand All @@ -128,20 +128,19 @@ const {

To customize the underlying DynamoDB's index name, you can optionally provide the `name()` modifier.

```ts
const schema = a
.schema({
Customer: a
.model({
name: a.string(),
phoneNumber: a.phone(),
accountRepresentativeId: a.id().required(),
})
.secondaryIndexes((index) => [
index("accountRepresentativeId")
// highlight-next-line
.name("MyCustomIndexName"),
])
.authorization([a.allow.owner()])
});
```ts title="amplify/data/resource.ts"
const schema = a.schema({
Customer: a
.model({
name: a.string(),
phoneNumber: a.phone(),
accountRepresentativeId: a.id().required(),
})
.secondaryIndexes((index) => [
index("accountRepresentativeId")
// highlight-next-line
.name("MyCustomIndexName"),
])
.authorization([a.allow.owner()]),
});
```

0 comments on commit ea78a8c

Please sign in to comment.