ChatiumFor developersPlaygroundPricing
Sign in

HeapTableRepo.countBy

Returns the number of records that meet the specified filter.

If no filter is provided, it returns the total count of the table.

Usage/Signature

table.countBy(ctx, where)
  • Arguments

    • ctx*: app.Ctx
      The request context. Used for internal implementation and allows executing the query in the appropriate transaction.
    • where: HeapFilter
      An object with filtering conditions in a special language.
  • Return Value: Promise<number>

    • The number of records

Examples


Count of records with a priority greater than 3.

const Tasks = Heap.Table('tasks', {
  title: Heap.String(),
  priority: Heap.Integer(),
})
const importantTasksCount = await Tasks.countBy(ctx, {
  priority: { $gt: 3 },
})

Count of all records in the 'tasks' table.

const allCount = await Tasks.countBy(ctx)