HeapTableRepo.findAll
Returns an array of heap objects with specified filtering, sorting, and quantity limits.
If filtering and quantity limits are not specified, all records from the table are returned.
The maximum number of records that this method can return is 1000. Use the
offset
andlimit
parameters to retrieve more records through multiple requests.
Usage / Signature
const rows = await table.findAll(ctx, options)
Arguments
-
ctx app.Ctx *
Request context. Used for internal implementation and allows executing the request in the desired transaction. -
options:
{ where, order, limit, offset }
An object with optional query parameters for the table.-
where: HeapFilter
An object with filtering conditions in a special language. -
order:
string | object | Array<string | object>
Rules for sorting records.A rule can be a single one (sorting by one field) or multiple as an array, in which case sorting occurs by several fields in the specified order, similar to SQL.
The type of the field is taken into account for proper sorting, as numbers are sorted as numbers.
-
string
For simple ascending sorting by a top-level field, you can simply specify its name as a string. -
object
If you need to sort in descending order or by a non-top-level field value, you can pass an object in the format{ topField: { nestedField: 'desc' } }
.
-
-
Sorting Direction Value Options
-
asc (default) for ascending order.
Equivalent toasc nulls last
. -
desc for descending order.
Equivalent todesc nulls first
. -
'asc nulls first' | 'asc nulls last' | 'desc nulls first' | 'desc nulls last'
You can additionally explicitly specify the behavior of sorting records with missing (null) values in the sorting field. -
limit:
number
Defines the maximum number of records from the result set after filtering and sorting that should be returned. Records are counted from the beginning of the result list. Fully analogous toSQL LIMIT
.
IMPORTANT: the maximum value for this parameter is 1000 records; specifying more will result in an error. If the limit is not specified, the first 1000 records will be returned by default. -
offset:
number
Defines the number of records to skip (remove from the result set) after filtering and sorting before returning the result. Fully analogous toSQL OFFSET
.
Return Value: Promise<HeapObject[]>
An array of heap objects that match the filtering and sorting conditions.
Examples
Fetching All Records from the Table
const Tasks = Heap.Table('tasks', {
title: Heap.String(),
responsible: Heap.RefLink('employees'),
priority: Heap.Integer(),
})
const all = await Tasks.findAll(ctx)
Fetching Tasks from 11th to 20th, Sorted by Title
const from11to20 = await Tasks.findAll(ctx, {
order: 'title',
limit: 10,
offset: 10,
})
Fetching All Tasks with Priority Greater than 5, Sorted by Responsible Employee ID (Pseudo-grouping) and Priority from Highest to Lowest for Each Responsible
const all = await Tasks.findAll(ctx, {
where: { priority: { $gt: 5 } },
order: ['responsible', { priority: 'desc' }],
})