var DB = require("topsin.database");
var moment = require("moment");

function pause(millseconds) {
  var start = moment();
  var end = null;
  do {
    end = moment();
  } while (end.diff(start) < millseconds);
}

DB.addConnection({
  database_type: 'pg',
  database_host: '192.168.2.22',
  database_name: 'TOPMES_ATC_LASER_DEV',
  database_user: 'postgres',
  database_pwd: 'TopLinker0510'
}, 'DEMO_CONN');

var query = DB.query("DEMO_CONN");
query.begin();

try {
  query.insertRow({
    table: 'sys_user',
    data: { username: 'dirty0724' }
  });
  
  var result = query.selectArrayMap({
    table: 'sys_user'
  });
  print(JSON.stringify(result, null, "  "));

  print("Pause 120 Seconds");
  pause(1 * 60 * 1000);
  print("End.");

  query.commit();
} catch (e) {
  query.rollback();
  print(e);
}
