The CMS instance that is exported in your config file can be used to query the stored data.
import {cms} from '@/cms'
const homePage = await cms.get(HomePage())
A single page can be fetched using the get method. Criteria can be passed to filter entries.
// Fetch the first page where field equals the string 'value'
const page = await cms.get(Page({field: 'value'}))
Multiple pages can be fetched using the find method.
// Fetch all pages where field equals the string 'value'
const pages = await cms.find(Page({field: 'value'}))
A result set can be limited using skip and take.
// Skip the first 10 pages and return a maximum of 10
const limited = await cms.find(Page().skip(10).take(10))
To filter pages on specific fields first narrow the search to a type, then use the where method to specify conditions.
const old = await cms.find(
Animal().where(Animal.age.greater(10))
)
const teenager = await cms.find(Human().where(
Human.age.greater(10).or(
Human.age.less(20)
)
)
const applesOrOranges = await cms.find(
Fruit().where(Fruit.title.isIn(['apple', 'orange']))
)
A result set can be ordered by passing one or multiple fields.
const ordered = await cms.find(NewsItem().orderBy(NewsItem.publishDate.desc())
Results can be grouped by one or more fields.
const grouped = await cms.find(
NewsItem().groupBy(NewsItem.category)
)
Resulting rows can be narrowed to contain only specific fields.
// Return only titles
const rows = await cms.find(
Page().select({title: Page.title})
)