A lightweight data access tool supporting Postgres and MySql today.
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.
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 = mapperschema;schemaBuilderadd"customers" "customerid"hasManyWithMany"addresses" "customeraddresses" "addressid"hasOne"profile" "profiles"saveadd"addresses" "addressid"saveadd"profiles"save;
And lastly tell it what engine you want to use and how to connect to the database:
var db = mapperinit"mysql" connString schemaBuilderschema;
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.
You can also pass in one or more parameters.
dbfindname: "brad" email: "email@example.com"in"customers"executeconsole.logresult0name;;
You can also tell it to load up the addresses for records matching your query.
Nothing really special here.
dbinsertname: "new" email: "firstname.lastname@example.org"in"customers"execute//do something here;
Yeah, you can update stuff as well.
dbupdatename: "updated"in"customers"where"customerid >": 1execute//do something here;
And just in case you have to get rid of some things you can do that too.
dbdelete"customerid >": 2in"customers"executeassertequalerr null;done;;