Nuclear Powered Marshmallows

    related-timestamps

    2.0.0 • Public • Published

    related-timestamps

    npm Travis node

    Timestamps / soft-delete extension for the Related ORM. This extension sets automatically timestamps when creating, updating and deleting records. You may select which timestamps to set and what the names of the columns are.

    The extension is only applied to models that have the timestamp columns.

    API

    To add the extension to the orm you have to initialize the extension first.

    var   Related       = require('related')
        , ORMTimestamps = require('related-timestamps');
    
    
    var orm = new Related(dbConfig);
    
    // you may set the names of the columns here, default is created, updated, deleted
    var timestamps = new ORMTimestamps({
          created: 'createdAt'
        , updated: 'modiefiedAt'
        , deleted: 'deletedAt'
    });
    
    // add the extension to the orm
    orm.use(timestamps);
    
    orm.load().then((related) => {
        log('the orm is ready and has now built in timestamp support');
    });
    

    includeSoftDeleted method

    if you have defined the deleted timestamp and a model has a coulmn with that name this method will be added to the querybuilder. It lets you query the database for soft deleted records.

    orm.myDatabase.event(['*']).includeSoftDeleted().limit(100).find(cb);
    

    hardDelete method

    if you have defined the deleted timestamp and a model has a coulmn with that name this method will be added to the model instance. It lets you hard delete the record.

    // soft delete, record marked as deleted
    model.delete(cb);
    
    // hard delete, record atucally deleted
    model.hardDelete(cb);

    Install

    npm i related-timestamps

    DownloadsWeekly Downloads

    7

    Version

    2.0.0

    License

    none

    Last publish

    Collaborators

    • avatar