Call matter.table(key) to get a handle to one of your app’s tables. Every filtered or ordered
read runs through one of the table’s indexes. To read tasks, see
Boards and tasks.
Reading rows
const deals = matter.table('deals')
// 1. Page of rows matching an index
const page = await deals.query({ index: 'by_stage', eq: { stage: 'lead' }, limit: 50 })
// -> { rows: [{ id, title, values, createdBy, createdAt, updatedAt, cursor }], nextCursor, prevCursor }
// 2. Counts, existence checks, and grouped counts
const total = await deals.count({ index: 'by_owner_stage', eq: { owner: '$viewer', stage: ['lead', 'won'] } })
const hasSam = await deals.exists({ index: 'by_email', eq: { email: 'sam@acme.com' } })
const byStage = await deals.groupCount({ index: 'by_stage', by: 'stage' })
// -> { groups: [{ values: { stage: 'lead' }, count }], more }
// 3. Lightweight ID scans and direct lookups
const { ids } = await deals.ids({ index: 'by_stage', eq: { stage: 'won' } })
const one = await deals.get(id)
const many = await deals.getMany(ids)Read methods#
| Method | Returns |
|---|---|
query(read?) |
{ rows, nextCursor, prevCursor } — a page of rows in index order (or table order when no
index is given).
|
count(read?) |
Total matching rows (or total rows in the table when called with no arguments). |
exists(read) |
boolean — whether at least one row matches the index query. Requires index.
|
groupCount({ index, eq?, by }) |
{ groups, more } — row counts grouped by the index’s match fields named in
by. Requires index.
|
ids(read) |
{ ids, nextCursor } — matching row IDs in index order without loading cell values.
Requires index.
|
get(id) / getMany(ids) |
Single row (or null) / array of found rows by ID. |
fields() |
Array of { id, key, name, type, options, declared } describing the table’s columns.
|
Query options#
index: name of the index to read through (as declared inmatter.json).-
eq: exact values for every match field of the index. Pass an array (such asstage: ['lead', 'won']) to match any of those values, ornullto match empty cells. -
range:{ field, gt?, gte?, lt?, lte? }bounding the index’s first order field. -
order:'asc'(the index’s declared order, default) or'desc'(reversed). -
limit: maximum rows to return (up to1000; defaults to50forqueryand100forids/groupCount). -
after,before,until: rowcursorstrings for pagination.
Compound match + range example
// Index: "by_stage": { "match": ["stage"], "order": [{ "field": "value", "direction": "desc" }] }
// Leads worth over $1,000, largest first:
const highValueLeads = await deals.query({
index: 'by_stage',
eq: { stage: 'lead' },
range: { field: 'value', gt: 1000 },
})How row values are formatted#
Each row’s values object is keyed by field key (and the row’s title is available both as
row.title and under the title field’s key, such as row.values.name). Empty fields
are omitted from values:
- Select / Multi-select: option key string(s).
-
Person:
{ id, name }(or an array whenallowMultiple: true). Ineq, pass a member ID, display name, or'$viewer'. -
Relation:
{ id, title }(or an array whenallowMultiple: true). - Date:
'YYYY-MM-DD'. -
Files (
attachment): a list of{ id, name, size, mime_type, url }, whereurlloads the file (since Matter 0.5.9). See Files.
Reading UI labels & cursor pagination#
Call fields() to display the labels people see in table headers or forms: your manifest’s names
for your app’s own tables, and whatever people named the fields of other tables in the space:
Labels and pagination
const fields = await deals.fields()
const labelByKey = Object.fromEntries(fields.map((f) => [f.key, f.name]))
// Page through a large result set with cursors:
let after: string | undefined
do {
const page = await deals.query({ index: 'by_stage', eq: { stage: 'lead' }, limit: 200, after })
processRows(page.rows)
after = page.nextCursor
} while (after)