Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
138 changes: 67 additions & 71 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,91 +4,87 @@ name: nodejs Release

on:
push:
branches: ['main']
branches: ["main"]
pull_request:
branches: ['main']
branches: ["main"]

jobs:
build:

runs-on: ubuntu-22.04

strategy:
matrix:
node-version: [16.x,20.x]
node-version: [16.x, 20.x]
steps:
- name: Build Tools
run: |
sudo apt-get update
sudo apt-get install -y build-essential cmake
sudo apt-get install -y python3 python3-pip python-is-python3

- name: Build Tools
run: |
sudo apt-get update
sudo apt-get install -y build-essential cmake
sudo apt-get install -y python3 python3-pip python-is-python3

- name: Checkout TDengine
uses: actions/checkout@v4
with:
- name: Checkout TDengine
uses: actions/checkout@v4
with:
fetch-depth: 1
repository: 'taosdata/TDengine'
path: 'TDengine'
ref: 'main'
submodules: 'recursive'

- name: Install system dependencies
run: |
sudo apt update -y
sudo apt install -y build-essential cmake \
libgeos-dev libjansson-dev libsnappy-dev liblzma-dev libz-dev \
zlib1g pkg-config libssl-dev gawk

- name: install TDengine
run: |
cd TDengine
mkdir debug
cd debug
cmake .. -DBUILD_HTTP=false -DBUILD_JDBC=false -DBUILD_TOOLS=false -DBUILD_TEST=off -DBUILD_DEPENDENCY_TESTS=false
make -j 4
sudo make install
which taosd
which taosadapter

- name: start taosd
run: |
nohup sudo taosd &
repository: "taosdata/TDengine"
path: "TDengine"
ref: "main"
submodules: "recursive"

- name: Install system dependencies
run: |
sudo apt update -y
sudo apt install -y build-essential cmake \
libgeos-dev libjansson-dev libsnappy-dev liblzma-dev libz-dev \
zlib1g pkg-config libssl-dev gawk

- name: install TDengine
run: |
cd TDengine
mkdir debug
cd debug
cmake .. -DBUILD_HTTP=false -DBUILD_JDBC=false -DBUILD_TOOLS=false -DBUILD_TEST=off -DBUILD_DEPENDENCY_TESTS=false
make -j 4
sudo make install
which taosd
which taosadapter

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

- name: Checkout current repo
uses: actions/checkout@v4
with:
path: 'nodejs-connector'
clean: true
set-safe-directory: true
- name: start taosadapter
run: |
nohup sudo taosadapter &

- name: Checkout current repo
uses: actions/checkout@v4
with:
path: "nodejs-connector"
clean: true
set-safe-directory: true

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: test nodejs websocket
working-directory: nodejs-connector/nodejs
run: |
export TDENGINE_CLOUD_URL=${{ secrets.TDENGINE_CLOUD_URL }}
export TDENGINE_CLOUD_TOKEN=${{ secrets.TDENGINE_CLOUD_TOKEN }}
ls -al
npm install
npm list
npm run example
npm run test

