var fs = require("fs");
var _ = require("lodash");
var moment = require("moment");
var logger = require("topsin.logger");
var crypto = require("topsin.crypto");
var DB = require("topsin.database");
var error = require("topsin.error");
var console = require("console");
var httpFunc = require("topsin.httpfunc");
var REQ = httpFunc.argv().request;
var RES = httpFunc.argv().response;
var response = new (require("topsin.responsedata"))();

try {
  var UTCERP_DB_CONN = 'UTCERP_DB_CONN';
  DB.addConnection({
    database_type: "mssql",
    database_host: "10.3.1.250\\MSSQLSERVER",
    database_name: "Unitech3",
    database_user: "TopLinker",
    database_pwd: "837914",
    database_driver: "/usr/local/freetds/lib/libtdsodbc.so.0"
  }, UTCERP_DB_CONN);
  var query = DB.query(UTCERP_DB_CONN);
  var sql = "select MatName,Gauge from MTL_ItemMaster where MatCode = '08634Z0506'";
  var dataList = query.selectArrayMap(sql, {});
  response.setData(dataList);
  RES.body(response.toJson());
} catch(e) {
  response.setErrText(_.toString(e));
  RES.badRequest(response.toJson());
}