objection-timestamp
Automatically set create and update timestamps on your Objection.js models.
Installation
Install from npm:
npm install objection-timestamp
Register the plugin with an instance of objection:
const objectionTimestamp = ;objectionTimestamp;
Configuration
By default, objection-timestamp uses createdAt
and updatedAt
attributes for timestamping. You can optionally pass in an options object as the second argument to register to specify custom attributes to use for timestamps:
objectionTimestamp;
Usage
When timestamps are enabled on a model, the appropriate timestamp attributes will be set to new Date()
before insert and update actions.
Enable timestamps for a model
Set the timestamp
static property on your model to true:
static { return true; }
Enable only a specific timestamp for a model
You can set the timestamp
static property to an object to enable or disable specific a timestamp:
static { return create: true update: false }
If either key is omitted it will be implicitly set to false
.