Skip to content

Commit be06771

Browse files
authored
fix: fix test case and format code (#91)
* style: format code * fix: fix test case
1 parent 23e82c8 commit be06771

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+6536
-4258
lines changed

.github/workflows/build.yaml

Lines changed: 67 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -4,91 +4,87 @@ name: nodejs Release
44

55
on:
66
push:
7-
branches: ['main']
7+
branches: ["main"]
88
pull_request:
9-
branches: ['main']
9+
branches: ["main"]
1010

1111
jobs:
1212
build:
13-
1413
runs-on: ubuntu-22.04
1514

1615
strategy:
1716
matrix:
18-
node-version: [16.x,20.x]
17+
node-version: [16.x, 20.x]
1918
steps:
19+
- name: Build Tools
20+
run: |
21+
sudo apt-get update
22+
sudo apt-get install -y build-essential cmake
23+
sudo apt-get install -y python3 python3-pip python-is-python3
2024
21-
- name: Build Tools
22-
run: |
23-
sudo apt-get update
24-
sudo apt-get install -y build-essential cmake
25-
sudo apt-get install -y python3 python3-pip python-is-python3
26-
27-
- name: Checkout TDengine
28-
uses: actions/checkout@v4
29-
with:
25+
- name: Checkout TDengine
26+
uses: actions/checkout@v4
27+
with:
3028
fetch-depth: 1
31-
repository: 'taosdata/TDengine'
32-
path: 'TDengine'
33-
ref: 'main'
34-
submodules: 'recursive'
35-
36-
- name: Install system dependencies
37-
run: |
38-
sudo apt update -y
39-
sudo apt install -y build-essential cmake \
40-
libgeos-dev libjansson-dev libsnappy-dev liblzma-dev libz-dev \
41-
zlib1g pkg-config libssl-dev gawk
42-
43-
- name: install TDengine
44-
run: |
45-
cd TDengine
46-
mkdir debug
47-
cd debug
48-
cmake .. -DBUILD_HTTP=false -DBUILD_JDBC=false -DBUILD_TOOLS=false -DBUILD_TEST=off -DBUILD_DEPENDENCY_TESTS=false
49-
make -j 4
50-
sudo make install
51-
which taosd
52-
which taosadapter
53-
54-
- name: start taosd
55-
run: |
56-
nohup sudo taosd &
29+
repository: "taosdata/TDengine"
30+
path: "TDengine"
31+
ref: "main"
32+
submodules: "recursive"
33+
34+
- name: Install system dependencies
35+
run: |
36+
sudo apt update -y
37+
sudo apt install -y build-essential cmake \
38+
libgeos-dev libjansson-dev libsnappy-dev liblzma-dev libz-dev \
39+
zlib1g pkg-config libssl-dev gawk
40+
41+
- name: install TDengine
42+
run: |
43+
cd TDengine
44+
mkdir debug
45+
cd debug
46+
cmake .. -DBUILD_HTTP=false -DBUILD_JDBC=false -DBUILD_TOOLS=false -DBUILD_TEST=off -DBUILD_DEPENDENCY_TESTS=false
47+
make -j 4
48+
sudo make install
49+
which taosd
50+
which taosadapter
5751
58-
- name: start taosadapter
59-
run: |
60-
nohup sudo taosadapter &
52+
- name: start taosd
53+
run: |
54+
nohup sudo taosd &
6155
62-
- name: Checkout current repo
63-
uses: actions/checkout@v4
64-
with:
65-
path: 'nodejs-connector'
66-
clean: true
67-
set-safe-directory: true
56+
- name: start taosadapter
57+
run: |
58+
nohup sudo taosadapter &
6859
60+
- name: Checkout current repo
61+
uses: actions/checkout@v4
62+
with:
63+
path: "nodejs-connector"
64+
clean: true
65+
set-safe-directory: true
6966

67+
- name: Use Node.js ${{ matrix.node-version }}
68+
uses: actions/setup-node@v3
69+
with:
70+
node-version: ${{ matrix.node-version }}
7071

71-
- name: Use Node.js ${{ matrix.node-version }}
72-
uses: actions/setup-node@v3
73-
with:
74-
node-version: ${{ matrix.node-version }}
72+
- name: test nodejs websocket
73+
working-directory: nodejs-connector/nodejs
74+
run: |
75+
export TDENGINE_CLOUD_URL=${{ secrets.TDENGINE_CLOUD_URL }}
76+
export TDENGINE_CLOUD_TOKEN=${{ secrets.TDENGINE_CLOUD_TOKEN }}
77+
ls -al
78+
npm install
79+
npm list
80+
npm run example
81+
npm run test
7582
76-
- name: test nodejs websocket
77-
working-directory: nodejs-connector/nodejs
78-
run: |
79-
export TDENGINE_CLOUD_URL=${{ secrets.TDENGINE_CLOUD_URL }}
80-
export TDENGINE_CLOUD_TOKEN=${{ secrets.TDENGINE_CLOUD_TOKEN }}
81-
ls -al
82-
npm install
83-
npm list
84-
npm run example
85-
npm run test
86-
87-
- name: Upload coverage to Codecov
88-
uses: codecov/codecov-action@v3
89-
with:
90-
fail_ci_if_error: false
91-
files: coverage/lcov.info
92-
verbose: true
93-
env:
94-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
83+
- name: Upload coverage to Codecov
84+
uses: codecov/codecov-action@v3
85+
with:
86+
fail_ci_if_error: false
87+
files: coverage/lcov.info
88+
verbose: true
89+
env:
90+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

README-CN.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313
[![LinkedIn](https://img.shields.io/badge/Follow_LinkedIn--white?logo=linkedin&style=social)](https://www.linkedin.com/company/tdengine)
1414
[![StackOverflow](https://img.shields.io/badge/Ask_StackOverflow--white?logo=stackoverflow&style=social&logoColor=orange)](https://stackoverflow.com/questions/tagged/tdengine)
1515

16-
1716
[English](README.md) | 简体中文
1817

19-
2018
## 目录
2119
<!-- omit in toc -->
2220

@@ -35,7 +33,6 @@
3533
- [9. 引用](#9-引用)
3634
- [10. 许可证](#10-许可证)
3735

38-
3936
## 1. 简介
4037

4138
@tdengine/websocket 是 TDengine 官方专为 Node.js 开发人员精心设计的一款高效连接器,它借助 taosAdapter 组件提供的 WebSocket API 与 TDengine 建立连接,摆脱了对 TDengine 客户端驱动的依赖 ,为开发者开辟了一条便捷的开发路径。凭借这一强大工具,开发人员能够轻松构建面向 TDengine 集群的应用程序。不管是执行复杂的 SQL 写入与查询任务,还是实现灵活的无模式写入操作,亦或是达成对实时性要求极高的订阅功能,这款连接器都能轻松胜任、完美实现,全方位满足多样化的数据交互需求。
@@ -44,13 +41,13 @@
4441

4542
- 使用 Node.js Connector, 请参考 [开发指南](https://docs.taosdata.com/develop/),包含了应用如何引入 @tdengine/websocket 和数据写入、查询、无模式写入、参数绑定和数据订阅等示例。
4643
- 其他参考信息请看 [参考手册](https://docs.taosdata.com/reference/connector/node/),包含了版本历史、数据类型、示例程序汇总、API 说明和常见问题等。
47-
- 本README主要是为想自己贡献、编译、测试 Node.js Connector 的开发者写的。如果要学习 TDengine,可以浏览 [官方文档](https://docs.taosdata.com/)
44+
- 本 README 主要是为想自己贡献、编译、测试 Node.js Connector 的开发者写的。如果要学习 TDengine,可以浏览 [官方文档](https://docs.taosdata.com/)
4845

4946
## 3. 前置条件
5047

51-
- 安装 Node.js 开发环境, 使用14以上版本[下载 Node.js](https://nodejs.org/en/download/)
48+
- 安装 Node.js 开发环境, 使用 14 以上版本[下载 Node.js](https://nodejs.org/en/download/)
5249
- 使用 npm 安装 TypeScript 5.3.3 以上版本。
53-
- 使用 npm 安装 Node.js 连接器依赖, 在项目的nodejs目录下执行 `npm install` 命令进行安装。
50+
- 使用 npm 安装 Node.js 连接器依赖, 在项目的 nodejs 目录下执行 `npm install` 命令进行安装。
5451
- 本地已经部署 TDengine,具体步骤请参考 [部署服务端](https://docs.taosdata.com/get-started/package/),且已经启动 `taosd``taosAdapter`
5552

5653
## 4. 构建
@@ -80,6 +77,7 @@ Ran all test suites.
8077
性能测试还在开发中。
8178

8279
## 6. CI/CD
80+
8381
- [Build Workflow](https://github.com/taosdata/taos-connector-node/actions/workflows/build.yaml)
8482
- [Code Coverage](https://app.codecov.io/gh/taosdata/taos-connector-node)
8583

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
[![StackOverflow](https://img.shields.io/badge/Ask_StackOverflow--white?logo=stackoverflow&style=social&logoColor=orange)](https://stackoverflow.com/questions/tagged/tdengine)
1515

1616
English | [简体中文](README-CN.md)
17+
1718
<!-- omit in toc -->
1819
## Table of Contents
1920
<!-- omit in toc -->
21+
2022
- [1. Introduction](#1-introduction)
2123
- [2. Documentation](#2-documentation)
2224
- [3. Prerequisites](#3-prerequisites)

nodejs/example/all_type_query.ts

Lines changed: 53 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,117 @@
1-
import { WSConfig } from '../src/common/config';
2-
import { sqlConnect, destroy, setLogLevel } from '../src'
1+
import { WSConfig } from "../src/common/config";
2+
import { sqlConnect, destroy, setLogLevel } from "../src";
33

4-
let dsn = 'ws://127.0.0.1:6041';
4+
let dsn = "ws://127.0.0.1:6041";
55
async function json_tag_example() {
66
let wsSql = null;
77
try {
8-
98
let conf = new WSConfig(dsn);
10-
conf.setUser('root');
11-
conf.setPwd('taosdata');
9+
conf.setUser("root");
10+
conf.setPwd("taosdata");
1211
wsSql = await sqlConnect(conf);
1312
console.log("Connected to " + dsn + " successfully.");
14-
13+
1514
// create database
16-
await wsSql.exec('CREATE DATABASE IF NOT EXISTS example_json_tag');
15+
await wsSql.exec("CREATE DATABASE IF NOT EXISTS example_json_tag");
1716
console.log("Create database example_json_tag successfully.");
18-
17+
1918
// create table
20-
await wsSql.exec('create table if not exists example_json_tag.stb (ts timestamp, v int) tags(jt json)');
19+
await wsSql.exec(
20+
"create table if not exists example_json_tag.stb (ts timestamp, v int) tags(jt json)"
21+
);
2122

2223
console.log("Create stable example_json_tag.stb successfully");
2324

24-
let insertQuery = 'INSERT INTO ' +
25+
let insertQuery =
26+
"INSERT INTO " +
2527
'example_json_tag.tb1 USING example_json_tag.stb TAGS(\'{"name":"value"}\') ' +
2628
"values(now, 1) ";
2729
let taosResult = await wsSql.exec(insertQuery);
28-
console.log("Successfully inserted " + taosResult.getAffectRows() + " rows to example_json_tag.stb.");
30+
console.log(
31+
"Successfully inserted " +
32+
taosResult.getAffectRows() +
33+
" rows to example_json_tag.stb."
34+
);
2935

30-
let sql = 'SELECT ts, v, jt FROM example_json_tag.stb limit 100';
36+
let sql = "SELECT ts, v, jt FROM example_json_tag.stb limit 100";
3137
let wsRows = await wsSql.query(sql);
3238
while (await wsRows.next()) {
3339
let row = wsRows.getData();
3440
if (row) {
35-
console.log('ts: ' + row[0] + ', v: ' + row[1] + ', jt: ' + row[2]);
41+
console.log(
42+
"ts: " + row[0] + ", v: " + row[1] + ", jt: " + row[2]
43+
);
3644
}
3745
}
38-
3946
} catch (err: any) {
40-
console.error(`Failed to create database example_json_tag or stable stb, ErrCode: ${err.code}, ErrMessage: ${err.message}`);
47+
console.error(
48+
`Failed to create database example_json_tag or stable stb, ErrCode: ${err.code}, ErrMessage: ${err.message}`
49+
);
4150
} finally {
4251
if (wsSql) {
4352
await wsSql.close();
4453
}
4554
}
46-
4755
}
4856

4957
async function all_type_example() {
5058
let wsSql = null;
5159
try {
5260
let conf = new WSConfig(dsn);
53-
conf.setUser('root');
54-
conf.setPwd('taosdata');
61+
conf.setUser("root");
62+
conf.setPwd("taosdata");
5563
wsSql = await sqlConnect(conf);
5664
console.log("Connected to " + dsn + " successfully.");
57-
65+
5866
// create database
59-
await wsSql.exec('CREATE DATABASE IF NOT EXISTS all_type_example');
67+
await wsSql.exec("CREATE DATABASE IF NOT EXISTS all_type_example");
6068
console.log("Create database all_type_example successfully.");
61-
69+
6270
// create table
63-
await wsSql.exec('create table if not exists all_type_example.stb (ts timestamp, ' +
64-
'int_col INT, double_col DOUBLE, bool_col BOOL, binary_col BINARY(100),' +
65-
'nchar_col NCHAR(100), varbinary_col VARBINARY(100), geometry_col GEOMETRY(100)) ' +
66-
'tags(int_tag INT, double_tag DOUBLE, bool_tag BOOL, binary_tag BINARY(100),' +
67-
'nchar_tag NCHAR(100), varbinary_tag VARBINARY(100), geometry_tag GEOMETRY(100));');
71+
await wsSql.exec(
72+
"create table if not exists all_type_example.stb (ts timestamp, " +
73+
"int_col INT, double_col DOUBLE, bool_col BOOL, binary_col BINARY(100)," +
74+
"nchar_col NCHAR(100), varbinary_col VARBINARY(100), geometry_col GEOMETRY(100)) " +
75+
"tags(int_tag INT, double_tag DOUBLE, bool_tag BOOL, binary_tag BINARY(100)," +
76+
"nchar_tag NCHAR(100), varbinary_tag VARBINARY(100), geometry_tag GEOMETRY(100));"
77+
);
6878

6979
console.log("Create stable all_type_example.stb successfully");
7080

71-
let insertQuery = "INSERT INTO all_type_example.tb1 using all_type_example.stb "
72-
+ "tags(1, 1.1, true, 'binary_value', 'nchar_value', '\\x98f46e', 'POINT(100 100)') "
73-
+ "values(now, 1, 1.1, true, 'binary_value', 'nchar_value', '\\x98f46e', 'POINT(100 100)')";
81+
let insertQuery =
82+
"INSERT INTO all_type_example.tb1 using all_type_example.stb " +
83+
"tags(1, 1.1, true, 'binary_value', 'nchar_value', '\\x98f46e', 'POINT(100 100)') " +
84+
"values(now, 1, 1.1, true, 'binary_value', 'nchar_value', '\\x98f46e', 'POINT(100 100)')";
7485
let taosResult = await wsSql.exec(insertQuery);
75-
console.log("Successfully inserted " + taosResult.getAffectRows() + " rows to all_type_example.stb.");
86+
console.log(
87+
"Successfully inserted " +
88+
taosResult.getAffectRows() +
89+
" rows to all_type_example.stb."
90+
);
7691

77-
let sql = 'SELECT * FROM all_type_example.stb limit 100';
92+
let sql = "SELECT * FROM all_type_example.stb limit 100";
7893
let wsRows = await wsSql.query(sql);
7994
let meta = wsRows.getMeta();
8095
console.log("wsRow:meta:=>", meta);
8196
while (await wsRows.next()) {
8297
let row = wsRows.getData();
8398
console.log(row);
8499
}
85-
86100
} catch (err: any) {
87-
console.error(`Failed to create database all_type_example or stable stb, ErrCode: ${err.code}, ErrMessage: ${err.message}`);
101+
console.error(
102+
`Failed to create database all_type_example or stable stb, ErrCode: ${err.code}, ErrMessage: ${err.message}`
103+
);
88104
} finally {
89105
if (wsSql) {
90106
await wsSql.close();
91107
}
92108
}
93-
94109
}
95110

96111
async function test() {
97-
await json_tag_example()
98-
await all_type_example()
112+
await json_tag_example();
113+
await all_type_example();
99114
destroy();
100115
}
101116

102-
test()
117+
test();

0 commit comments

Comments
 (0)