Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
libgeos-dev libjansson-dev libsnappy-dev liblzma-dev libz-dev \
zlib1g pkg-config libssl-dev gawk

- name: install TDengine
- name: Install TDengine
run: |
cd TDengine
mkdir debug
Expand All @@ -49,11 +49,11 @@ jobs:
which taosd
which taosadapter

- name: start taosd
- name: Start taosd
run: |
nohup sudo taosd &

- name: start taosadapter
- name: Start taosadapter
run: |
nohup sudo taosadapter &

Expand All @@ -69,7 +69,7 @@ jobs:
with:
node-version: ${{ matrix.node-version }}

- name: test nodejs websocket
- name: Test nodejs websocket
working-directory: nodejs-connector/nodejs
run: |
export TDENGINE_CLOUD_URL=${{ secrets.TDENGINE_CLOUD_URL }}
Expand Down
18 changes: 9 additions & 9 deletions nodejs/example/all_type_query.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { WSConfig } from "../src/common/config";
import { sqlConnect, destroy, setLogLevel } from "../src";
import { sqlConnect, destroy } from "../src";

let dsn = "ws://127.0.0.1:6041";
async function json_tag_example() {
Expand Down Expand Up @@ -29,8 +29,8 @@ async function json_tag_example() {
let taosResult = await wsSql.exec(insertQuery);
console.log(
"Successfully inserted " +
taosResult.getAffectRows() +
" rows to example_json_tag.stb."
taosResult.getAffectRows() +
" rows to example_json_tag.stb."
);
Comment thread
qevolg marked this conversation as resolved.

let sql = "SELECT ts, v, jt FROM example_json_tag.stb limit 100";
Expand Down Expand Up @@ -70,10 +70,10 @@ async function all_type_example() {
// create table
await wsSql.exec(
"create table if not exists all_type_example.stb (ts timestamp, " +
"int_col INT, double_col DOUBLE, bool_col BOOL, binary_col BINARY(100)," +
"nchar_col NCHAR(100), varbinary_col VARBINARY(100), geometry_col GEOMETRY(100)) " +
"tags(int_tag INT, double_tag DOUBLE, bool_tag BOOL, binary_tag BINARY(100)," +
"nchar_tag NCHAR(100), varbinary_tag VARBINARY(100), geometry_tag GEOMETRY(100));"
"int_col INT, double_col DOUBLE, bool_col BOOL, binary_col BINARY(100)," +
"nchar_col NCHAR(100), varbinary_col VARBINARY(100), geometry_col GEOMETRY(100)) " +
"tags(int_tag INT, double_tag DOUBLE, bool_tag BOOL, binary_tag BINARY(100)," +
"nchar_tag NCHAR(100), varbinary_tag VARBINARY(100), geometry_tag GEOMETRY(100));"
);

console.log("Create stable all_type_example.stb successfully");
Expand All @@ -85,8 +85,8 @@ async function all_type_example() {
let taosResult = await wsSql.exec(insertQuery);
console.log(
"Successfully inserted " +
taosResult.getAffectRows() +
" rows to all_type_example.stb."
taosResult.getAffectRows() +
" rows to all_type_example.stb."
);

let sql = "SELECT * FROM all_type_example.stb limit 100";
Expand Down
1 change: 0 additions & 1 deletion nodejs/src/client/wsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ export class WsClient {
this._wsConnector
);
this._wsConnector = undefined;
// this._wsConnector.close();
}
}

Expand Down
6 changes: 3 additions & 3 deletions nodejs/src/client/wsConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ export class WebSocketConnector {
}
logger.debug(
"[wsClient.sendBinaryMsg()]===>" +
reqId +
action +
message.byteLength
reqId +
action +
message.byteLength
);
Comment thread
qevolg marked this conversation as resolved.
this._wsConn.send(message);
} else {
Expand Down
22 changes: 11 additions & 11 deletions nodejs/src/client/wsConnectorPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,28 +67,28 @@ export class WebSocketConnectionPool {
if (connector) {
logger.debug(
"get connection success:" +
Atomics.load(WebSocketConnectionPool.sharedArray, 0)
Atomics.load(WebSocketConnectionPool.sharedArray, 0)
);
return connector;
}

if (
this._maxConnections != -1 &&
Atomics.load(WebSocketConnectionPool.sharedArray, 0) >
this._maxConnections
this._maxConnections
) {
throw new TDWebSocketClientError(
ErrorCode.ERR_WEBSOCKET_CONNECTION_ARRIVED_LIMIT,
"websocket connect arrived limited:" +
Atomics.load(WebSocketConnectionPool.sharedArray, 0)
Atomics.load(WebSocketConnectionPool.sharedArray, 0)
);
}
Atomics.add(WebSocketConnectionPool.sharedArray, 0, 1);
logger.info(
"getConnection, new connection count:" +
Atomics.load(WebSocketConnectionPool.sharedArray, 0) +
", connectAddr:" +
connectAddr
Atomics.load(WebSocketConnectionPool.sharedArray, 0) +
", connectAddr:" +
connectAddr
);
Comment thread
qevolg marked this conversation as resolved.
return new WebSocketConnector(url, timeout);
} finally {
Expand All @@ -115,14 +115,14 @@ export class WebSocketConnectionPool {
}
logger.info(
"releaseConnection, current connection count:" +
connectors.length
connectors.length
);
} else {
Atomics.add(WebSocketConnectionPool.sharedArray, 0, -1);
connector.close();
logger.info(
"releaseConnection, current connection status fail:" +
Atomics.load(WebSocketConnectionPool.sharedArray, 0)
Atomics.load(WebSocketConnectionPool.sharedArray, 0)
);
}
} finally {
Expand All @@ -143,9 +143,9 @@ export class WebSocketConnectionPool {
}
logger.info(
"destroyed connect:" +
Atomics.load(WebSocketConnectionPool.sharedArray, 0) +
" current count:" +
num
Atomics.load(WebSocketConnectionPool.sharedArray, 0) +
" current count:" +
num
);
Atomics.store(WebSocketConnectionPool.sharedArray, 0, 0);
this.pool = new Map();
Expand Down
18 changes: 13 additions & 5 deletions nodejs/src/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,31 @@ export class WSConfig {
public getToken(): string | undefined | null {
return this._token;
}

public setToken(token: string) {
this._token = token;
}

public getUser(): string | undefined | null {
return this._user;
}

public setUser(user: string) {
this._user = user;
}

public getPwd(): string | undefined | null {
return this._password;
}

public setPwd(pws: string) {
this._password = pws;
}

public getDb(): string | undefined | null {
return this._db;
}

public setDb(db: string) {
this._db = db;
}
Expand All @@ -55,18 +59,22 @@ export class WSConfig {
this._url = url;
}

public setTimeOut(ms: number) {
this._timeout = ms;
}
public getTimeOut(): number | undefined | null {
return this._timeout;
}
public setTimezone(timezone: string) {
this._timezone = timezone;

public setTimeOut(ms: number) {
this._timeout = ms;
}

public getTimezone(): string | undefined | null {
return this._timezone;
}

public setTimezone(timezone: string) {
this._timezone = timezone;
}

public getMinStmt2Version() {
return this._minStmt2Version;
}
Expand Down
4 changes: 2 additions & 2 deletions nodejs/src/common/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ export enum TDengineTypeCode {
}

export enum TSDB_OPTION_CONNECTION {
TSDB_OPTION_CONNECTION_CHARSET, // charset, Same as the scope supported by the system
TSDB_OPTION_CONNECTION_CHARSET, // charset, Same as the scope supported by the system
TSDB_OPTION_CONNECTION_TIMEZONE, // timezone, Same as the scope supported by the system
TSDB_OPTION_CONNECTION_USER_IP, // user ip
TSDB_OPTION_CONNECTION_USER_IP, // user ip
TSDB_OPTION_CONNECTION_USER_APP, // user app
}

Expand Down
4 changes: 4 additions & 0 deletions nodejs/src/common/taosResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,11 @@ export class TaosResult {
public getData(): Array<Array<any>> | null {
return this._data;
}

public setData(value: Array<Array<any>> | null) {
this._data = value;
}

public getAffectRows(): number | null | undefined {
return this._affectRows;
}
Expand All @@ -137,9 +139,11 @@ export class TaosResult {
public getPrecision(): number | null | undefined {
return this._precision;
}

public getTotalTime() {
return this._totalTime;
}

public addTotalTime(totalTime: number) {
this._totalTime += totalTime;
}
Expand Down
1 change: 0 additions & 1 deletion nodejs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { WsSql } from "./sql/wsSql";
import { WSConfig } from "./common/config";
import { WsConsumer } from "./tmq/wsTmq";
import logger, { setLevel } from "./common/log";

import { WebSocketConnectionPool } from "./client/wsConnectorPool";

let sqlConnect = async (conf: WSConfig) => {
Expand Down
4 changes: 2 additions & 2 deletions nodejs/src/sql/wsRows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { WsClient } from "../client/wsClient";
import logger from "../common/log";
import { ReqId } from "../common/reqid";
import { getBinarySql } from "../common/utils";
import { BinaryQueryMessage, FetchRawBlockMessage } from "../common/constant";
import { FetchRawBlockMessage } from "../common/constant";

export class WSRows {
private _wsClient: WsClient;
Expand Down Expand Up @@ -107,7 +107,7 @@ export class WSRows {
let data = this._taosResult.getData();
if (this._taosResult && data != null) {
if (Array.isArray(data) && data.length > 0) {
return data.pop();
return data.shift();
Comment thread
qevolg marked this conversation as resolved.
Comment thread
zitsen marked this conversation as resolved.
}
}
return undefined;
Expand Down
4 changes: 2 additions & 2 deletions nodejs/src/sql/wsSql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { ReqId } from "../common/reqid";
import {
BinaryQueryMessage,
FetchRawBlockMessage,
MinStmt2Version,
PrecisionLength,
TSDB_OPTION_CONNECTION,
} from "../common/constant";
Expand All @@ -27,10 +26,11 @@ import { WsStmt2 } from "../stmt/wsStmt2";
export class WsSql {
private wsConfig: WSConfig;
private _wsClient: WsClient;

constructor(wsConfig: WSConfig) {
let url = getUrl(wsConfig);
this._wsClient = new WsClient(url, wsConfig.getTimeOut());
this.wsConfig = wsConfig;
this._wsClient = new WsClient(url, wsConfig.getTimeOut());
}

static async open(wsConfig: WSConfig): Promise<WsSql> {
Expand Down
15 changes: 1 addition & 14 deletions nodejs/test/bulkPulling/queryTables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
tableMeta,
tagMeta,
} from "../utils";
// const DSN = 'ws://root:taosdata@127.0.0.1:6041'

let dsn = "ws://root:taosdata@localhost:6041";
let conf: WSConfig = new WSConfig(dsn);
const resultMap: Map<string, any> = new Map();
Expand Down Expand Up @@ -337,7 +337,6 @@ describe("ws.query(stable)", () => {

for (let i = 0; i < actualData.length; i++) {
actualData[i].forEach((d, index) => {
// // console.log(i, index, d, expectData[i][index])
if (
expectMeta[index].name == "geo" ||
expectMeta[index].name == "vbinary"
Expand Down Expand Up @@ -379,9 +378,7 @@ describe("ws.query(stable)", () => {
let ws = await WsSql.open(conf);
await ws.exec(useDB);
let insertCN = insertStable(tableCNValues, stableCNTags, stableCN);
// console.log(insertCN)
let insertRes = await ws.exec(insertCN);
// console.log(insertRes)
expect(insertRes.getAffectRows()).toBe(5);

let queryRes = await ws.exec(selectStableCN);
Expand Down Expand Up @@ -443,7 +440,6 @@ describe("ws.query(table)", () => {
let ws = await WsSql.open(conf);
await ws.exec(useDB);
let insert = insertNTable(tableValues, table);
// console.log(insert)
let insertRes = await ws.exec(insert);
expect(insertRes.getAffectRows()).toBe(5);

Expand All @@ -456,7 +452,6 @@ describe("ws.query(table)", () => {
await ws.close();
if (actualData && actualMeta) {
actualMeta.forEach((meta, index) => {
// console.log(meta,expectMeta[index]);
expect(meta.name).toBe(expectMeta[index].name);
expect(meta.type).toBe(expectMeta[index].type);
expect(meta.length).toBe(expectMeta[index].length);
Expand All @@ -483,9 +478,7 @@ describe("ws.query(table)", () => {
let ws = await WsSql.open(conf);
await ws.exec(useDB);
let insertCN = insertNTable(tableCNValues, tableCN);
// console.log(insertCN)
let insertRes = await ws.exec(insertCN);
// console.log(insertRes)
expect(insertRes.getAffectRows()).toBe(5);

let queryRes = await ws.exec(selectTableCN);
Expand All @@ -497,8 +490,6 @@ describe("ws.query(table)", () => {
await ws.close();
if (actualData && actualMeta) {
actualMeta.forEach((meta, index) => {
// console.log(meta, expectMeta[index]);

expect(meta.name).toBe(expectMeta[index].name);
expect(meta.type).toBe(expectMeta[index].type);
expect(meta.length).toBe(expectMeta[index].length);
Expand Down Expand Up @@ -527,7 +518,6 @@ describe("ws.query(jsonTable)", () => {
let ws = await WsSql.open(conf);
await ws.exec(useDB);
let insert = insertStable(tableValues, jsonTags, jsonTable);
// console.log(insert)

let insertRes = await ws.exec(insert);
expect(insertRes.getAffectRows()).toBe(5);
Expand Down Expand Up @@ -567,7 +557,6 @@ describe("ws.query(jsonTable)", () => {
let ws = await WsSql.open(conf);
await ws.exec(useDB);
let insert = insertStable(tableCNValues, jsonTagsCN, jsonTableCN);
// console.log(insert)

let insertRes = await ws.exec(insert);
expect(insertRes.getAffectRows()).toBe(5);
Expand Down Expand Up @@ -610,5 +599,3 @@ afterAll(async () => {
await ws.close();
WebSocketConnectionPool.instance().destroyed();
});

//--detectOpenHandles --maxConcurrency=1 --forceExit
Loading