Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    pg-dalpublic

    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 
      }
    });

    Keywords

    none

    install

    npm i pg-dal

    Downloadsweekly downloads

    1

    version

    0.0.2

    license

    none

    repository

    github.com

    last publish

    collaborators

    • avatar