var DB = require("topsin.database");
var _ = require("lodash");
var TError = require("topsin.error");
var logger = require('topsin.logger')
var moment = require('moment')


DB.addConnection({
  database_type: 'mysql',
  database_host: '192.168.2.22:3306',
  database_name: 'topbi',
  database_user: 'toplinker',
  database_pwd: 'TopLinker0510'
}, 'DEMO_CONN');

try {
  var result = DB.query('DEMO_CONN', function (query) {
    // 测试连接
    var ok = query.selectValue("SELECT 1", {});
    if (query.lastError().isValid()) {
      throw query.lastError().text();
    }
    print("ok: ", ok);
    // 测试prepare
    query.replaceRow({
      table: 'test',
      data: {
        // create_time: '2019-07-16 00:09:00',
        Date: '2019-07-16 00:00:00',
        // RUN: '0'
      },
      unique_field: 'id'
    });
    if (query.lastError().isValid()) {
      throw query.lastError().text();
    }
  })
} catch (e) {
  print(e);
}
