0.0.2 • Published 11 years ago

pg-dal v0.0.2

Weekly downloads
9
License
-
Repository
github
Last release
11 years ago

pg-dal

Simple Postgres Data access layer for node.js

Examples

Creating Records

var Dal = require('pg-dal');
var pgConfig = {
  user: 'dbuser',
  password: 'password',
  database: 'mydb',
  host: 'localhost',
  port: 5432
};
var sanitizeColumns = ['id', 'name', 'size'];
var defaults = {
  size: 'Large'
};
var itemDal = new Dal('items', pgConfig, sanitizeColumns, defaults, function(){
  console.log('created dal!');
});
item = itemDal.build({name: 'wheel'});
item.save(function(err, item){
  console.log('wheel saved!');
});

Custom Validation

var myValidation = function(item, next){
  var err = null;
  if(item.name === 'wheel'){
    err = new Error('Don\'t add wheels');
  }
  next(err);
};
itemDal.validation(function);
item = itemDal.build({name: 'wheel'});
item.save(function(err, item){
  if(err){
    console.log(err.message);
    // will log Don't add wheels
  }
});