testMicroseconds.js 1.2 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
const taos = require('../tdengine');
var conn = taos.connect();
var c1 = conn.cursor();
let stime = new Date();
let interval = 1000;

function convertDateToTS(date) {
  let tsArr = date.toISOString().split("T")
  return "\"" + tsArr[0] + " " + tsArr[1].substring(0, tsArr[1].length - 1) + "\"";
}
function R(l, r) {
  return Math.random() * (r - l) - r;
}
function randomBool() {
  if (Math.random() < 0.5) {
    return true;
  }
  return false;
}

// Initialize
//c1.execute('drop database td_connector_test;');
const dbname = 'nodejs_test_us';
c1.execute('create database if not exists ' + dbname + ' precision "us"');
c1.execute('use ' + dbname)
c1.execute('create table if not exists tstest (ts timestamp, _int int);');
c1.execute('insert into tstest values(1625801548423914, 0)');
// Select
console.log('select * from tstest');
c1.execute('select * from tstest');

var d = c1.fetchall();
console.log(c1.fields);
let ts = d[0][0];
console.log(ts);

if (ts.taosTimestamp() != 1625801548423914) {
  throw "microseconds not match!";
}
if (ts.getMicroseconds() % 1000 !== 914) {
  throw "micronsecond precision error";
}
setTimeout(function () {
  c1.query('drop database nodejs_us_test;');
}, 200);

setTimeout(function () {
  conn.close();
}, 2000);