A pages instance is used to query the data stored in the cms.
A single page can be fetched using the findFirst method. Criteria can be passed to filter entries.
// Fetch the first page where field equals the string 'value'
const page: AnyPage | undefined = await pages
.findFirst(page => page.field.is('value'))
Multiple pages can be fetched using the findMany method.
// Fetch all pages where field equals the string 'value'
const pages: Array<AnyPage> = await pages
.findMany(page => page.field.is('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 pages
.all()
.skip(10)
.take(10)
A result set can be ordered by passing one or multiple fields.
const ordered = await pages
.all()
.orderBy(Type.foo.asc(), Type.bar.desc())
Results can be grouped by one or more fields.
const grouped = await pages
.all()
.groupBy(Type.foo, Type.bar)
Resulting rows can be narrowed to contain only specific fields.
// Return only titles
const rows = await pages
.all()
.select(page => ({
title: page.title
})
It's possible to process field values by passing a function, which can be async.
const row = await pages
.findFirst()
.select(page => ({
title:
page.title.process(title => `process title ${title}`)
})