node package manager


A lightweight data access tool supporting Postgres and MySql today.

Okay, so what is it?

data-mapper-js is a little bit more than massive-js, but not so much that it gets in your way. Initially I was going to try and just extend massive-js to meet my needs, but my approach seemed different enough from that of massive-js that I gave birth to data-mapper-js. Currently it supports MySql and Postgres, but you should find it easily extensible, if you are so inclined.

How do I get started?

I wasn't going to, but I went ahead and registered the package so installation is as easy as:

npm install data-mapper-js

Then just this to start using it:

var mapper = require("data-mapper-js");

The important part, if you are trying to wire up any relational data queries, is to define the schema.

var schemaBuilder = mapper.schema();
        .add("customers", "customerid")
            .hasManyWithMany("addresses", "customeraddresses", "addressid")
            .hasOne("profile", "profiles")
        .add("addresses", "addressid").save()

And lastly tell it what engine you want to use and how to connect to the database:

var db = mapper.init("mysql", connString, schemaBuilder.schema);


The query syntax is borrowed almost exactly from massive-js, but we don't build the tables for you.

A quick query to pull all the records in the customers table.

db.find().in("customers").execute(function(err, result) {

You can also pass in one or more parameters.

db.find({name: "brad", email: ""}).in("customers").execute(function(err, result) {

You can also tell it to load up the addresses for records matching your query.

db.find({name: "bobcat"}).in("customers").load("addresses").execute(function(err, result) {


Nothing really special here.

db.insert({name: "new", email: ""}).in("customers").execute(function(err, result) {
    //do something here 


Yeah, you can update stuff as well.

db.update({name: "updated"}).in("customers").where({"customerid >": 1}).execute(function(err, result) {
    //do something here 


And just in case you have to get rid of some things you can do that too.

db.delete({"customerid >": 2}).in("customers").execute(function(err, result) {
    assert.equal(err, null);