# node-data-mapper

> An object-relational mapper for node.js using the data mapper pattern.

Latest version **1.1.27** (published 2018-06-05) · ISC license · 0 weekly downloads

## Install

```sh
npm install node-data-mapper
pnpm add node-data-mapper
yarn add node-data-mapper
bun add node-data-mapper
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.27 |
| Published | 2018-06-05 |
| First published | 2015-12-19 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 4.5 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Ben Botto |
| Maintainers | avejidah |

## Links

- npm: https://www.npmjs.com/package/node-data-mapper
- Repository: https://github.com/benbotto/node-data-mapper
- Homepage: https://github.com/benbotto/node-data-mapper#readme
- Issues: https://github.com/benbotto/node-data-mapper/issues
- npm.io page: https://npm.io/package/node-data-mapper

## Dependencies (5)

- [glob](https://npm.io/package/glob.md) ^7.1.1
- [moment](https://npm.io/package/moment.md) ^2.13.0
- [insulin](https://npm.io/package/insulin.md) ^1.0.7
- [deferred](https://npm.io/package/deferred.md) ^0.7.4
- [bsy-error](https://npm.io/package/bsy-error.md) ^1.0.4

## Recent versions

- 1.1.27 (latest) — 2018-06-05
- 1.1.17 (dev) — 2017-02-04
- 1.1.26 — 2018-05-07
- 1.1.25 — 2017-07-24
- 1.1.24 — 2017-07-08
- 1.1.23 — 2017-07-06
- 1.1.22 — 2017-05-05
- 1.1.21 — 2017-04-08
- 1.1.20 — 2017-04-08
- 1.1.19 — 2017-02-14
- 1.1.18 — 2017-02-10
- 1.1.16 — 2017-02-04
- 1.1.15 — 2017-01-04
- 1.1.14 — 2017-01-01
- 1.1.12 — 2016-12-31
- … 30 more at https://npm.io/package/node-data-mapper/versions

## README

[![Build Status](https://travis-ci.org/benbotto/node-data-mapper.svg?branch=1.1.x)](https://travis-ci.org/benbotto/node-data-mapper)
[![Coverage Status](https://coveralls.io/repos/benbotto/node-data-mapper/badge.svg?branch=1.1.x&service=github)](https://coveralls.io/github/benbotto/node-data-mapper?branch=1.1.x)

# node-data-mapper

node-data-mapper in object-relational mapper for Node.js.  It uses the data-mapper pattern.

##### What does it do?

It takes queries that look like this:

```sql
SELECT  bs.bikeShopID, bs.name, bs.address,
        s.staffID, s.firstName, s.lastName
FROM    bike_shops bs
INNER JOIN staff s ON bs.bikeShopID = s.bikeShopID
ORDER BY bs.name, s.firstName
```
and makes them look like this:

```js
dataContext
  .from('bike_shops bs')
  .innerJoin('bs.staff s')
  .select(
    'bs.bikeShopID', 'bs.name', 'bs.address',
    's.staffID', 's.firstName', 's.lastName')
  .orderBy('bs.name', 's.firstName')
```

It maps relational, tabular data that look like this:

bikeShopID|name|address|staffID|firstName|lastName
---|---|---|---|---|---
1|Bob's Bikes|9107 Sunrise Blvd|2|John|Stovall
1|Bob's Bikes|9107 Sunrise Blvd|1|Randy|Alamedo
1|Bob's Bikes|9107 Sunrise Blvd|3|Tina|Beckenworth
3|Cycle Works|3100 La Riviera Wy|7|Kimberly|Fenters
3|Cycle Works|3100 La Riviera Wy|8|Michael|Xavier
3|Cycle Works|3100 La Riviera Wy|5|Sal|Green
3|Cycle Works|3100 La Riviera Wy|6|Valerie|Stocking
2|Zephyr Cove Cruisers|18271 Highway 50|4|Abe|Django

to a normalized document like this:

```js
[ { bikeShopID: 1,
    name: 'Bob\'s Bikes',
    address: '9107 Sunrise Blvd',
    staff: 
     [ { staffID: 2, firstName: 'John', lastName: 'Stovall' },
       { staffID: 1, firstName: 'Randy', lastName: 'Alamedo' },
       { staffID: 3, firstName: 'Tina', lastName: 'Beckenworth' } ] },
  { bikeShopID: 3,
    name: 'Cycle Works',
    address: '3100 La Riviera Wy',
    staff: 
     [ { staffID: 7, firstName: 'Kimberly', lastName: 'Fenters' },
       { staffID: 8, firstName: 'Michael', lastName: 'Xavier' },
       { staffID: 5, firstName: 'Sal', lastName: 'Green' },
       { staffID: 6, firstName: 'Valerie', lastName: 'Stocking' } ] },
  { bikeShopID: 2,
    name: 'Zephyr Cove Cruisers',
    address: '18271 Highway 50',
    staff: [ { staffID: 4, firstName: 'Abe', lastName: 'Django' } ] } ]
