Skip to content

Commit 7245f10

Browse files
committed
Add section about query/queryRecord
1 parent 56ea471 commit 7245f10

File tree

11 files changed

+38
-1
lines changed

11 files changed

+38
-1
lines changed

app/routes/application.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@ export default class ApplicationRoute extends Route {
1111
classicFiles: ['old.js'],
1212
octaneFiles: ['new.js', 'replicate-store.js', 'own-builder.js'],
1313
},
14+
{
15+
id: 'find-all',
16+
classicFiles: ['old.js'],
17+
octaneFiles: ['new.js'],
18+
},
19+
{
20+
id: 'query',
21+
classicFiles: ['old.js'],
22+
octaneFiles: ['new.js'],
23+
},
24+
{
25+
id: 'query-record',
26+
classicFiles: ['old.js'],
27+
octaneFiles: ['new.js'],
28+
},
1429
],
1530
},
1631
{
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { query } from '@ember-data/json-api/request';
2+
3+
const result = await store.request(query('user'));
4+
const users = result.content.data;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const users = this.store.findAll('user')
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { query } from '@ember-data/json-api/request';
2+
3+
const result = await store.request(query('user', { ...params, limit: 1 }));
4+
const user = result.content.data[0] ?? null;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const user = await store.queryRecord('user', params);

snippets/fetching-data/query/new.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { query } from '@ember-data/json-api/request';
2+
3+
const result = await store.request(query('user', { filter: { name: 'John' } }));
4+
const users = result.content.data;

snippets/fetching-data/query/old.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const users = await store.query('user', { filter: { name: 'John' } });
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
title: findAll
2+
description: |
3+
There is no direct replacement for <code>findAll</code>, you should just use <code>query</code> without options instead.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
title: Find Record
1+
title: findRecord
22
description: |
33
Examples here are shown for apps that use JSON:API. Apps using other paradigms should use the builders for REST or ActiveRecord if applicable, or author their own (or a new community lib!) if not.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
title: queryRecord
2+
description: There is no direct replacement of <code>queryRecord</code>. You can just use <code>query</code> with <code>limit=1</code> option.

0 commit comments

Comments
 (0)