🚀 Launch Week Day 4:Introducing the Alert Details Page: A Better Way to Explore Alerts.Learn More →
Socket
Book a DemoInstallSign in
Socket

mongorito-timestamps

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongorito-timestamps

Created and updated timestamps for Mongorito

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

mongorito-timestamps Build Status

Plugin to add "created" and "updated" timestamps for Mongorito models.

Installation

$ npm install --save mongorito-timestamps

Usage

const {Database, Model} = require('mongorito');
const timestamps = require('mongorito-timestamps');

class Post extends Model {}

const db = new Database('localhost/blog');
await db.connect();

db.use(timestamps());
db.register(Post);

const post = new Post({title: 'Hello'});
await post.save();

post.get('created_at');
//=> 2017-05-17T18:02:06.612Z

post.get('updated_at');
//=> same as `created_at`

post.set({title: 'World'});
await post.save();

post.get('created_at');
//=> same as previous `created_at`

post.get('updated_at');
//=> 2017-05-17T18:02:06.971Z

API

timestamps([options])

Configures and returns a timestamps plugin. Accepts an optional options object to customize field names and a function, which generates the timestamps.

options

createdAt

Type: string
Default: created_at

Name of the field, which stores the date when the document was created. This field doesn't change after the initial creation.

updatedAt

Type: string
Default: updated_at

Name of the field, which stores the date when the document was updated. This field changes on every save of the document.

getTimestamp

Type: function
Default:

const getTimestamp = () => new Date();

Function, which generates a timestamp.

License

MIT © Vadim Demedes

Keywords

mongorito

FAQs

Package last updated on 26 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts