-
Notifications
You must be signed in to change notification settings - Fork 122
Finding records
Michael Dostál edited this page Nov 14, 2018
·
1 revision
You can use your Datastore
in order to query your API with the findAll()
method:
- The first argument is the type of object you want to query.
- The second argument is the list of params: write them in JSON format and they will be serialized.
- The returned value is a document which gives access to the metdata and the models.
// ...
constructor(private datastore: Datastore) { }
getPosts(){
this.datastore.findAll(Post, {
page: { size: 10, number: 1 },
filter: {
title: 'My Post',
},
}).subscribe(
(posts: JsonApiQueryData<Post>) => console.log(posts.getModels())
);
}
Use peekAll()
to retrieve all of the records for a given type that are already loaded into the store, without making a network request:
let posts = this.datastore.peekAll(Post);
Use findRecord()
to retrieve a record by its type and ID:
this.datastore.findRecord(Post, '1').subscribe(
(post: Post) => console.log(post)
);
Use peekRecord()
to retrieve a record by its type and ID, without making a network request. This will return the record only if it is already present in the store:
let post = this.datastore.peekRecord(Post, '1');