pg-dal

0.0.2 • Public • Published

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(myValidation);
item = itemDal.build({name: 'wheel'});
item.save(function(err, item){
  if(err){
    console.log(err.message);
    // will log Don't add wheels
  }
});

/pg-dal/

    Package Sidebar

    Install

    npm i pg-dal

    Weekly Downloads

    3

    Version

    0.0.2

    License

    none

    Last publish

    Collaborators

    • sipajahava