Timestamps plugin for knorm.
This plugin adds the knex timestamp
fields to your models and also updates your query methods so that createdAt
and updatedAt
are set to the current time (i.e. new Date()
) for insert
calls and the updatedAt
field is set to the current time for any update
calls. It will also ensure that any update
calls do not overwrite the
createdAt
field.
npm install --save knorm knorm-timestamps
knorm-timestamps has a peer dependency on knorm
const knorm = require('knorm');
const knormTimestamps = require('knorm-timestamps');
const orm = knorm({
// knorm options
}).use(
knormTimestamps({
// knormTimestamps options
})
);
type: object, default:
{ name: 'createdAt', column: 'created_at' }
The createdAt
field can be configured with these options:
-
name
string, default: createdAt: the field name -
column
string, default: created_at: the column name
type: object, default:
{ name: 'updatedAt', column: 'updated_at' }
The updatedAt
field can be configured with these options:
-
name
string, default: updatedAt: the field name -
column
string, default: updated_at: the column name