connection.js 1.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
const TDengineCursor = require('./cursor')
const CTaosInterface = require('./cinterface')
module.exports = TDengineConnection;

/*
 * TDengine Connection object
 * @param {Object.<string, string>} options - Options for configuring the connection with TDengine
 * @return {TDengineConnection}
 *
 *
 */
function TDengineConnection(options) {
  this._conn = null;
  this._host = null;
  this._user = "root"; //The default user
  this._password = "taosdata"; //The default password
  this._database = null;
  this._port = 0;
  this._config = null;
  this._chandle = null;
  this.config(options)
  return this;
}

TDengineConnection.prototype.config = function config(options) {
  if (options['host']) {
    this._host = options['host'];
  }
  if (options['user']) {
    this._user = options['user'];
  }
  if (options['password']) {
    this._password = options['password'];
  }
  if (options['database']) {
    this._database = options['database'];
  }
  if (options['port']) {
    this._port = options['port'];
  }
  if (options['config']) {
    this._config = options['config'];
  }
  this._chandle = new CTaosInterface(this._config);
  this._conn = this._chandle.connect(this._host, this._user, this._password, this._database, this._port);
}

TDengineConnection.prototype.close = function close() {
  return this._chandle.close(this._conn);
}
TDengineConnection.prototype.cursor = function cursor() {
  //Pass the connection object to the cursor
  return new TDengineCursor(this);
}
TDengineConnection.prototype.commit = function commit() {
  return this;
}
TDengineConnection.prototype.rollback = function rollback() {
  return this;
}
TDengineConnection.prototype.clear_result_set = function clear_result_set() {
  var result = this._chandle.useResult(this._conn).result;
  if (result) {
    this._chandle.freeResult(result)
  }
}