Finding Records
The Store provides functions for retrieving records of a single type.
See Fetching Data in the routing guide for how to obtain a reference to the application-wide store.
Retrieving a Single Record
Use Store::find_record() to retrieve a record by its type and ID.
use crate::generated::Bucket;
use crate::models::customer::Customer;
let customer: Customer = store.find_record(Bucket::Customers, "123", None).await?;
Use Store::peek_record() 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's cache:
let maybe_customer: Option<Customer> = store.peek_record(Bucket::Customers, "123")?;
Retrieving Multiple Records
Use Store::find_all() to retrieve all of the records for a given type:
let customers: Vec<Customer> = store.find_all(Bucket::Customers, None).await?;
Use Store::peek_all() to retrieve all of the records for a given type that are already
loaded in the store, without making a network request:
let customers: Vec<Customer> = store.peek_all(Bucket::Customers)?;
Querying for Multiple Records
Use Store::query() to query for records that meet certain criteria.
use serde_json::json;
let customers: Vec<Customer> = store.query(Bucket::Customers, json!({
"filter": {
"name": "Acme Widgets",
},
})).await?;