提交 6b582a78 编写于 作者: Z zyyang-taosdata

[TD-1722]<hotfix>: fix dynamic link error for win32

上级 edadef71
const TDengineCursor = require('./cursor')
const CTaosInterface = require('./cinterface')
const TDengineCursor = require('./cursor');
const CTaosInterface = require('./cinterface');
module.exports = TDengineConnection;
/**
......@@ -14,61 +14,62 @@ module.exports = 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._configConn(options)
return this;
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._configConn(options)
return this;
}
/**
* Configure the connection to TDengine
* @private
* @memberof TDengineConnection
*/
TDengineConnection.prototype._configConn = function _configConn(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);
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);
}
/** Close the connection to TDengine */
TDengineConnection.prototype.close = function close() {
this._chandle.close(this._conn);
this._chandle.close(this._conn);
}
/**
* Initialize a new cursor to interact with TDengine with
* @return {TDengineCursor}
*/
TDengineConnection.prototype.cursor = function cursor() {
//Pass the connection object to the cursor
return new TDengineCursor(this);
//Pass the connection object to the cursor
return new TDengineCursor(this);
}
TDengineConnection.prototype.commit = function commit() {
return this;
return this;
}
TDengineConnection.prototype.rollback = function rollback() {
return this;
return this;
}
/**
* Clear the results from connector
......
......@@ -563,6 +563,11 @@
"wrappy": "1"
}
},
"os": {
"version": "0.1.1",
"resolved": "https://registry.npm.taobao.org/os/download/os-0.1.1.tgz",
"integrity": "sha1-IIhF6J4ZOtTZcUdLk5R3NqVtE/M="
},
"path-is-absolute": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
......
......@@ -17,6 +17,7 @@
"dependencies": {
"ffi": "^2.3.0",
"node-gyp": "^5.0.2",
"os": "^0.1.1",
"ref": "^1.3.5",
"ref-array": "^1.2.0"
},
......
var TDengineConnection = require('./nodetaos/connection.js')
module.exports.connect = function (connection=null) {
return new TDengineConnection(connection);
}
var TDengineConnection = require('./nodetaos/connection.js');
module.exports.connect = function (connection = null) {
return new TDengineConnection(connection);
};
const taos = require('../tdengine');
// establish connection
var conn = taos.connect({host: "192.168.1.59", user: "root", password: "taosdata", port: 6030});
var cursor = conn.cursor();
// create database
executeSql("create database if not exists jschecker", 0);
// use db
executeSql("use jschecker", 0);
// drop table
executeSql("drop table if exists jschecker.weather", 0);
// create table
executeSql("create table if not exists jschecker.weather(ts timestamp, temperature float, humidity int)", 0);
// insert
executeSql("insert into jschecker.weather (ts, temperature, humidity) values(now, 20.5, 34)", 1);
// select
executeQuery("select * from jschecker.weather");
// close connection
conn.close();
function executeQuery(sql) {
var start = new Date().getTime();
var promise = cursor.query(sql, true);
var end = new Date().getTime();
printSql(sql, promise != null, (end - start));
promise.then(function (result) {
result.pretty();
});
}
function executeSql(sql, affectRows) {
var start = new Date().getTime();
var promise = cursor.execute(sql);
var end = new Date().getTime();
printSql(sql, promise == affectRows, (end - start));
}
function printSql(sql, succeed, cost) {
console.log("[ " + (succeed ? "OK" : "ERROR!") + " ] time cost: " + cost + " ms, execute statement ====> " + sql);
}
function memoryUsageData() {
let s = process.memoryUsage()
for (key in s) {
s[key] = (s[key]/1000000).toFixed(3) + "MB";
}
return s;
let s = process.memoryUsage();
for (key in s) {
s[key] = (s[key] / 1000000).toFixed(3) + "MB";
}
return s;
}
console.log("initial mem usage:", memoryUsageData());
const { PerformanceObserver, performance } = require('perf_hooks');
const {PerformanceObserver, performance} = require('perf_hooks');
const taos = require('../tdengine');
var conn = taos.connect({host:"127.0.0.1", user:"root", password:"taosdata", config:"/etc/taos",port:0});
var conn = taos.connect({host: "127.0.0.1", user: "root", password: "taosdata", config: "/etc/taos", port: 0});
var c1 = conn.cursor();
// Initialize env
......@@ -25,65 +26,69 @@ var insertTime = 0;
var insertTime5000 = 0;
var avgInsert5ktime = 0;
const obs = new PerformanceObserver((items) => {
let entry = items.getEntries()[0];
let entry = items.getEntries()[0];
if (entry.name == 'Data Prep') {
dataPrepTime += entry.duration;
}
else if (entry.name == 'Insert'){
insertTime += entry.duration
}
else {
console.log(entry.name + ': ' + (entry.duration/1000).toFixed(8) + 's');
}
performance.clearMarks();
if (entry.name == 'Data Prep') {
dataPrepTime += entry.duration;
}
else if (entry.name == 'Insert') {
insertTime += entry.duration
}
else {
console.log(entry.name + ': ' + (entry.duration / 1000).toFixed(8) + 's');
}
performance.clearMarks();
});
obs.observe({ entryTypes: ['measure'] });
obs.observe({entryTypes: ['measure']});
function R(l,r) {
return Math.random() * (r - l) - r;
function R(l, r) {
return Math.random() * (r - l) - r;
}
function randomBool() {
if (Math.random() < 0.5) {
return true;
}
return false;
if (Math.random() < 0.5) {
return true;
}
return false;
}
function insertN(n) {
for (let i = 0; i < n; i++) {
performance.mark('A3');
let insertData = ["now + " + i + "m", // Timestamp
parseInt( R(-Math.pow(2,31) + 1 , Math.pow(2,31) - 1) ), // Int
parseInt( R(-Math.pow(2,31) + 1 , Math.pow(2,31) - 1) ), // BigInt
parseFloat( R(-3.4E38, 3.4E38) ), // Float
parseFloat( R(-1.7E308, 1.7E308) ), // Double
"\"Long Binary\"", // Binary
parseInt( R(-32767, 32767) ), // Small Int
parseInt( R(-127, 127) ), // Tiny Int
randomBool(),
"\"Nchars 一些中文字幕\""]; // Bool
let query = 'insert into td_connector_test.all_types values(' + insertData.join(',') + ' );';
performance.mark('B3');
performance.measure('Data Prep', 'A3', 'B3');
performance.mark('A2');
c1.execute(query, {quiet:true});
performance.mark('B2');
performance.measure('Insert', 'A2', 'B2');
if ( i % 5000 == 4999) {
console.log("Insert # " + (i+1));
console.log('Insert 5k records: ' + ((insertTime - insertTime5000)/1000).toFixed(8) + 's');
insertTime5000 = insertTime;
avgInsert5ktime = (avgInsert5ktime/1000 * Math.floor(i / 5000) + insertTime5000/1000) / Math.ceil( i / 5000);
console.log('DataPrepTime So Far: ' + (dataPrepTime/1000).toFixed(8) + 's | Inserting time So Far: ' + (insertTime/1000).toFixed(8) + 's | Avg. Insert 5k time: ' + avgInsert5ktime.toFixed(8));
for (let i = 0; i < n; i++) {
performance.mark('A3');
let insertData = ["now + " + i + "m", // Timestamp
parseInt(R(-Math.pow(2, 31) + 1, Math.pow(2, 31) - 1)), // Int
parseInt(R(-Math.pow(2, 31) + 1, Math.pow(2, 31) - 1)), // BigInt
parseFloat(R(-3.4E38, 3.4E38)), // Float
parseFloat(R(-1.7E308, 1.7E308)), // Double
"\"Long Binary\"", // Binary
parseInt(R(-32767, 32767)), // Small Int
parseInt(R(-127, 127)), // Tiny Int
randomBool(),
"\"Nchars 一些中文字幕\""]; // Bool
let query = 'insert into td_connector_test.all_types values(' + insertData.join(',') + ' );';
performance.mark('B3');
performance.measure('Data Prep', 'A3', 'B3');
performance.mark('A2');
c1.execute(query, {quiet: true});
performance.mark('B2');
performance.measure('Insert', 'A2', 'B2');
if (i % 5000 == 4999) {
console.log("Insert # " + (i + 1));
console.log('Insert 5k records: ' + ((insertTime - insertTime5000) / 1000).toFixed(8) + 's');
insertTime5000 = insertTime;
avgInsert5ktime = (avgInsert5ktime / 1000 * Math.floor(i / 5000) + insertTime5000 / 1000) / Math.ceil(i / 5000);
console.log('DataPrepTime So Far: ' + (dataPrepTime / 1000).toFixed(8) + 's | Inserting time So Far: ' + (insertTime / 1000).toFixed(8) + 's | Avg. Insert 5k time: ' + avgInsert5ktime.toFixed(8));
}
}
}
}
performance.mark('insert 1E5')
insertN(1E5);
performance.mark('insert 1E5 2')
performance.measure('Insert With Logs', 'insert 1E5', 'insert 1E5 2');
console.log('DataPrepTime: ' + (dataPrepTime/1000).toFixed(8) + 's | Inserting time: ' + (insertTime/1000).toFixed(8) + 's');
dataPrepTime = 0; insertTime = 0;
console.log('DataPrepTime: ' + (dataPrepTime / 1000).toFixed(8) + 's | Inserting time: ' + (insertTime / 1000).toFixed(8) + 's');
dataPrepTime = 0;
insertTime = 0;
//'insert into td_connector_test.all_types values (now, null,null,null,null,null,null,null,null,null);'
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册