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


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?
##### Table of Contents
- Getting Started
- Example Database Setup
- Installing and Connecting
- Selecting
- Select all from a Single Table
- Limiting Columns
- Ad-Hoc Mapping
- Ordering
- Ad-Hoc Converters
- Conditions I
- Conditions II
- Joins
- Inserting
- Create a Single Model
- Create Multiple Models
- Deleting
- Delete a Single Model
- Delete Multiple Models
- Delete Using a From Instance
- Updating
- Update a Single Model
- Update Multiple Models
- Updating Using a From Instance
- Schema Objects (Global Property Names and Conversions)
- Schema Generation Overview
- Customizing Names (Mapping)
- Converters