# related

> Unopinionated ORM for relational databases

Latest version **2.16.5** (published 2022-05-02) · MIT license · 0 weekly downloads

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

## Install

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

Provides the command `related`.

## Health

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

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.16.5 |
| Published | 2022-05-02 |
| First published | 2014-11-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6 |
| Dependencies | 10 |
| Unpacked size | 392 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 23 |
| Author | Lina van der Weg |
| Maintainers | ee |
| Keywords | orm, mysql, postgres, object relational mapper, eager loading, connection pooling, cluster |

## Links

- npm: https://www.npmjs.com/package/related
- Repository: https://github.com/linaGirl/related
- Issues: https://github.com/linaGirl/related/issues
- npm.io page: https://npm.io/package/related

## Dependencies (10)

- [ee-log](https://npm.io/package/ee-log.md) ^3.0.5
- [ee-argv](https://npm.io/package/ee-argv.md) ^0.1.4
- [ee-class](https://npm.io/package/ee-class.md) ^1.4.0
- [ee-types](https://npm.io/package/ee-types.md) ^2.1.4
- [test-config](https://npm.io/package/test-config.md) ^0.1.1
- [async-method](https://npm.io/package/async-method.md) ^0.1.1
- [ee-arguments](https://npm.io/package/ee-arguments.md) ^1.0.4
- [ee-event-emitter](https://npm.io/package/ee-event-emitter.md) ^0.3.1
- [related-db-cluster](https://npm.io/package/related-db-cluster.md) ^2.2.16
- [related-query-context](https://npm.io/package/related-query-context.md) ^2.1.1

## 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.16.5 (latest) — 2022-05-02
- 2.16.4 — 2022-05-02
- 2.16.3 — 2022-04-29
- 2.16.2 — 2022-04-29
- 2.16.1 — 2021-03-19
- 2.16.0 — 2018-07-14
- 2.15.2 — 2018-07-08
- 2.15.1 — 2018-07-08
- 2.15.0 — 2018-01-18
- 2.14.0 — 2018-01-15
- 2.13.4 — 2018-01-11
- 2.13.3 — 2017-09-27
- 2.13.2 — 2017-08-24
- 2.13.1 — 2017-07-03
- 2.13.0 — 2017-07-02
- … 98 more at https://npm.io/package/related/versions

## README

# Related ORM

ORM for relational databases.


[![npm](https://img.shields.io/npm/dm/related.svg?style=flat-square)](https://www.npmjs.com/package/related)
[![Travis](https://img.shields.io/travis/eventEmitter/related.svg?style=flat-square)](https://travis-ci.org/eventEmitter/related)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://raw.githubusercontent.com/eventEmitter/related/master/LICENSE)
[![node](https://img.shields.io/node/v/related.svg?style=flat-square)](https://nodejs.org/)



On the fly builds an extensive API representing your database and its tables including their relations and columns. No need to write javascript models.


**Features**
- Supports Postgres & MySQL
- Simple loading and filtering of nested entities
- Advanced query builder that rocks
- Transactions
- Table locks
- Bulk operations
- User extendable models (optional)
- Connection pooling
- Extensions for soft-deletes, nested sets, multilingual content, geo distance computation and reference counting
- Complex DB Cluster support (includes read replicas and failover on AWS RDS)
- No conventions for column names etc.
- Commercial support avialable
- And much more


````
var Related = require('related');

// The ORM looks at your database and builds on the fly models. 
// You can start working on your database immediatelly. 
new Related({
      schema        : 'mySchemaName' // optional
    , database      : 'myDatabaseName'
    , type          : 'postgres'     // or mysql
    , hosts: [{
          host      : 'localhost'
        , username  : 'postgres'
        , password  : ''
        , maxConnections: 20
        , pools     : ['master', 'read', 'write']
    }]    
}).load().then(function(orm) {


    // get 10 events, their images, their tags, their categories, their venues,
    // the venues images, the venues types. the 'get' prefix change sscope to the other model
    // the 'fetch' prefix doenst change the scope and you can continue working on the current
    // model
    orm.event({id: Related.lt(2000)}, ['*'])
        .fetchImage(['url'])
        .fetchTag(['name'])
        .fetchCategory(['name'])
        .getVenue(['*'])
        .fetchImage(['url'])
        .fetchVenueType(['name'])
        .limit(10)
        .find().then(function(events) {

        log(events);
    }).catch(function(err) {

        log('something went wrong :(');
    });
});
````


## API

We are currently working on an extensive documentation and a website. Until those are online please look at the [tests](https://github.com/eventEmitter/related/blob/master/test/orm.js) 


### Extensions

- ***[Timestamps](https://www.npmjs.com/package/related-timestamps):*** support for automatic timestamps and soft deletes 
- ***[GEO](https://www.npmjs.com/package/related-geo):*** Area and distance searches using longitutde and latitude
- ***[Localization](https://www.npmjs.com/package/related-localization):*** support for multilanguage content in the relational model
- ***[Nested Sets](https://www.npmjs.com/package/related-nested-set):*** support for [nested sets](https://en.wikipedia.org/wiki/Nested_set_model) 
- ***[Reference Counting](https://www.npmjs.com/package/related-reference-counter):*** Counts items that are referenced by the current entity

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