Skip to content

Commit 780284f

Browse files
committed
added documentation for flutter querying by secondary indexes in the data category
1 parent 8d3d6da commit 780284f

File tree

1 file changed

+44
-1
lines changed
  • src/pages/[platform]/build-a-backend/data/data-modeling/secondary-index

1 file changed

+44
-1
lines changed

src/pages/[platform]/build-a-backend/data/data-modeling/secondary-index/index.mdx

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,28 @@ let queriedCustomers = try await Amplify.API.query(
104104
```
105105

106106
</InlineFilter>
107+
108+
<InlineFilter filters={["flutter"]}>
109+
110+
The example client query below allows you to query for "Customer" records based on their `accountRepresentativeId`:
111+
112+
```dart title="lib/main.dart"
113+
import 'package:amplify_api/amplify_api.dart';
114+
import 'package:amplify_flutter/amplify_flutter.dart';
115+
import 'amplify_outputs.dart';
116+
import 'models/ModelProvider.dart';
117+
118+
// highlight-start
119+
final request = ModelQueries.list(
120+
Customer.classType,
121+
where: accountRepresentativeId.eq(YOUR_REP_ID),
122+
);
123+
// highlight-end
124+
125+
```
126+
127+
</InlineFilter>
128+
107129
<Accordion title="Review how this works under the hood with Amazon DynamoDB">
108130

109131
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.
@@ -185,6 +207,27 @@ let queriedCustomers = try await Amplify.API.query(
185207
```
186208
</InlineFilter>
187209

210+
<InlineFilter filters={["flutter"]}>
211+
212+
The example client query below allows you to query for "Customer" records based on their `accountRepresentativeId`:
213+
214+
```dart title="lib/main.dart"
215+
import 'package:amplify_api/amplify_api.dart';
216+
import 'package:amplify_flutter/amplify_flutter.dart';
217+
import 'amplify_outputs.dart';
218+
import 'models/ModelProvider.dart';
219+
220+
// highlight-start
221+
final request = ModelQueries.list(
222+
Customer.classType,
223+
where: Customer.accountRepresentativeId.eq(YOUR_REP_ID) & Customer.name.begins("Rene"),
224+
);
225+
// highlight-end
226+
227+
```
228+
229+
</InlineFilter>
230+
188231
## Customize the query field for secondary indexes
189232

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

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

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

0 commit comments

Comments
 (0)