@sanity/groq-store
In-memory GROQ store. Streams all available documents from Sanity into an in-memory database and allows you to query them there.
Targets
- Node.js >= 10
- Modern browsers (Edge >= 14, Chrome, Safari, Firefox etc)
Caveats
- Streams entire dataset to memory, so generally not recommended for large datasets
- Does not work with tokens in browser (currently)
Installation
npm install --save @sanity/groq-store
Usage
import {groqStore, groq} from '@sanity/groq-store'
const store = groqStore({
projectId: 'abc123',
dataset: 'blog',
listen: true,
overlayDrafts: true,
token: 'someAuthToken',
})
store.query(groq`*[_type == "author"]`).then((docs) => {
console.log(docs)
})
store.getDocument('grrm').then((grrm) => {
console.log(grrm)
})
store.getDocuments(['grrm', 'jrrt']).then(([grrm, jrrt]) => {
console.log(grrm, jrrt)
})
const sub = store.subscribe(
groq`*[_type == $type][] {name}`,
{type: 'author'},
(result) => console.log(result)
)
sub.unsubscribe()
store.close()
License
MIT © Sanity.io