HeapTableRepo.deleteAll
The deleteAll method is designed for bulk deletion of records from a table in the database. It takes a record context as well as options for filtering the records to be deleted and controlling their quantity.
Usage/Signature
table.deleteAll(ctx, options)
Arguments
-
ctx*:
WriteCtx
The record context required to perform the operation. It is used to manage transactions and store information about the current request. -
options:
HsDeleteAllOptions<HSP>
- Deletion options that include:- where?:
HsFilter<HSP> | null | undefined
— A condition for filtering the records to be deleted. You can specify a filter to delete only those records that meet certain criteria. - limit:
number | null
— A limit on the number of records that can be deleted. If a value ofnull
is specified, no limit is applied, and all records matching the where condition are deleted. By default, limit =1
, to avoid accidentally deleting more records than expected. Important: if the number of records matching the where condition exceeds limit, no records will be deleted, and an error will occur. - hard?:
boolean
— Indicates whether the deletion will be "hard" (irreversible) or "soft" (with the possibility of recovery). The default value isfalse
, which means "soft" deletion (e.g., by setting a deletion flag).
- where?:
-
Return Value:
Promise<number>
- Returns the number of deleted records.
Examples
const deletedCount = await heapTableRepo.deleteAll(ctx, {
where: { status: 'inactive' },
limit: 10,
hard: true
});
console.log(`Number of deleted records: ${deletedCount}`);