From 1741d9abebec4c8c45c7be2153cfd30a356627e4 Mon Sep 17 00:00:00 2001 From: liu0x54 Date: Tue, 28 Jul 2020 14:08:05 +0000 Subject: [PATCH 1/6] [TD-1001] adapt nodejs connector to TD 2.0 --- src/connector/nodejs/nodetaos/cinterface.js | 142 +++++++++++++------- src/connector/nodejs/nodetaos/connection.js | 4 +- src/connector/nodejs/nodetaos/cursor.js | 30 +++-- src/connector/nodejs/package-lock.json | 4 +- src/connector/nodejs/package.json | 4 +- src/connector/nodejs/test/test.js | 13 +- 6 files changed, 126 insertions(+), 71 deletions(-) diff --git a/src/connector/nodejs/nodetaos/cinterface.js b/src/connector/nodejs/nodetaos/cinterface.js index d076beb8c0..15502205f4 100644 --- a/src/connector/nodejs/nodetaos/cinterface.js +++ b/src/connector/nodejs/nodetaos/cinterface.js @@ -10,6 +10,7 @@ const Struct = require('ref-struct'); const FieldTypes = require('./constants'); const errors = require ('./error'); const TaosObjects = require('./taosobjects'); +const { NULL_POINTER } = require('ref'); module.exports = CTaosInterface; @@ -25,7 +26,7 @@ function convertTimestamp(data, num_of_rows, nbytes = 0, offset = 0, micro=false if (micro == true) { timestampConverter = convertMicrosecondsToDatetime; } - data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset); + data = ref.reinterpret(data, nbytes * num_of_rows, offset); let res = []; let currOffset = 0; while (currOffset < data.length) { @@ -43,7 +44,7 @@ function convertTimestamp(data, num_of_rows, nbytes = 0, offset = 0, micro=false return res; } function convertBool(data, num_of_rows, nbytes = 0, offset = 0, micro=false) { - data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset); + data = ref.reinterpret(data, nbytes * num_of_rows, offset); let res = new Array(data.length); for (let i = 0; i < data.length; i++) { if (data[i] == 0) { @@ -59,7 +60,7 @@ function convertBool(data, num_of_rows, nbytes = 0, offset = 0, micro=false) { return res; } function convertTinyint(data, num_of_rows, nbytes = 0, offset = 0, micro=false) { - data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset); + data = ref.reinterpret(data, nbytes * num_of_rows, offset); let res = []; let currOffset = 0; while (currOffset < data.length) { @@ -70,7 +71,7 @@ function convertTinyint(data, num_of_rows, nbytes = 0, offset = 0, micro=false) return res; } function convertSmallint(data, num_of_rows, nbytes = 0, offset = 0, micro=false) { - data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset); + data = ref.reinterpret(data, nbytes * num_of_rows, offset); let res = []; let currOffset = 0; while (currOffset < data.length) { @@ -81,7 +82,7 @@ function convertSmallint(data, num_of_rows, nbytes = 0, offset = 0, micro=false) return res; } function convertInt(data, num_of_rows, nbytes = 0, offset = 0, micro=false) { - data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset); + data = ref.reinterpret(data, nbytes * num_of_rows, offset); let res = []; let currOffset = 0; while (currOffset < data.length) { @@ -92,18 +93,18 @@ function convertInt(data, num_of_rows, nbytes = 0, offset = 0, micro=false) { return res; } function convertBigint(data, num_of_rows, nbytes = 0, offset = 0, micro=false) { - data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset); + data = ref.reinterpret(data, nbytes * num_of_rows, offset); let res = []; let currOffset = 0; while (currOffset < data.length) { let d = data.readInt64LE(currOffset); - res.push(d == FieldTypes.C_BIGINT_NULL ? null : BigInt(d)); + res.push(d == FieldTypes.C_BIGINT_NULL ? null : d); currOffset += nbytes; } return res; } function convertFloat(data, num_of_rows, nbytes = 0, offset = 0, micro=false) { - data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset); + data = ref.reinterpret(data, nbytes * num_of_rows, offset); let res = []; let currOffset = 0; while (currOffset < data.length) { @@ -114,7 +115,7 @@ function convertFloat(data, num_of_rows, nbytes = 0, offset = 0, micro=false) { return res; } function convertDouble(data, num_of_rows, nbytes = 0, offset = 0, micro=false) { - data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset); + data = ref.reinterpret(data, nbytes * num_of_rows, offset); let res = []; let currOffset = 0; while (currOffset < data.length) { @@ -125,7 +126,7 @@ function convertDouble(data, num_of_rows, nbytes = 0, offset = 0, micro=false) { return res; } function convertBinary(data, num_of_rows, nbytes = 0, offset = 0, micro=false) { - data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset); + data = ref.reinterpret(data, nbytes * num_of_rows, offset); let res = []; let currOffset = 0; while (currOffset < data.length) { @@ -141,7 +142,7 @@ function convertBinary(data, num_of_rows, nbytes = 0, offset = 0, micro=false) { return res; } function convertNchar(data, num_of_rows, nbytes = 0, offset = 0, micro=false) { - data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset); + data = ref.reinterpret(data, nbytes * num_of_rows, offset); let res = []; let currOffset = 0; // every 4 bytes, a character is encoded; @@ -177,9 +178,10 @@ var char_arr = ArrayType(ref.types.char); var TaosField = Struct({ 'name': char_arr, }); -TaosField.fields.name.type.size = 64; -TaosField.defineProperty('bytes', ref.types.short); +TaosField.fields.name.type.size = 65; TaosField.defineProperty('type', ref.types.char); +TaosField.defineProperty('bytes', ref.types.short); + /** * @@ -202,14 +204,14 @@ function CTaosInterface (config = null, pass = false) { 'taos_connect': [ ref.types.void_ptr, [ ref.types.char_ptr, ref.types.char_ptr, ref.types.char_ptr, ref.types.char_ptr, ref.types.int ] ], //void taos_close(TAOS *taos) 'taos_close': [ ref.types.void, [ ref.types.void_ptr ] ], - //TAOS_RES *taos_use_result(TAOS *taos); - 'taos_use_result': [ ref.types.void_ptr, [ ref.types.void_ptr ] ], + //int *taos_fetch_lengths(TAOS_RES *taos); + 'taos_fetch_lengths': [ ref.types.void_ptr, [ ref.types.void_ptr ] ], //int taos_query(TAOS *taos, char *sqlstr) - 'taos_query': [ ref.types.int, [ ref.types.void_ptr, ref.types.char_ptr ] ], + 'taos_query': [ ref.types.void_ptr, [ ref.types.void_ptr, ref.types.char_ptr ] ], //int taos_affected_rows(TAOS *taos) 'taos_affected_rows': [ ref.types.int, [ ref.types.void_ptr] ], //int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) - 'taos_fetch_block': [ ref.types.int, [ ref.types.void_ptr, ref.types.void_ptr] ], + 'taos_fetch_block': [ ref.types.int, [ ref.types.void_ptr, ref.types.void_ptr2] ], //int taos_num_fields(TAOS_RES *res); 'taos_num_fields': [ ref.types.int, [ ref.types.void_ptr] ], //TAOS_ROW taos_fetch_row(TAOS_RES *res) @@ -329,44 +331,66 @@ CTaosInterface.prototype.query = function query(connection, sql) { CTaosInterface.prototype.affectedRows = function affectedRows(connection) { return this.libtaos.taos_affected_rows(connection); } -CTaosInterface.prototype.useResult = function useResult(connection) { - let result = this.libtaos.taos_use_result(connection); +CTaosInterface.prototype.useResult = function useResult(result) { + let fields = []; let pfields = this.fetchFields(result); if (ref.isNull(pfields) == false) { - pfields = ref.reinterpret(pfields, this.fieldsCount(connection) * 68, 0); + pfields = ref.reinterpret(pfields, this.fieldsCount(result) * 68, 0); for (let i = 0; i < pfields.length; i += 68) { //0 - 63 = name //64 - 65 = bytes, 66 - 67 = type fields.push( { - name: ref.readCString(ref.reinterpret(pfields,64,i)), - bytes: pfields[i + 64], - type: pfields[i + 66] + name: ref.readCString(ref.reinterpret(pfields,65,i)), + type: pfields[i + 65], + bytes: pfields[i + 66] }) } } - return {result:result, fields:fields} + return {fields:fields} } CTaosInterface.prototype.fetchBlock = function fetchBlock(result, fields) { - let pblock = ref.ref(ref.ref(ref.NULL)); // equal to our raw data - let num_of_rows = this.libtaos.taos_fetch_block(result, pblock) - if (num_of_rows == 0) { + let pblock = ref.ref(ref.NULL); // equal to our raw data + pblock = this.libtaos.taos_fetch_row(result); + + if (pblock == 0) { return {block:null, num_of_rows:0}; } let isMicro = (this.libtaos.taos_result_precision(result) == FieldTypes.C_TIMESTAMP_MICRO) - let blocks = new Array(fields.length); - blocks.fill(null); - num_of_rows = Math.abs(num_of_rows); - let offset = 0; - pblock = pblock.deref(); - for (let i = 0; i < fields.length; i++) { + - if (!convertFunctions[fields[i]['type']] ) { + //num_of_rows = Math.abs(num_of_rows); + let offset = 0; + //pblock = pblock.deref(); + + var fieldL = this.libtaos.taos_fetch_lengths(result); + var numoffields = this.libtaos.taos_field_count(result); + + let blocks = new Array(numoffields); + blocks.fill(null); + var fieldlens = []; + + if (ref.isNull(fieldL) == false) { + + for (let i = 0; i < numoffields; i ++) { + let plen = ref.reinterpret(fieldL, 4, i*4); + //plen = ref.readPointer(plen,0,ref.types.int); + let len = plen.readInt32LE(0); + fieldlens.push(len); + //console.log(len); + } + } + for (let i = 0; i < numoffields; i++) { + if (!convertFunctions[fields['fields'][i]['type']] ) { throw new errors.DatabaseError("Invalid data type returned from database"); } - blocks[i] = convertFunctions[fields[i]['type']](pblock, num_of_rows, fields[i]['bytes'], offset, isMicro); - offset += fields[i]['bytes'] * num_of_rows; + prow = ref.reinterpret(pblock,8,i*8); + console.log(fieldlens[i]); + blocks[i] = convertFunctions[fields['fields'][i]['type']](prow, 1, fieldlens[i], 0, isMicro); + console.log('******************************'); + console.log(blocks[i]); + //offset += fields[i]['bytes'] * num_of_rows; } - return {blocks: blocks, num_of_rows:Math.abs(num_of_rows)} + return {blocks: blocks, num_of_rows:1} } CTaosInterface.prototype.fetchRow = function fetchRow(result, fields) { let row = this.libtaos.taos_fetch_row(result); @@ -381,17 +405,17 @@ CTaosInterface.prototype.numFields = function numFields(result) { return this.libtaos.taos_num_fields(result); } // Fetch fields count by connection, the latest query -CTaosInterface.prototype.fieldsCount = function fieldsCount(connection) { - return this.libtaos.taos_field_count(connection); +CTaosInterface.prototype.fieldsCount = function fieldsCount(result) { + return this.libtaos.taos_field_count(result); } CTaosInterface.prototype.fetchFields = function fetchFields(result) { return this.libtaos.taos_fetch_fields(result); } -CTaosInterface.prototype.errno = function errno(connection) { - return this.libtaos.taos_errno(connection); +CTaosInterface.prototype.errno = function errno(result) { + return this.libtaos.taos_errno(result); } -CTaosInterface.prototype.errStr = function errStr(connection) { - return ref.readCString(this.libtaos.taos_errstr(connection)); +CTaosInterface.prototype.errStr = function errStr(result) { + return ref.readCString(this.libtaos.taos_errstr(result)); } // Async CTaosInterface.prototype.query_a = function query_a(connection, sql, callback, param = ref.ref(ref.NULL)) { @@ -411,19 +435,39 @@ CTaosInterface.prototype.fetch_rows_a = function fetch_rows_a(result, callback, let asyncCallbackWrapper = function (param2, result2, numOfRows2) { // Data preparation to pass to cursor. Could be bottleneck in query execution callback times. let row = cti.libtaos.taos_fetch_row(result2); + console.log(row); let fields = cti.fetchFields_a(result2); + + let isMicro = (cti.libtaos.taos_result_precision(result2) == FieldTypes.C_TIMESTAMP_MICRO); let blocks = new Array(fields.length); blocks.fill(null); numOfRows2 = Math.abs(numOfRows2); let offset = 0; + var fieldL = cti.libtaos.taos_fetch_lengths(result); + var fieldlens = []; + if (ref.isNull(fieldL) == false) { + + for (let i = 0; i < fields.length; i ++) { + let plen = ref.reinterpret(fieldL, 8, i*8); + let len = ref.get(plen,0,ref.types.int32); + fieldlens.push(len); + console.log('11111111111111111111'); + console.log(fields.length); + console.log(len); + } + } + if (numOfRows2 > 0){ for (let i = 0; i < fields.length; i++) { if (!convertFunctions[fields[i]['type']] ) { throw new errors.DatabaseError("Invalid data type returned from database"); } - blocks[i] = convertFunctions[fields[i]['type']](row, numOfRows2, fields[i]['bytes'], offset, isMicro); - offset += fields[i]['bytes'] * numOfRows2; + let prow = ref.reinterpret(row,8,i*8); + //blocks[i] = convertFunctions[fields[i]['type']](ref.get(prow,0,ref.types.void_ptr), numOfRows2, fieldlens[i], 0, isMicro); + console.log(prow); + blocks[i] = convertFunctions[fields[i]['type']](ref.readPointer(prow), numOfRows2, fieldlens[i], 0, isMicro); + //offset += fields[i]['bytes'] * numOfRows2; } } callback(param2, result2, numOfRows2, blocks); @@ -440,11 +484,11 @@ CTaosInterface.prototype.fetchFields_a = function fetchFields_a (result) { if (ref.isNull(pfields) == false) { pfields = ref.reinterpret(pfields, 68 * pfieldscount , 0); for (let i = 0; i < pfields.length; i += 68) { - //0 - 63 = name //64 - 65 = bytes, 66 - 67 = type + //0 - 64 = name //65 = type, 66 - 67 = bytes fields.push( { - name: ref.readCString(ref.reinterpret(pfields,64,i)), - bytes: pfields[i + 64], - type: pfields[i + 66] + name: ref.readCString(ref.reinterpret(pfields,65,i)), + type: pfields[i + 65], + bytes: pfields[i + 66] }) } } diff --git a/src/connector/nodejs/nodetaos/connection.js b/src/connector/nodejs/nodetaos/connection.js index bb7651544a..08186f8705 100644 --- a/src/connector/nodejs/nodetaos/connection.js +++ b/src/connector/nodejs/nodetaos/connection.js @@ -74,9 +74,11 @@ TDengineConnection.prototype.rollback = function rollback() { * Clear the results from connector * @private */ -TDengineConnection.prototype._clearResultSet = function _clearResultSet() { +/* + TDengineConnection.prototype._clearResultSet = function _clearResultSet() { var result = this._chandle.useResult(this._conn).result; if (result) { this._chandle.freeResult(result) } } +*/ diff --git a/src/connector/nodejs/nodetaos/cursor.js b/src/connector/nodejs/nodetaos/cursor.js index acfe96dfbc..3f01b2b518 100644 --- a/src/connector/nodejs/nodetaos/cursor.js +++ b/src/connector/nodejs/nodetaos/cursor.js @@ -98,7 +98,7 @@ TDengineCursor.prototype.execute = function execute(operation, options, callback if (this._connection == null) { throw new errors.ProgrammingError('Cursor is not connected'); } - this._connection._clearResultSet(); + this._reset_result(); let stmt = operation; @@ -111,18 +111,18 @@ TDengineCursor.prototype.execute = function execute(operation, options, callback }); obs.observe({ entryTypes: ['measure'] }); performance.mark('A'); - res = this._chandle.query(this._connection._conn, stmt); + this._result = this._chandle.query(this._connection._conn, stmt); performance.mark('B'); performance.measure('query', 'A', 'B'); } else { - res = this._chandle.query(this._connection._conn, stmt); + this._result = this._chandle.query(this._connection._conn, stmt); } - + res = this._chandle.errno(this._result); if (res == 0) { - let fieldCount = this._chandle.fieldsCount(this._connection._conn); + let fieldCount = this._chandle.fieldsCount(this._result); if (fieldCount == 0) { - let affectedRowCount = this._chandle.affectedRows(this._connection._conn); + let affectedRowCount = this._chandle.affectedRows(this._result); let response = this._createAffectedResponse(affectedRowCount, time) if (options['quiet'] != true) { console.log(response); @@ -131,16 +131,17 @@ TDengineCursor.prototype.execute = function execute(operation, options, callback return affectedRowCount; //return num of affected rows, common with insert, use statements } else { - let resAndField = this._chandle.useResult(this._connection._conn, fieldCount) - this._result = resAndField.result; - this._fields = resAndField.fields; - this.fields = resAndField.fields; + this._fields = this._chandle.useResult(this._result); + this.fields = this._fields; + console.log('++++++++++++++++++++++++++'); + console.log(this._result); wrapCB(callback); + return this._result; //return a pointer to the result } } else { - throw new errors.ProgrammingError(this._chandle.errStr(this._connection._conn)) + throw new errors.ProgrammingError(this._chandle.errStr(this._result)) } } @@ -195,6 +196,8 @@ TDengineCursor.prototype.fetchall = function fetchall(options, callback) { */ obs.observe({ entryTypes: ['measure'] }); performance.mark('A'); + console.log('fetchall ----------------'); + while(true) { let blockAndRows = this._chandle.fetchBlock(this._result, this._fields); @@ -221,7 +224,7 @@ TDengineCursor.prototype.fetchall = function fetchall(options, callback) { let response = this._createSetResponse(this._rowcount, time) console.log(response); - this._connection._clearResultSet(); + // this._connection._clearResultSet(); let fields = this.fields; this._reset_result(); this.data = data; @@ -381,6 +384,9 @@ TDengineCursor.prototype.stopQuery = function stopQuery(result) { } TDengineCursor.prototype._reset_result = function _reset_result() { this._rowcount = -1; + if (this._result != null) { + this._chandle.freeResult(this._result); + } this._result = null; this._fields = null; this.data = []; diff --git a/src/connector/nodejs/package-lock.json b/src/connector/nodejs/package-lock.json index 1137e35106..5b10e7381b 100644 --- a/src/connector/nodejs/package-lock.json +++ b/src/connector/nodejs/package-lock.json @@ -1,6 +1,6 @@ { - "name": "td-connector", - "version": "1.6.1", + "name": "td2.0-connector", + "version": "0.0.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/connector/nodejs/package.json b/src/connector/nodejs/package.json index 2bc4a2453d..f5560742b2 100644 --- a/src/connector/nodejs/package.json +++ b/src/connector/nodejs/package.json @@ -1,6 +1,6 @@ { - "name": "td-connector", - "version": "2.0.0", + "name": "td2.0-connector", + "version": "0.0.1", "description": "A Node.js connector for TDengine.", "main": "tdengine.js", "scripts": { diff --git a/src/connector/nodejs/test/test.js b/src/connector/nodejs/test/test.js index 5d96e798d8..b8a8bcd151 100644 --- a/src/connector/nodejs/test/test.js +++ b/src/connector/nodejs/test/test.js @@ -19,7 +19,7 @@ function randomBool() { } // Initialize - +//c1.execute('drop database td_connector_test;'); c1.execute('create database if not exists td_connector_test;'); c1.execute('use td_connector_test;') c1.execute('create table if not exists all_types (ts timestamp, _int int, _bigint bigint, _float float, _double double, _binary binary(40), _smallint smallint, _tinyint tinyint, _bool bool, _nchar nchar(40));'); @@ -28,7 +28,7 @@ c1.execute('create table if not exists stabletest (ts timestamp, v1 int, v2 int, // Shell Test : The following uses the cursor to imitate the taos shell // Insert -for (let i = 0; i < 10000; i++) { +for (let i = 0; i < 100; i++) { let insertData = ["now+" + i + "s", // 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 @@ -40,18 +40,20 @@ for (let i = 0; i < 10000; i++) { randomBool(), "\"Nchars\""]; // Bool c1.execute('insert into td_connector_test.all_types values(' + insertData.join(',') + ' );', {quiet:true}); - if (i % 1000 == 0) { + if (i % 10 == 0) { console.log("Insert # " , i); } } // Select -c1.execute('select * from td_connector_test.all_types limit 10 offset 1000;'); +console.log('select * from td_connector_test.all_types limit 3 offset 100;'); +c1.execute('select * from td_connector_test.all_types limit 1 offset 100;'); var d = c1.fetchall(); console.log(c1.fields); console.log(d); - +/* // Functions +console.log('select count(*), avg(_int), sum(_float), max(_bigint), min(_double) from td_connector_test.all_types;') c1.execute('select count(*), avg(_int), sum(_float), max(_bigint), min(_double) from td_connector_test.all_types;'); var d = c1.fetchall(); console.log(c1.fields); @@ -134,3 +136,4 @@ setTimeout(function(){ c1.query('drop database td_connector_test;'); },2000); conn.close(); +*/ \ No newline at end of file From bd32da5bf16eead5b17e241b163e8137eb01e706 Mon Sep 17 00:00:00 2001 From: liu0x54 Date: Wed, 29 Jul 2020 11:31:04 +0000 Subject: [PATCH 2/6] [TD-1001]update nodejs connector documentation --- documentation/webdocs/markdowndocs/connector-ch.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/documentation/webdocs/markdowndocs/connector-ch.md b/documentation/webdocs/markdowndocs/connector-ch.md index 61da53585f..ec97816a27 100644 --- a/documentation/webdocs/markdowndocs/connector-ch.md +++ b/documentation/webdocs/markdowndocs/connector-ch.md @@ -917,15 +917,16 @@ TDengine 同时也提供了node.js 的连接器。用户可以通过[npm](https: 首先,通过[npm](https://www.npmjs.com/)安装node.js 连接器. ```cmd -npm install td-connector +npm install td2.0-connector ``` 我们建议用户使用npm 安装node.js连接器。如果您没有安装npm, 可以将*src/connector/nodejs/*拷贝到您的nodejs 项目目录下 我们使用[node-gyp](https://github.com/nodejs/node-gyp)和TDengine服务端进行交互。安装node.js 连接器之前,还需安装以下软件: -### Unix +### Linux - `python` (建议`v2.7` , `v3.x.x` 目前还不支持) +- `node` 必须采用v8.x版本,之后的版本存在兼容性的问题。 - `make` - c语言编译器比如[GCC](https://gcc.gnu.org) @@ -980,10 +981,10 @@ npm install td-connector #### 连接 -使用node.js连接器时,必须先require ```td-connector```,然后使用 ```taos.connect``` 函数。```taos.connect``` 函数必须提供的参数是```host```,其它参数在没有提供的情况下会使用如下的默认值。最后需要初始化```cursor``` 来和TDengine服务端通信 +使用node.js连接器时,必须先require ```td2.0-connector```,然后使用 ```taos.connect``` 函数。```taos.connect``` 函数必须提供的参数是```host```,其它参数在没有提供的情况下会使用如下的默认值。最后需要初始化```cursor``` 来和TDengine服务端通信 ```javascript -const taos = require('td-connector'); +const taos = require('td2.0-connector'); var conn = taos.connect({host:"127.0.0.1", user:"root", password:"taosdata", config:"/etc/taos",port:0}) var cursor = conn.cursor(); // Initializing a new cursor ``` From d55b0991c214dbd76987dea6b6a944dbb6053eb9 Mon Sep 17 00:00:00 2001 From: liu0x54 Date: Wed, 29 Jul 2020 12:55:07 +0000 Subject: [PATCH 3/6] [TD-1001] fix bugs --- src/connector/nodejs/nodetaos/cinterface.js | 60 ++++++++++----------- src/connector/nodejs/nodetaos/cursor.js | 4 -- 2 files changed, 27 insertions(+), 37 deletions(-) diff --git a/src/connector/nodejs/nodetaos/cinterface.js b/src/connector/nodejs/nodetaos/cinterface.js index 15502205f4..c8ba31dc68 100644 --- a/src/connector/nodejs/nodetaos/cinterface.js +++ b/src/connector/nodejs/nodetaos/cinterface.js @@ -26,7 +26,7 @@ function convertTimestamp(data, num_of_rows, nbytes = 0, offset = 0, micro=false if (micro == true) { timestampConverter = convertMicrosecondsToDatetime; } - data = ref.reinterpret(data, nbytes * num_of_rows, offset); + data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset); let res = []; let currOffset = 0; while (currOffset < data.length) { @@ -44,7 +44,7 @@ function convertTimestamp(data, num_of_rows, nbytes = 0, offset = 0, micro=false return res; } function convertBool(data, num_of_rows, nbytes = 0, offset = 0, micro=false) { - data = ref.reinterpret(data, nbytes * num_of_rows, offset); + data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset); let res = new Array(data.length); for (let i = 0; i < data.length; i++) { if (data[i] == 0) { @@ -60,7 +60,7 @@ function convertBool(data, num_of_rows, nbytes = 0, offset = 0, micro=false) { return res; } function convertTinyint(data, num_of_rows, nbytes = 0, offset = 0, micro=false) { - data = ref.reinterpret(data, nbytes * num_of_rows, offset); + data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset); let res = []; let currOffset = 0; while (currOffset < data.length) { @@ -71,7 +71,7 @@ function convertTinyint(data, num_of_rows, nbytes = 0, offset = 0, micro=false) return res; } function convertSmallint(data, num_of_rows, nbytes = 0, offset = 0, micro=false) { - data = ref.reinterpret(data, nbytes * num_of_rows, offset); + data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset); let res = []; let currOffset = 0; while (currOffset < data.length) { @@ -82,7 +82,7 @@ function convertSmallint(data, num_of_rows, nbytes = 0, offset = 0, micro=false) return res; } function convertInt(data, num_of_rows, nbytes = 0, offset = 0, micro=false) { - data = ref.reinterpret(data, nbytes * num_of_rows, offset); + data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset); let res = []; let currOffset = 0; while (currOffset < data.length) { @@ -93,18 +93,18 @@ function convertInt(data, num_of_rows, nbytes = 0, offset = 0, micro=false) { return res; } function convertBigint(data, num_of_rows, nbytes = 0, offset = 0, micro=false) { - data = ref.reinterpret(data, nbytes * num_of_rows, offset); + data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset); let res = []; let currOffset = 0; while (currOffset < data.length) { let d = data.readInt64LE(currOffset); - res.push(d == FieldTypes.C_BIGINT_NULL ? null : d); + res.push(d == FieldTypes.C_BIGINT_NULL ? null : BigInt(d)); currOffset += nbytes; } return res; } function convertFloat(data, num_of_rows, nbytes = 0, offset = 0, micro=false) { - data = ref.reinterpret(data, nbytes * num_of_rows, offset); + data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset); let res = []; let currOffset = 0; while (currOffset < data.length) { @@ -115,7 +115,7 @@ function convertFloat(data, num_of_rows, nbytes = 0, offset = 0, micro=false) { return res; } function convertDouble(data, num_of_rows, nbytes = 0, offset = 0, micro=false) { - data = ref.reinterpret(data, nbytes * num_of_rows, offset); + data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset); let res = []; let currOffset = 0; while (currOffset < data.length) { @@ -126,7 +126,7 @@ function convertDouble(data, num_of_rows, nbytes = 0, offset = 0, micro=false) { return res; } function convertBinary(data, num_of_rows, nbytes = 0, offset = 0, micro=false) { - data = ref.reinterpret(data, nbytes * num_of_rows, offset); + data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset); let res = []; let currOffset = 0; while (currOffset < data.length) { @@ -142,7 +142,7 @@ function convertBinary(data, num_of_rows, nbytes = 0, offset = 0, micro=false) { return res; } function convertNchar(data, num_of_rows, nbytes = 0, offset = 0, micro=false) { - data = ref.reinterpret(data, nbytes * num_of_rows, offset); + data = ref.reinterpret(data.deref(), nbytes * num_of_rows, offset); let res = []; let currOffset = 0; // every 4 bytes, a character is encoded; @@ -211,7 +211,7 @@ function CTaosInterface (config = null, pass = false) { //int taos_affected_rows(TAOS *taos) 'taos_affected_rows': [ ref.types.int, [ ref.types.void_ptr] ], //int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) - 'taos_fetch_block': [ ref.types.int, [ ref.types.void_ptr, ref.types.void_ptr2] ], + 'taos_fetch_block': [ ref.types.int, [ ref.types.void_ptr, ref.types.void_ptr] ], //int taos_num_fields(TAOS_RES *res); 'taos_num_fields': [ ref.types.int, [ ref.types.void_ptr] ], //TAOS_ROW taos_fetch_row(TAOS_RES *res) @@ -349,48 +349,42 @@ CTaosInterface.prototype.useResult = function useResult(result) { return {fields:fields} } CTaosInterface.prototype.fetchBlock = function fetchBlock(result, fields) { - let pblock = ref.ref(ref.NULL); // equal to our raw data - pblock = this.libtaos.taos_fetch_row(result); - - if (pblock == 0) { + let pblock = ref.ref(ref.ref(ref.NULL)); // equal to our raw data + let num_of_rows = this.libtaos.taos_fetch_block(result, pblock) + if (num_of_rows == 0) { return {block:null, num_of_rows:0}; } - let isMicro = (this.libtaos.taos_result_precision(result) == FieldTypes.C_TIMESTAMP_MICRO) - - - //num_of_rows = Math.abs(num_of_rows); - let offset = 0; - //pblock = pblock.deref(); - var fieldL = this.libtaos.taos_fetch_lengths(result); var numoffields = this.libtaos.taos_field_count(result); - let blocks = new Array(numoffields); - blocks.fill(null); + let isMicro = (this.libtaos.taos_result_precision(result) == FieldTypes.C_TIMESTAMP_MICRO); + var fieldlens = []; if (ref.isNull(fieldL) == false) { for (let i = 0; i < numoffields; i ++) { let plen = ref.reinterpret(fieldL, 4, i*4); - //plen = ref.readPointer(plen,0,ref.types.int); let len = plen.readInt32LE(0); fieldlens.push(len); - //console.log(len); } } + + let blocks = new Array(numoffields); + blocks.fill(null); + num_of_rows = Math.abs(num_of_rows); + let offset = 0; + pblock = pblock.deref(); for (let i = 0; i < numoffields; i++) { + if (!convertFunctions[fields['fields'][i]['type']] ) { throw new errors.DatabaseError("Invalid data type returned from database"); } - prow = ref.reinterpret(pblock,8,i*8); - console.log(fieldlens[i]); - blocks[i] = convertFunctions[fields['fields'][i]['type']](prow, 1, fieldlens[i], 0, isMicro); - console.log('******************************'); + blocks[i] = convertFunctions[fields['fields'][i]['type']](pblock, num_of_rows, fieldlens[i], offset, isMicro); console.log(blocks[i]); - //offset += fields[i]['bytes'] * num_of_rows; + offset += fields['fields'][i]['bytes'] * num_of_rows; } - return {blocks: blocks, num_of_rows:1} + return {blocks: blocks, num_of_rows:Math.abs(num_of_rows)} } CTaosInterface.prototype.fetchRow = function fetchRow(result, fields) { let row = this.libtaos.taos_fetch_row(result); diff --git a/src/connector/nodejs/nodetaos/cursor.js b/src/connector/nodejs/nodetaos/cursor.js index 3f01b2b518..390e1becbc 100644 --- a/src/connector/nodejs/nodetaos/cursor.js +++ b/src/connector/nodejs/nodetaos/cursor.js @@ -196,15 +196,11 @@ TDengineCursor.prototype.fetchall = function fetchall(options, callback) { */ obs.observe({ entryTypes: ['measure'] }); performance.mark('A'); - console.log('fetchall ----------------'); - while(true) { let blockAndRows = this._chandle.fetchBlock(this._result, this._fields); - let block = blockAndRows.blocks; let num_of_rows = blockAndRows.num_of_rows; - if (num_of_rows == 0) { break; } From 2b84d45098ed79df9cbc74665b54abd95530540f Mon Sep 17 00:00:00 2001 From: liu0x54 Date: Thu, 30 Jul 2020 13:58:36 +0000 Subject: [PATCH 4/6] [TD-1001] adapt nodejs connector --- src/connector/nodejs/nodetaos/cinterface.js | 30 ++++++++------------- src/connector/nodejs/nodetaos/cursor.js | 10 +++---- src/connector/nodejs/test/test.js | 17 ++++++------ 3 files changed, 25 insertions(+), 32 deletions(-) diff --git a/src/connector/nodejs/nodetaos/cinterface.js b/src/connector/nodejs/nodetaos/cinterface.js index c8ba31dc68..656741ea16 100644 --- a/src/connector/nodejs/nodetaos/cinterface.js +++ b/src/connector/nodejs/nodetaos/cinterface.js @@ -346,7 +346,7 @@ CTaosInterface.prototype.useResult = function useResult(result) { }) } } - return {fields:fields} + return fields; } CTaosInterface.prototype.fetchBlock = function fetchBlock(result, fields) { let pblock = ref.ref(ref.ref(ref.NULL)); // equal to our raw data @@ -355,7 +355,6 @@ CTaosInterface.prototype.fetchBlock = function fetchBlock(result, fields) { return {block:null, num_of_rows:0}; } var fieldL = this.libtaos.taos_fetch_lengths(result); - var numoffields = this.libtaos.taos_field_count(result); let isMicro = (this.libtaos.taos_result_precision(result) == FieldTypes.C_TIMESTAMP_MICRO); @@ -363,26 +362,25 @@ CTaosInterface.prototype.fetchBlock = function fetchBlock(result, fields) { if (ref.isNull(fieldL) == false) { - for (let i = 0; i < numoffields; i ++) { + for (let i = 0; i < fields.length; i ++) { let plen = ref.reinterpret(fieldL, 4, i*4); let len = plen.readInt32LE(0); fieldlens.push(len); } } - let blocks = new Array(numoffields); + let blocks = new Array(fields.length); blocks.fill(null); num_of_rows = Math.abs(num_of_rows); let offset = 0; pblock = pblock.deref(); - for (let i = 0; i < numoffields; i++) { - - if (!convertFunctions[fields['fields'][i]['type']] ) { + for (let i = 0; i < fields.length; i++) { + pdata = ref.reinterpret(pblock,8,i*8); + pdata = ref.ref(pdata.readPointer()); + if (!convertFunctions[fields[i]['type']] ) { throw new errors.DatabaseError("Invalid data type returned from database"); } - blocks[i] = convertFunctions[fields['fields'][i]['type']](pblock, num_of_rows, fieldlens[i], offset, isMicro); - console.log(blocks[i]); - offset += fields['fields'][i]['bytes'] * num_of_rows; + blocks[i] = convertFunctions[fields[i]['type']](pdata, 1, fieldlens[i], offset, isMicro); } return {blocks: blocks, num_of_rows:Math.abs(num_of_rows)} } @@ -429,9 +427,7 @@ CTaosInterface.prototype.fetch_rows_a = function fetch_rows_a(result, callback, let asyncCallbackWrapper = function (param2, result2, numOfRows2) { // Data preparation to pass to cursor. Could be bottleneck in query execution callback times. let row = cti.libtaos.taos_fetch_row(result2); - console.log(row); let fields = cti.fetchFields_a(result2); - let isMicro = (cti.libtaos.taos_result_precision(result2) == FieldTypes.C_TIMESTAMP_MICRO); let blocks = new Array(fields.length); @@ -446,21 +442,17 @@ CTaosInterface.prototype.fetch_rows_a = function fetch_rows_a(result, callback, let plen = ref.reinterpret(fieldL, 8, i*8); let len = ref.get(plen,0,ref.types.int32); fieldlens.push(len); - console.log('11111111111111111111'); - console.log(fields.length); - console.log(len); } } - if (numOfRows2 > 0){ for (let i = 0; i < fields.length; i++) { if (!convertFunctions[fields[i]['type']] ) { throw new errors.DatabaseError("Invalid data type returned from database"); } let prow = ref.reinterpret(row,8,i*8); - //blocks[i] = convertFunctions[fields[i]['type']](ref.get(prow,0,ref.types.void_ptr), numOfRows2, fieldlens[i], 0, isMicro); - console.log(prow); - blocks[i] = convertFunctions[fields[i]['type']](ref.readPointer(prow), numOfRows2, fieldlens[i], 0, isMicro); + prow = prow.readPointer(); + prow = ref.ref(prow); + blocks[i] = convertFunctions[fields[i]['type']](prow, 1, fieldlens[i], offset, isMicro); //offset += fields[i]['bytes'] * numOfRows2; } } diff --git a/src/connector/nodejs/nodetaos/cursor.js b/src/connector/nodejs/nodetaos/cursor.js index 390e1becbc..8296a2132c 100644 --- a/src/connector/nodejs/nodetaos/cursor.js +++ b/src/connector/nodejs/nodetaos/cursor.js @@ -133,8 +133,6 @@ TDengineCursor.prototype.execute = function execute(operation, options, callback else { this._fields = this._chandle.useResult(this._result); this.fields = this._fields; - console.log('++++++++++++++++++++++++++'); - console.log(this._result); wrapCB(callback); return this._result; //return a pointer to the result @@ -205,10 +203,12 @@ TDengineCursor.prototype.fetchall = function fetchall(options, callback) { break; } this._rowcount += num_of_rows; + let numoffields = this._fields.length; for (let i = 0; i < num_of_rows; i++) { data.push([]); - let rowBlock = new Array(this._fields.length); - for (let j = 0; j < this._fields.length; j++) { + + let rowBlock = new Array(numoffields); + for (let j = 0; j < numoffields; j++) { rowBlock[j] = block[j][i]; } data[data.length-1] = (rowBlock); @@ -268,7 +268,7 @@ TDengineCursor.prototype.execute_a = function execute_a (operation, options, cal let fieldCount = cr._chandle.numFields(res2); if (fieldCount == 0) { cr._chandle.freeResult(res2); - } + } else { return res2; } diff --git a/src/connector/nodejs/test/test.js b/src/connector/nodejs/test/test.js index b8a8bcd151..db86178da1 100644 --- a/src/connector/nodejs/test/test.js +++ b/src/connector/nodejs/test/test.js @@ -28,7 +28,7 @@ c1.execute('create table if not exists stabletest (ts timestamp, v1 int, v2 int, // Shell Test : The following uses the cursor to imitate the taos shell // Insert -for (let i = 0; i < 100; i++) { +for (let i = 0; i < 1000; i++) { let insertData = ["now+" + i + "s", // 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 @@ -40,18 +40,18 @@ for (let i = 0; i < 100; i++) { randomBool(), "\"Nchars\""]; // Bool c1.execute('insert into td_connector_test.all_types values(' + insertData.join(',') + ' );', {quiet:true}); - if (i % 10 == 0) { + if (i % 100 == 0) { console.log("Insert # " , i); } } // Select console.log('select * from td_connector_test.all_types limit 3 offset 100;'); -c1.execute('select * from td_connector_test.all_types limit 1 offset 100;'); +c1.execute('select * from td_connector_test.all_types limit 2 offset 100;'); var d = c1.fetchall(); console.log(c1.fields); console.log(d); -/* + // Functions console.log('select count(*), avg(_int), sum(_float), max(_bigint), min(_double) from td_connector_test.all_types;') c1.execute('select count(*), avg(_int), sum(_float), max(_bigint), min(_double) from td_connector_test.all_types;'); @@ -61,12 +61,14 @@ console.log(d); // Immediate Execution like the Shell -c1.query('select count(*), stddev(_double), min(_tinyint) from all_types where _tinyint > 50 and _int < 0;', true).then(function(result){ - result.pretty(); -}) +//c1.query('select count(*), stddev(_double), min(_tinyint) from all_types where _tinyint > 50 and _int < 0;', true).then(function(result){ +// result.pretty(); +//}) + c1.query('select _tinyint, _bool from all_types where _tinyint > 50 and _int < 0 limit 50;', true).then(function(result){ result.pretty(); }) + c1.query('select stddev(_double), stddev(_bigint), stddev(_float) from all_types;', true).then(function(result){ result.pretty(); }) @@ -136,4 +138,3 @@ setTimeout(function(){ c1.query('drop database td_connector_test;'); },2000); conn.close(); -*/ \ No newline at end of file From 8da73b3b009d8eae7359ea0335c15522271bd0c3 Mon Sep 17 00:00:00 2001 From: liu0x54 Date: Fri, 31 Jul 2020 03:16:38 +0000 Subject: [PATCH 5/6] [TD-1001] fix node js connector --- src/connector/nodejs/nodetaos/cursor.js | 16 +++++----- src/connector/nodejs/test/test.js | 42 ++++++++++++++----------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/connector/nodejs/nodetaos/cursor.js b/src/connector/nodejs/nodetaos/cursor.js index 8296a2132c..0c9214fe32 100644 --- a/src/connector/nodejs/nodetaos/cursor.js +++ b/src/connector/nodejs/nodetaos/cursor.js @@ -265,13 +265,15 @@ TDengineCursor.prototype.execute_a = function execute_a (operation, options, cal } if (resCode >= 0) { - let fieldCount = cr._chandle.numFields(res2); - if (fieldCount == 0) { - cr._chandle.freeResult(res2); - } - else { - return res2; - } +// let fieldCount = cr._chandle.numFields(res2); +// if (fieldCount == 0) { +// //cr._chandle.freeResult(res2); +// return res2; +// } +// else { +// return res2; +// } + return res2; } else { diff --git a/src/connector/nodejs/test/test.js b/src/connector/nodejs/test/test.js index db86178da1..73dac8b26c 100644 --- a/src/connector/nodejs/test/test.js +++ b/src/connector/nodejs/test/test.js @@ -28,7 +28,7 @@ c1.execute('create table if not exists stabletest (ts timestamp, v1 int, v2 int, // Shell Test : The following uses the cursor to imitate the taos shell // Insert -for (let i = 0; i < 1000; i++) { +for (let i = 0; i < 10000; i++) { let insertData = ["now+" + i + "s", // 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 @@ -40,7 +40,7 @@ for (let i = 0; i < 1000; i++) { randomBool(), "\"Nchars\""]; // Bool c1.execute('insert into td_connector_test.all_types values(' + insertData.join(',') + ' );', {quiet:true}); - if (i % 100 == 0) { + if (i % 1000 == 0) { console.log("Insert # " , i); } } @@ -61,9 +61,9 @@ console.log(d); // Immediate Execution like the Shell -//c1.query('select count(*), stddev(_double), min(_tinyint) from all_types where _tinyint > 50 and _int < 0;', true).then(function(result){ -// result.pretty(); -//}) +c1.query('select count(*), stddev(_double), min(_tinyint) from all_types where _tinyint > 50 and _int < 0;', true).then(function(result){ + result.pretty(); +}) c1.query('select _tinyint, _bool from all_types where _tinyint > 50 and _int < 0 limit 50;', true).then(function(result){ result.pretty(); @@ -87,54 +87,58 @@ q.execute().then(function(r) { // Raw Async Testing (Callbacks, not promises) function cb2(param, result, rowCount, rd) { + console.log('CB2 Callbacked!'); console.log("RES *", result); - console.log("Async fetched", rowCount, "rows"); + console.log("Async fetched", rowCount, " rows"); console.log("Passed Param: ", param); - console.log("Fields", rd.fields); - console.log("Data", rd.data); - + console.log("Fields ", rd.fields); + console.log("Data ", rd.data); } function cb1(param,result,code) { - console.log('Callbacked!'); - console.log("RES *", result); + console.log('CB1 Callbacked!'); + console.log("RES * ", result); console.log("Status: ", code); - console.log("Passed Param", param); - c1.fetchall_a(result, cb2, param) + console.log("Passed Param ", param); + c1.fetchall_a(result, cb2, param); } c1.execute_a("describe td_connector_test.all_types;", cb1, {myparam:3.141}); function cb4(param, result, rowCount, rd) { + console.log('CB4 Callbacked!'); console.log("RES *", result); console.log("Async fetched", rowCount, "rows"); console.log("Passed Param: ", param); console.log("Fields", rd.fields); console.log("Data", rd.data); - } // Without directly calling fetchall_a var thisRes; function cb3(param,result,code) { - console.log('Callbacked!'); + console.log('CB3 Callbacked!'); console.log("RES *", result); - console.log("Status: ", code); + console.log("Status:", code); console.log("Passed Param", param); thisRes = result; } //Test calling execute and fetchall seperately and not through callbacks var param = c1.execute_a("describe td_connector_test.all_types;", cb3, {e:2.718}); console.log("Passed Param outside of callback: ", param); +console.log(param); setTimeout(function(){ c1.fetchall_a(thisRes, cb4, param); },100); // Async through promises -var aq = c1.query('select count(*) from td_connector_test.all_types;') +var aq = c1.query('select count(*) from td_connector_test.all_types;',false); aq.execute_a().then(function(data) { data.pretty(); -}) +}); c1.query('describe td_connector_test.stabletest;').execute_a().then(r=> r.pretty()); setTimeout(function(){ c1.query('drop database td_connector_test;'); +},200); +setTimeout(function(){ + conn.close(); },2000); -conn.close(); + From 3bbec8f87fb77df2d305f29cc4b253829763158c Mon Sep 17 00:00:00 2001 From: liu0x54 Date: Fri, 31 Jul 2020 03:23:44 +0000 Subject: [PATCH 6/6] [TD-1001] update files --- src/connector/nodejs/package-lock.json | 2 +- src/connector/nodejs/package.json | 2 +- src/connector/nodejs/readme.md | 13 +++++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/connector/nodejs/package-lock.json b/src/connector/nodejs/package-lock.json index 5b10e7381b..d13fe6959c 100644 --- a/src/connector/nodejs/package-lock.json +++ b/src/connector/nodejs/package-lock.json @@ -1,6 +1,6 @@ { "name": "td2.0-connector", - "version": "0.0.1", + "version": "2.0.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/connector/nodejs/package.json b/src/connector/nodejs/package.json index f5560742b2..3f0600a09c 100644 --- a/src/connector/nodejs/package.json +++ b/src/connector/nodejs/package.json @@ -1,6 +1,6 @@ { "name": "td2.0-connector", - "version": "0.0.1", + "version": "2.0.1", "description": "A Node.js connector for TDengine.", "main": "tdengine.js", "scripts": { diff --git a/src/connector/nodejs/readme.md b/src/connector/nodejs/readme.md index cf60b11024..26a28afbdd 100644 --- a/src/connector/nodejs/readme.md +++ b/src/connector/nodejs/readme.md @@ -1,23 +1,24 @@ # TDengine Node.js connector -[![minzip](https://img.shields.io/bundlephobia/minzip/td-connector.svg)](https://github.com/taosdata/TDengine/tree/master/src/connector/nodejs) [![NPM](https://img.shields.io/npm/l/td-connector.svg)](https://github.com/taosdata/TDengine/#what-is-tdengine) +[![minzip](https://img.shields.io/bundlephobia/minzip/td2.0-connector.svg)](https://github.com/taosdata/TDengine/tree/master/src/connector/nodejs) [![NPM](https://img.shields.io/npm/l/td2.0-connector.svg)](https://github.com/taosdata/TDengine/#what-is-tdengine) -This is the Node.js library that lets you connect to [TDengine](https://www.github.com/taosdata/tdengine). It is built so that you can use as much of it as you want or as little of it as you want through providing an extensive API. If you want the raw data in the form of an array of arrays for the row data retrieved from a table, you can do that. If you want to wrap that data with objects that allow you easily manipulate and display data such as using a prettifier function, you can do that! +This is the Node.js library that lets you connect to [TDengine](https://www.github.com/taosdata/tdengine) 2.0 version. It is built so that you can use as much of it as you want or as little of it as you want through providing an extensive API. If you want the raw data in the form of an array of arrays for the row data retrieved from a table, you can do that. If you want to wrap that data with objects that allow you easily manipulate and display data such as using a prettifier function, you can do that! ## Installation To get started, just type in the following to install the connector through [npm](https://www.npmjs.com/) ```cmd -npm install td-connector +npm install td2.0-connector ``` To interact with TDengine, we make use of the [node-gyp](https://github.com/nodejs/node-gyp) library. To install, you will need to install the following depending on platform (the following instructions are quoted from node-gyp) -### On Unix +### On Linux - `python` (`v2.7` recommended, `v3.x.x` is **not** supported) - `make` - A proper C/C++ compiler toolchain, like [GCC](https://gcc.gnu.org) +- `node` (between `v10.x` and `v11.x`, other version has some dependency compatibility problems) ### On macOS @@ -71,12 +72,12 @@ The following is a short summary of the basic usage of the connector, the full ### Connection -To use the connector, first require the library ```td-connector```. Running the function ```taos.connect``` with the connection options passed in as an object will return a TDengine connection object. The required connection option is ```host```, other options if not set, will be the default values as shown below. +To use the connector, first require the library ```td2.0-connector```. Running the function ```taos.connect``` with the connection options passed in as an object will return a TDengine connection object. The required connection option is ```host```, other options if not set, will be the default values as shown below. A cursor also needs to be initialized in order to interact with TDengine from Node.js. ```javascript -const taos = require('td-connector'); +const taos = require('td2.0-connector'); var conn = taos.connect({host:"127.0.0.1", user:"root", password:"taosdata", config:"/etc/taos",port:0}) var cursor = conn.cursor(); // Initializing a new cursor ```