ChatiumFor developersPlaygroundPricing
Sign in

HeapTableRepo.updateAll

The updateAll method updates all records that match the specified conditions in the table. It returns the number of updated records.

Usage/Signature

table.updateAll(ctx, options)

Arguments

  • ctx*: WriteCtx
    The write context required to perform the operation. It is used for managing transactions and storing information about the current request.

  • options: HsUpdateAllOptions<HSP> - An object with parameters for updating, containing conditions for finding records and data for their update:

    • patch: <Partial<HsUpdateInputObject<HSP>> — An object containing the data to be updated. This is a partial object that includes the fields that need to be changed in the selected records.
    • where?: HsFilter<HSP> | null | undefined — (Optional) A filter for selecting the records to be updated. If not specified (null or undefined), the method may apply to all records.
    • limit: number | null — Defines the maximum number of records that can be updated in a single method call. If null, the update will be applied without any limit on the number of records. By default, limit = 1 to avoid accidentally updating more records than expected. Important: if the number of records matching the where condition exceeds limit, no records will be updated, and an error will occur.
  • Return Value: Promise<number>

    • Returns the number of updated records.

<!-- ### Properties -->

Examples


const updatedCount = await heapTableRepo.updateAll(ctx, {
  patch: {
    status: 'inactive',
    updatedAt: new Date()
  },
  where: { status: 'active' },
  limit: 100
});
console.log(`Number of updated records: ${updatedCount}`);