Gets the validation function for the JSON schema defined in the ISchemaFields for this model.
Gets a partition accessor for the collection. See Partition for more information.
Raw model properties. These are also accessible on the instance directly, but you need to manually declare them if you use TypeScript.
Schema for this model.
Instance of ajv used for validation. You can modify or replace this as needed, to add custom validators for example. Modifications must happen before you start using models, since validation functions will be compiled and cached the first time they're used.
Default Cosmos DB container for the model. This can be populated by hand,
or by the connectModels()
helper function.
Default container for the model. This can be populated by hand, or by
the connectModels()
helper function.
Gets the etag of the data when it was read.
This will be undefined if the model was not yet saved and was not loaded from the database.
Gets the model ID. This is unique within a Cosmos DB partition.
Gets the time the model was last updated.
This will be undefined if the model was not yet saved and was not loaded from the database.
Lifecycle hook called after the model is created for the first time.
Lifecycle hook called after an existing model is deleted.
Lifecycle hook called after the model is successfully persisted. This is
called before afterCreate
or afterUpdate
.
Lifecycle hook called after an existing model is updated.
Lifecycle hook called before the model is created for the first time.
Lifecycle hook called before an existing model is deleted.
Lifecycle hook called before the model is persisted. This is called
after beforeCreate
or beforeUpdate
.
Lifecycle hook called before an existing model is updated.
Creates the item, if it doesn't exist. If it does, an error is thrown.
Gets the value for the partition key in the current model.
Safely persists the model -- updating it if it was originally retrieved from the database (provided a model with the ID doesn't already exist) or creating it if not.
Implements JSON serialization, returns the same as BaseModel.toObject.
Returns a shallow copy of the properties on the model, excluding internal Cosmos DB fields.
Persists item updates to the database. This uses etags to avoid a
conflict, if the item was originally retrieved from the database.
This can throw an error if another process made and update in
the meantime. To avoid this behavior, pass { overwrite: true }
.
Validates the current set of properties on the model.
Generated using TypeDoc
The BaseModel is the foundational type for models, which is returned by a call to Model. It provides lifecycle hooks (which can be overridden) and methods for saving, deleting, and validating a document in Cosmos DB.
To look up a model, you'll usually use the methods on
Model.partition()
, orModel.crossPartitionQuery()
.