- name: test nodejs websocket
working-directory: nodejs-connector/nodejs
run: |
export TDENGINE_CLOUD_URL=${{ secrets.TDENGINE_CLOUD_URL }}
export TDENGINE_CLOUD_TOKEN=${{ secrets.TDENGINE_CLOUD_TOKEN }}
ls -al
npm install
npm list
npm run example
npm run test

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: false
files: coverage/lcov.info
verbose: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: false
files: coverage/lcov.info
verbose: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
10 changes: 4 additions & 6 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
[![LinkedIn](https://img.shields.io/badge/Follow_LinkedIn--white?logo=linkedin&style=social)](https://www.linkedin.com/company/tdengine)
[![StackOverflow](https://img.shields.io/badge/Ask_StackOverflow--white?logo=stackoverflow&style=social&logoColor=orange)](https://stackoverflow.com/questions/tagged/tdengine)


[English](README.md) | 简体中文


## 目录
<!-- omit in toc -->

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


## 1. 简介

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

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

## 3. 前置条件

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

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

## 6. CI/CD

- [Build Workflow](https://github.com/taosdata/taos-connector-node/actions/workflows/build.yaml)
- [Code Coverage](https://app.codecov.io/gh/taosdata/taos-connector-node)

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
[![StackOverflow](https://img.shields.io/badge/Ask_StackOverflow--white?logo=stackoverflow&style=social&logoColor=orange)](https://stackoverflow.com/questions/tagged/tdengine)

English | [简体中文](README-CN.md)

<!-- omit in toc -->
## Table of Contents
<!-- omit in toc -->

- [1. Introduction](#1-introduction)
- [2. Documentation](#2-documentation)
- [3. Prerequisites](#3-prerequisites)
Expand Down
91 changes: 53 additions & 38 deletions nodejs/example/all_type_query.ts
Original file line number Diff line number Diff line change
@@ -1,102 +1,117 @@
import { WSConfig } from '../src/common/config';
import { sqlConnect, destroy, setLogLevel } from '../src'
import { WSConfig } from "../src/common/config";
import { sqlConnect, destroy, setLogLevel } from "../src";

let dsn = 'ws://127.0.0.1:6041';
let dsn = "ws://127.0.0.1:6041";
async function json_tag_example() {
let wsSql = null;
try {

let conf = new WSConfig(dsn);
conf.setUser('root');
conf.setPwd('taosdata');
conf.setUser("root");
conf.setPwd("taosdata");
wsSql = await sqlConnect(conf);
console.log("Connected to " + dsn + " successfully.");

// create database
await wsSql.exec('CREATE DATABASE IF NOT EXISTS example_json_tag');
await wsSql.exec("CREATE DATABASE IF NOT EXISTS example_json_tag");
console.log("Create database example_json_tag successfully.");

// create table
await wsSql.exec('create table if not exists example_json_tag.stb (ts timestamp, v int) tags(jt json)');
await wsSql.exec(
"create table if not exists example_json_tag.stb (ts timestamp, v int) tags(jt json)"
);

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

let insertQuery = 'INSERT INTO ' +
let insertQuery =
"INSERT INTO " +
'example_json_tag.tb1 USING example_json_tag.stb TAGS(\'{"name":"value"}\') ' +
"values(now, 1) ";
let taosResult = await wsSql.exec(insertQuery);
console.log("Successfully inserted " + taosResult.getAffectRows() + " rows to example_json_tag.stb.");
console.log(
"Successfully inserted " +
taosResult.getAffectRows() +
" rows to example_json_tag.stb."
);

let sql = 'SELECT ts, v, jt FROM example_json_tag.stb limit 100';
let sql = "SELECT ts, v, jt FROM example_json_tag.stb limit 100";
let wsRows = await wsSql.query(sql);
while (await wsRows.next()) {
let row = wsRows.getData();
if (row) {
console.log('ts: ' + row[0] + ', v: ' + row[1] + ', jt: ' + row[2]);
console.log(
"ts: " + row[0] + ", v: " + row[1] + ", jt: " + row[2]
);
}
}

} catch (err: any) {
console.error(`Failed to create database example_json_tag or stable stb, ErrCode: ${err.code}, ErrMessage: ${err.message}`);
console.error(
`Failed to create database example_json_tag or stable stb, ErrCode: ${err.code}, ErrMessage: ${err.message}`
);
} finally {
if (wsSql) {
await wsSql.close();
}
}

}

async function all_type_example() {
let wsSql = null;
try {
let conf = new WSConfig(dsn);
conf.setUser('root');
conf.setPwd('taosdata');
conf.setUser("root");
conf.setPwd("taosdata");
wsSql = await sqlConnect(conf);
console.log("Connected to " + dsn + " successfully.");

// create database
await wsSql.exec('CREATE DATABASE IF NOT EXISTS all_type_example');
await wsSql.exec("CREATE DATABASE IF NOT EXISTS all_type_example");
console.log("Create database all_type_example successfully.");

// 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));');
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));"
);

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

let insertQuery = "INSERT INTO all_type_example.tb1 using all_type_example.stb "
+ "tags(1, 1.1, true, 'binary_value', 'nchar_value', '\\x98f46e', 'POINT(100 100)') "
+ "values(now, 1, 1.1, true, 'binary_value', 'nchar_value', '\\x98f46e', 'POINT(100 100)')";
let insertQuery =
"INSERT INTO all_type_example.tb1 using all_type_example.stb " +
"tags(1, 1.1, true, 'binary_value', 'nchar_value', '\\x98f46e', 'POINT(100 100)') " +
"values(now, 1, 1.1, true, 'binary_value', 'nchar_value', '\\x98f46e', 'POINT(100 100)')";
let taosResult = await wsSql.exec(insertQuery);
console.log("Successfully inserted " + taosResult.getAffectRows() + " rows to all_type_example.stb.");
console.log(
"Successfully inserted " +
taosResult.getAffectRows() +
" rows to all_type_example.stb."
);

let sql = 'SELECT * FROM all_type_example.stb limit 100';
let sql = "SELECT * FROM all_type_example.stb limit 100";
let wsRows = await wsSql.query(sql);
let meta = wsRows.getMeta();
console.log("wsRow:meta:=>", meta);
while (await wsRows.next()) {
let row = wsRows.getData();
console.log(row);
}

} catch (err: any) {
console.error(`Failed to create database all_type_example or stable stb, ErrCode: ${err.code}, ErrMessage: ${err.message}`);
console.error(
`Failed to create database all_type_example or stable stb, ErrCode: ${err.code}, ErrMessage: ${err.message}`
);
} finally {
if (wsSql) {
await wsSql.close();
}
}

}

async function test() {
await json_tag_example()
await all_type_example()
await json_tag_example();
await all_type_example();
destroy();
}

test()
test();
Loading