# related-timestamps

> Timestamps / soft-delete extension for the related package

Latest version **2.0.0** (published 2015-11-26) · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install related-timestamps
pnpm add related-timestamps
yarn add related-timestamps
bun add related-timestamps
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2015-11-26 |
| First published | 2015-04-02 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=v4 |
| Dependencies | 5 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Michael van der Weg |
| Maintainers | ee |
| Keywords | related, orm, extension, timestamps, soft-delete |

## Links

- npm: https://www.npmjs.com/package/related-timestamps
- Repository: https://github.com/eventEmitter/relatedtimestamps
- Homepage: https://github.com/eventEmitter/related-timestamps
- Issues: https://github.com/eventEmitter/related-timestamps/issues
- npm.io page: https://npm.io/package/related-timestamps

## Dependencies (5)

- [ee-log](https://npm.io/package/ee-log.md) 0.3.x
- [ee-class](https://npm.io/package/ee-class.md) 1.x
- [ee-types](https://npm.io/package/ee-types.md) 1.x
- [ee-event-emitter](https://npm.io/package/ee-event-emitter.md) 0.3.x
- [related-extension](https://npm.io/package/related-extension.md) 1.x

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2015-11-26
- 1.0.2 — 2015-10-29
- 1.0.1 — 2015-10-29
- 1.0.0 — 2015-10-29
- 0.4.1 — 2015-05-31
- 0.4.0 — 2015-04-02

## README

# related-timestamps

[![npm](https://img.shields.io/npm/dm/related-timestamps.svg?style=flat-square)](https://www.npmjs.com/package/related-timestamps)
[![Travis](https://img.shields.io/travis/eventEmitter/related-timestamps.svg?style=flat-square)](https://travis-ci.org/eventEmitter/related-timestamps)
[![node](https://img.shields.io/node/v/related-timestamps.svg?style=flat-square)](https://nodejs.org/)


Timestamps / soft-delete extension for the [Related ORM](https://www.npmjs.com/package/related). 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);

---
_Source: https://npm.io/package/related-timestamps · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
