From e9bbc02df4f639eb734c41229544e652917c2b94 Mon Sep 17 00:00:00 2001 From: xleili Date: Fri, 12 Aug 2022 18:59:15 +0800 Subject: [PATCH] test(docs):add nodejs 3.0 reference sample to CI --- docs/examples/csharp/QueryExample.cs | 2 +- docs/examples/node/nativeexample/connect.js | 31 ++++++--------- docs/examples/node/restexample/connect.js | 2 +- tests/docs-examples-test/node.sh | 42 +++++++++++++++++++++ 4 files changed, 56 insertions(+), 21 deletions(-) create mode 100644 tests/docs-examples-test/node.sh diff --git a/docs/examples/csharp/QueryExample.cs b/docs/examples/csharp/QueryExample.cs index c90a8cd0b7..d75bb8d661 100644 --- a/docs/examples/csharp/QueryExample.cs +++ b/docs/examples/csharp/QueryExample.cs @@ -10,7 +10,7 @@ namespace TDengineExample { IntPtr conn = GetConnection(); // run query - IntPtr res = TDengine.Query(conn, "SELECT * FROM test.meters LIMIT 2"); + IntPtr res = TDengine.Query(conn, "SELECT * FROM meters LIMIT 2"); if (TDengine.ErrorNo(res) != 0) { Console.WriteLine("Failed to query since: " + TDengine.Error(res)); diff --git a/docs/examples/node/nativeexample/connect.js b/docs/examples/node/nativeexample/connect.js index bb027d4fe8..7971cc2348 100644 --- a/docs/examples/node/nativeexample/connect.js +++ b/docs/examples/node/nativeexample/connect.js @@ -1,20 +1,13 @@ -const { options, connect } = require("@tdengine/rest"); +//A cursor also needs to be initialized in order to interact with TDengine from Node.js. +const taos = require("@tdengine/client"); +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 -async function test() { - options.path = "/rest/sql"; - options.host = "localhost"; - let conn = connect(options); - let cursor = conn.cursor(); - try { - let res = await cursor.query("SELECT server_version()"); - res.toString(); - } catch (err) { - console.log(err); - } -} -test(); - -// output: -// server_version() | -// =================== -// 3.0.0.0 | +//Close a connection +conn.close(); \ No newline at end of file diff --git a/docs/examples/node/restexample/connect.js b/docs/examples/node/restexample/connect.js index 132e284ce9..bb027d4fe8 100644 --- a/docs/examples/node/restexample/connect.js +++ b/docs/examples/node/restexample/connect.js @@ -1,7 +1,7 @@ const { options, connect } = require("@tdengine/rest"); async function test() { - options.path = "/rest/sqlt"; + options.path = "/rest/sql"; options.host = "localhost"; let conn = connect(options); let cursor = conn.cursor(); diff --git a/tests/docs-examples-test/node.sh b/tests/docs-examples-test/node.sh new file mode 100644 index 0000000000..0283904815 --- /dev/null +++ b/tests/docs-examples-test/node.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +set -e + +pgrep taosd || taosd >> /dev/null 2>&1 & +pgrep taosadapter || taosadapter >> /dev/null 2>&1 & + +cd ../../docs/examples/node + +npm install +cd restexample; + +node connect.js + +cd ../nativeexample + +node connect.js + +taos -s "drop database if exists power" +node insert_example.js + +node query_example.js + +node async_query_example.js + +node subscribe_demo.js + +taos -s "drop topic if exists topic_name_example" +taos -s "drop database if exists power" +node param_bind_example.js + +taos -s "drop database if exists power" +node multi_bind_example.js + +taos -s "drop database if exists test" +node influxdb_line_example.js + +taos -s "drop database if exists test" +node opentsdb_telnet_example.js + +taos -s "drop database if exists test" +node opentsdb_json_example.js \ No newline at end of file