```

##### Why should I use it?

* It's fast.
* The code is well documented and thoroughly tested.
* Tutorials and documentation help you to get started quickly.
* It works well with existing projects and databases.
* The query interface is intuitive and closely resembles SQL.
* Unlike other ORMs, there's no need to define models.
* Queries use plain ol' JavaScript objects and arrays.
* Security concerns like SQL injection are covered.
* CRUD operations can be reused.  Create a select query, and use the same query for updates and deletes.
* It lets you easily create queries that can be filtered and ordered dynamically.
* There are hooks for global conversions and transformations, like normalizing dates and formatting phone numbers.
* Database modifications show up immediately.  If you add a column to the database, you don't have to change any code.
* It eliminates incosistent property names, which is a common problem in APIs.

##### How do I get started?

[Go check out the tutorials!](https://benbotto.github.io/doc/node-data-mapper/1.1.x/tutorial-000%20-%20Example%20Database%20Setup.html)

##### Table of Contents

- Getting Started
  - [Example Database Setup](https://benbotto.github.io/doc/node-data-mapper/1.1.x/tutorial-000%20-%20Example%20Database%20Setup.html)
  - [Installing and Connecting](https://benbotto.github.io/doc/node-data-mapper/1.1.x/tutorial-001%20-%20Installing%20and%20Connecting.html)
- Selecting
  - [Select all from a Single Table](https://benbotto.github.io/doc/node-data-mapper/1.1.x/tutorial-002%20-%20Select%20-%20Select%20all%20from%20a%20Single%20Table.html)
  - [Limiting Columns](https://benbotto.github.io/doc/node-data-mapper/1.1.x/tutorial-003%20-%20Select%20-%20Limiting%20Columns.html)
  - [Ad-Hoc Mapping](https://benbotto.github.io/doc/node-data-mapper/1.1.x/tutorial-004%20-%20Select%20-%20Ad-Hoc%20Mapping.html)
  - [Ordering](https://benbotto.github.io/doc/node-data-mapper/1.1.x/tutorial-005%20-%20Select%20-%20Ordering.html)
  - [Ad-Hoc Converters](https://benbotto.github.io/doc/node-data-mapper/1.1.x/tutorial-006%20-%20Select%20-%20Ad-Hoc%20Converters.html)
  - [Conditions I](https://benbotto.github.io/doc/node-data-mapper/1.1.x/tutorial-007%20-%20Select%20-%20Conditions.html)
  - [Conditions II](https://benbotto.github.io/doc/node-data-mapper/1.1.x/tutorial-008%20-%20Select%20-%20Conditions.html)
  - [Joins](https://benbotto.github.io/doc/node-data-mapper/1.1.x/tutorial-009%20-%20Select%20-%20Joins.html)
- Inserting
  - [Create a Single Model](https://benbotto.github.io/doc/node-data-mapper/1.1.x/tutorial-010%20-%20Insert%20-%20Create%20a%20Single%20Model.html)
  - [Create Multiple Models](https://benbotto.github.io/doc/node-data-mapper/1.1.x/tutorial-011%20-%20Insert%20-%20Create%20Multiple%20Models.html)
- Deleting
  - [Delete a Single Model](https://benbotto.github.io/doc/node-data-mapper/1.1.x/tutorial-012%20-%20Delete%20-%20Delete%20a%20Single%20Model.html)
  - [Delete Multiple Models](https://benbotto.github.io/doc/node-data-mapper/1.1.x/tutorial-013%20-%20Delete%20-%20Delete%20Multiple%20Models.html)
  - [Delete Using a From Instance](https://benbotto.github.io/doc/node-data-mapper/1.1.x/tutorial-014%20-%20Delete%20-%20Delete%20Using%20a%20From%20Instance.html)
- Updating
  - [Update a Single Model](https://benbotto.github.io/doc/node-data-mapper/1.1.x/tutorial-015%20-%20Update%20-%20Update%20a%20Single%20Model.html)
  - [Update Multiple Models](https://benbotto.github.io/doc/node-data-mapper/1.1.x/tutorial-016%20-%20Update%20-%20Update%20Multiple%20Models.html)
  - [Updating Using a From Instance](https://benbotto.github.io/doc/node-data-mapper/1.1.x/tutorial-017%20-%20Update%20-%20Updating%20Using%20a%20From%20Instance.html)
- Schema Objects (Global Property Names and Conversions)
  - [Schema Generation Overview](https://benbotto.github.io/doc/node-data-mapper/1.1.x/tutorial-018%20-%20Schema%20-%20Schema%20Generation%20Overview.html)
  - [Customizing Names (Mapping)](https://benbotto.github.io/doc/node-data-mapper/1.1.x/tutorial-019%20-%20Schema%20-%20Customizing%20Names%20.html)
  - [Converters](https://benbotto.github.io/doc/node-data-mapper/1.1.x/tutorial-020%20-%20Schema%20-%20Converters.html)

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