var _db = require("topsin.database");
var _ = require("lodash");
var _error = require("topsin.error");

var DEMO_CONN = 'DEMO_CONN';
_db.addConnection({
  database_type: 'pg',
  database_host: '139.196.104.13:5433',
  database_name: 'TOPDFM_DEV_V6',
  database_user: 'toplinker',
  database_pwd: 'TopLinker0510'
}, DEMO_CONN);

try {
    _db.query(DEMO_CONN, function(query){
        var r = query.selectArrayMap("SELECT username, department_id FROM sys_user LIMIT 2", {});
        if (query.lastError().isValid()) {
            throw query.lastError().text();
        }
        print(JSON.stringify(r));
        print(JSON.stringify(r, function(k, v){
            return typeof v === 'undefined' ? null : v;
          }));
    });
} catch (e) {
    print(e);
}
