firenze-behavior-timestamp
v0.4.0
Published
Timestamp behavior for firenze.js ORM
Downloads
2
Maintainers
Readme
firenze-behavior-timestamp
Timestamp behavior for firenze.js.
Automatically generate timestamps on certain fields, when saving records.
$ npm install --save firenze-behavior-timestamp
$ bower install --save firenze-behavior-timestamp
Contents
What it does
When saving a new model, it will automatically populate timestamp as value on speficied field(s).
For example, when saving a post:
var posts = new Posts();
var post = posts.model({
title: 'Hello World'
});
post.save().then(function (model) {
var created = model.get('created'); // `2015-01-01 12:00:00`
});
It will automatically save the value of current timestamp in created
field.
Usage
Node.js
With npm:
$ npm install --save firenze-behavior-timestamp
Now you can require it as follows:
var TimestampBehavior = require('firenze-behavior-timestamp');
// create your Database instance...
db.createCollection({
behaviors: [
{
'class': TimestampBehavior,
options: {
created: {
on: 'create' // 'create', 'update', or 'always'
format: 'YYYY-MM-DD HH:mm:ss' // 'object' for Date object, or moment.js format
}
}
}
]
});
Browser
Or Bower:
$ bower installl --save firenze-behavior-timestamp
Can be loaded in your HTML page as follows:
<script src="bower_components/firenze/dist/firenze.full.min.js"></script>
<script src="bower_components/moment/min/moment.min.js"></script>
<script src="bower_components/firenze-behavior-timestamp/dist/firenze-behavior-timestamp.min.js"></script>
<script>
// Timestamp behavior is available in `firenze.TimestampBehavior`
</script>
Testing
Tests are written with mocha, and can be run via npm:
$ npm test
License
MIT © Fahad Ibnay Heylaal