Skip to main content

Deleting a Model

MVOM allows deleting database records by specifying the iD to the record. The Model class exposes a static method deleteById to support this ability.

deleteById Method

The deleteById static method is available on all Model classes. It allows a consumer to specify a record id which will initiate a call to the MultiValue database to delete that record. It will return an instance of the Model that contains the data from the record at the time of deletion. If no record with that ID exists, null will be returned.

Syntax

static deleteById(id: string, options?: ModelDeleteByIdOptions): Promise<Model | null>

Parameters

ParameterTypeDescription
idstringThe record ID of the record to read
optionsobjectOptions object (see below)

Options Object Properties

PropertyTypeDescription
maxReturnPayloadSizenumberThe maximum allowed return payload size in bytes. If this size is exceeded a DbServerError will be thrown. If omitted the value specified during connection creation is used.
requestIdstringA request/trace ID to be passed to MVIS as a request header with the key X-MVIS-Trace-Id
userDefinedobjectThe user defined options to pass to the database subroutines

Example

const schema = new Schema({
description: { type: 'string', path: 1 },
price: { type: 'number', path: 2, dbDecimals: 2 },
});

const Item = connection.model(schema, 'ITEM');

const deletedItem = await Item.deleteById('0001');

Record Delete Notes

Record Locks

MVOM will reject any database deletes for a record that is currently locked (e.g. a READU statement). In this scenario, deleteById will reject with a RecordLockedError.