3.0.2 • Published 7 years ago
knorm-timestamps v3.0.2
knorm-timestamps
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.
Installation
npm install --save knorm knorm-timestamps
knorm-timestamps has a peer dependency on knorm
Usage
const knorm = require('knorm');
const knormTimestamps = require('knorm-timestamps');
const orm = knorm({
// knorm options
}).use(
knormTimestamps({
// knormTimestamps options
})
);
Options
createdAt
type: object, default:
{ name: 'createdAt', column: 'created_at' }
The createdAt
field can be configured with these options:
name
string, default: createdAt: the field namecolumn
string, default: created_at: the column name
updatedAt
type: object, default:
{ name: 'updatedAt', column: 'updated_at' }
The updatedAt
field can be configured with these options:
name
string, default: updatedAt: the field namecolumn
string, default: updated_at: the column name