Automatically set create and update timestamps on your Objection.js models.
Install from npm:
npm install objection-timestampRegister the plugin with an instance of objection:
const objectionTimestamp = require('objection-timestamp');
objectionTimestamp.register(objection);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.register(objection, {
create: 'createdOn',
update: 'updatedOn'
});When timestamps are enabled on a model, the appropriate timestamp attributes will be set to new Date() before insert and update actions.
Set the timestamp static property on your model to true:
class MyModel {
static get timestamp() {
return true;
}
}You can set the timestamp static property to an object to enable or disable specific a timestamp:
class MyModel {
static get timestamp() {
return {
create: true,
update: false
}
}
}If either key is omitted it will be implicitly set to false.