Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const schema = a.schema({
});
```

<InlineFilter filters={["javascript", "angular", "react-native", "react", "nextjs", "vue", "android", "flutter"]}>
<InlineFilter filters={["javascript", "angular", "react-native", "react", "nextjs", "vue", "android"]}>

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

Expand Down Expand Up @@ -104,6 +104,28 @@ let queriedCustomers = try await Amplify.API.query(
```

</InlineFilter>

<InlineFilter filters={["flutter"]}>

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

```dart title="lib/main.dart"
import 'package:amplify_api/amplify_api.dart';
import 'package:amplify_flutter/amplify_flutter.dart';
import 'amplify_outputs.dart';
import 'models/ModelProvider.dart';

// highlight-start
final request = ModelQueries.list(
Customer.classType,
where: accountRepresentativeId.eq(YOUR_REP_ID),
);
// highlight-end

```

</InlineFilter>

<Accordion title="Review how this works under the hood with Amazon DynamoDB">

Amplify uses Amazon DynamoDB tables as the default data source for `a.model()`. For key-value databases, it is critical to model your access patterns with "secondary indexes". Use the `.secondaryIndexes()` modifier to configure a secondary index.
Expand Down Expand Up @@ -133,7 +155,7 @@ export const schema = a.schema({
});
```

<InlineFilter filters={["javascript", "angular", "react-native", "react", "nextjs", "vue", "android", "flutter"]}>
<InlineFilter filters={["javascript", "angular", "react-native", "react", "nextjs", "vue", "android",]}>

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:

Expand Down Expand Up @@ -185,6 +207,27 @@ let queriedCustomers = try await Amplify.API.query(
```
</InlineFilter>

<InlineFilter filters={["flutter"]}>

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

```dart title="lib/main.dart"
import 'package:amplify_api/amplify_api.dart';
import 'package:amplify_flutter/amplify_flutter.dart';
import 'amplify_outputs.dart';
import 'models/ModelProvider.dart';

// highlight-start
final request = ModelQueries.list(
Customer.classType,
where: Customer.accountRepresentativeId.eq(YOUR_REP_ID) & Customer.name.begins("Rene"),
);
// highlight-end

```

</InlineFilter>

## Customize the query field for secondary indexes

You can also customize the auto-generated query name under `client.models.<MODEL_NAME>.listBy...` by setting the `queryField()` modifier.
Expand All @@ -206,7 +249,7 @@ const schema = a.schema({
});
```

<InlineFilter filters={["javascript", "angular", "react-native", "react", "nextjs", "vue", "android", "flutter"]}>
<InlineFilter filters={["javascript", "angular", "react-native", "react", "nextjs", "vue", "android"]}>

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

Expand Down