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:
SELECT bs.bikeShopID, bs.name, bs.address, s.staffID, s.firstName, s.lastNameFROM bike_shops bsINNER JOIN staff s ON bs.bikeShopID = s.bikeShopIDORDER BY bs.name, s.firstName
and makes them look like this:
dataContext
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:
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
- Selecting
- Inserting
- Deleting
- Updating
- Schema Objects (Global Property Names and Conversions)