diff --git a/docs/examples/node/websocketexample/stmt_example.js b/docs/examples/node/websocketexample/stmt_example.js
index 842a8a4c3d..1b78e4bccd 100644
--- a/docs/examples/node/websocketexample/stmt_example.js
+++ b/docs/examples/node/websocketexample/stmt_example.js
@@ -2,13 +2,13 @@ const taos = require("@tdengine/websocket");
let db = 'power';
let stable = 'meters';
-let tags = ['California.SanFrancisco', 3];
-let values = [
- [1706786044994, 1706786044995, 1706786044996],
- [10.2, 10.3, 10.4],
- [292, 293, 294],
- [0.32, 0.33, 0.34],
-];
+let numOfSubTable = 10;
+let numOfRow = 10;
+function getRandomInt(min, max) {
+ min = Math.ceil(min);
+ max = Math.floor(max);
+ return Math.floor(Math.random() * (max - min + 1)) + min;
+}
async function prepare() {
let dsn = 'ws://localhost:6041'
@@ -29,24 +29,36 @@ async function prepare() {
connector = await prepare();
stmt = await connector.stmtInit();
await stmt.prepare(`INSERT INTO ? USING ${db}.${stable} (location, groupId) TAGS (?, ?) VALUES (?, ?, ?, ?)`);
- await stmt.setTableName('d1001');
- let tagParams = stmt.newStmtParam();
- tagParams.setVarchar([tags[0]]);
- tagParams.setInt([tags[1]]);
- await stmt.setTags(tagParams);
-
- let bindParams = stmt.newStmtParam();
- bindParams.setTimestamp(values[0]);
- bindParams.setFloat(values[1]);
- bindParams.setInt(values[2]);
- bindParams.setFloat(values[3]);
- await stmt.bind(bindParams);
- await stmt.batch();
- await stmt.exec();
- console.log(stmt.getLastAffected());
+ for (let i = 0; i < numOfSubTable; i++) {
+ await stmt.setTableName(`d_bind_${i}`);
+ let tagParams = stmt.newStmtParam();
+ tagParams.setVarchar([`location_${i}`]);
+ tagParams.setInt([i]);
+ await stmt.setTags(tagParams);
+ let timestampParams = [];
+ let currentParams = [];
+ let voltageParams = [];
+ let phaseParams = [];
+ const currentMillis = new Date().getTime();
+ for (let j = 0; j < numOfRow; j++) {
+ timestampParams.push(currentMillis + j);
+ currentParams.push(Math.random() * 30);
+ voltageParams.push(getRandomInt(100, 300));
+ phaseParams.push(Math.random());
+ }
+ let bindParams = stmt.newStmtParam();
+ bindParams.setTimestamp(timestampParams);
+ bindParams.setFloat(currentParams);
+ bindParams.setInt(voltageParams);
+ bindParams.setFloat(phaseParams);
+ await stmt.bind(bindParams);
+ await stmt.batch();
+ await stmt.exec();
+ console.log(`d_bind_${i} insert ` + stmt.getLastAffected() + " rows.");
+ }
}
- catch (err) {
- console.error(err.code, err.message);
+ catch (e) {
+ console.error(e);
}
finally {
if (stmt) {
diff --git a/docs/examples/node/websocketexample/tmq_example.js b/docs/examples/node/websocketexample/tmq_example.js
index 9b77abe4d0..b7a8d13809 100644
--- a/docs/examples/node/websocketexample/tmq_example.js
+++ b/docs/examples/node/websocketexample/tmq_example.js
@@ -7,24 +7,30 @@ const topics = ['power_meters_topic'];
// ANCHOR: create_consumer
async function createConsumer() {
let configMap = new Map([
- [taos.TMQConstants.GROUP_ID, "gId"],
+ [taos.TMQConstants.GROUP_ID, "group1"],
+ [taos.TMQConstants.CLIENT_ID, 'client1'],
[taos.TMQConstants.CONNECT_USER, "root"],
[taos.TMQConstants.CONNECT_PASS, "taosdata"],
[taos.TMQConstants.AUTO_OFFSET_RESET, "latest"],
- [taos.TMQConstants.CLIENT_ID, 'test_tmq_client'],
[taos.TMQConstants.WS_URL, 'ws://localhost:6041'],
[taos.TMQConstants.ENABLE_AUTO_COMMIT, 'true'],
[taos.TMQConstants.AUTO_COMMIT_INTERVAL_MS, '1000']
]);
- return await taos.tmqConnect(configMap);
+ try {
+ return await taos.tmqConnect(configMap);
+ }catch (err) {
+ console.log(err);
+ throw err;
+ }
+
}
// ANCHOR_END: create_consumer
async function prepare() {
let conf = new taos.WSConfig('ws://localhost:6041');
- conf.setUser('root')
- conf.setPwd('taosdata')
- conf.setDb('power')
+ conf.setUser('root');
+ conf.setPwd('taosdata');
+ conf.setDb('power');
const createDB = `CREATE DATABASE IF NOT EXISTS POWER ${db} KEEP 3650 DURATION 10 BUFFER 16 WAL_LEVEL 1;`;
const createStable = `CREATE STABLE IF NOT EXISTS ${db}.${stable} (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupId int);`;
diff --git a/docs/examples/python/connect_example.py b/docs/examples/python/connect_example.py
index 493cd512ee..744f2aa49e 100644
--- a/docs/examples/python/connect_example.py
+++ b/docs/examples/python/connect_example.py
@@ -4,14 +4,14 @@ def create_connection():
# all parameters are optional.
conn = None
try:
- conn = taosws.connect(
+ conn = taos.connect(
user="root",
password="taosdata",
- host="192.168.1.98",
+ host="localhost",
port=6041,
)
except Exception as err:
- print(f'Exception {err}')
+ print(err)
finally:
if conn:
conn.close()
diff --git a/docs/examples/python/connect_rest_with_req_id_examples.py b/docs/examples/python/connect_rest_with_req_id_examples.py
index 568cbea168..7d90bef158 100644
--- a/docs/examples/python/connect_rest_with_req_id_examples.py
+++ b/docs/examples/python/connect_rest_with_req_id_examples.py
@@ -1,11 +1,12 @@
# ANCHOR: connect
from taosrest import connect, TaosRestConnection, TaosRestCursor
-conn = connect(url="http://localhost:6041",
- user="root",
- password="taosdata",
- timeout=30)
+conn = connect(url="http://localhost:6041",
+ user="root",
+ password="taosdata",
+ timeout=30)
+
# ANCHOR_END: connect
# ANCHOR: basic
# create STable
diff --git a/docs/examples/python/connect_websocket_examples.py b/docs/examples/python/connect_websocket_examples.py
index 69c3900187..3d93634bcc 100644
--- a/docs/examples/python/connect_websocket_examples.py
+++ b/docs/examples/python/connect_websocket_examples.py
@@ -1,19 +1,20 @@
+# ANCHOR: connect
import taosws
def create_connection():
conn = None
-# ANCHOR: connect
try:
conn = taosws.connect(
user="root",
password="taosdata",
- host="192.168.1.98",
+ host="localhost",
port=6041,
)
except Exception as err:
- print(f'Exception {err}')
-# ANCHOR_END: connect
+ print(err)
+
return conn
+ # ANCHOR_END: connect
def create_db_table(conn):
# ANCHOR: create_db
diff --git a/docs/examples/python/create_db_native.py b/docs/examples/python/create_db_native.py
index 6eeb94b879..3404363dc3 100644
--- a/docs/examples/python/create_db_native.py
+++ b/docs/examples/python/create_db_native.py
@@ -1,26 +1,33 @@
import taos
-conn = taos.connect(
- host="localhost",
- user="root",
- password="taosdata",
- port=6030,
-)
+conn = None
+try:
+ conn = taos.connect(host="localhost",
+ user="root",
+ password="taosdata",
+ port=6030)
-db = "power"
+ db = "power"
+ # create database
+ rowsAffected = conn.execute(f"CREATE DATABASE IF NOT EXISTS {db}")
+ assert rowsAffected == 0
-conn.execute(f"DROP DATABASE IF EXISTS {db}")
-conn.execute(f"CREATE DATABASE {db}")
+ # change database. same as execute "USE db"
+ rowsAffected = conn.select_db(db)
+ assert rowsAffected == 0
+
+ # create super table
+ rowsAffected = conn.execute(
+ "CREATE TABLE IF NOT EXISTS `meters` (`ts` TIMESTAMP, `current` FLOAT, `voltage` INT, `phase` FLOAT) TAGS (`groupid` INT, `location` BINARY(16))"
+ )
+ assert rowsAffected == 0
-# change database. same as execute "USE db"
-conn.select_db(db)
+ # create table
+ rowsAffected = conn.execute("CREATE TABLE IF NOT EXISTS `d0` USING `meters` (groupid, location) TAGS(0, 'Los Angles')")
+ assert rowsAffected == 0
-# create super table
-conn.execute(
- "CREATE TABLE `meters` (`ts` TIMESTAMP, `current` FLOAT, `voltage` INT, `phase` FLOAT) TAGS (`groupid` INT, `location` BINARY(16))"
-)
-
-# create table
-conn.execute("CREATE TABLE `d0` USING `meters` TAGS(0, 'Los Angles')")
-
-conn.close()
+except Exception as err:
+ print(err)
+finally:
+ if conn:
+ conn.close()
diff --git a/docs/examples/python/create_db_rest.py b/docs/examples/python/create_db_rest.py
index fc262b30f8..818fa748ad 100644
--- a/docs/examples/python/create_db_rest.py
+++ b/docs/examples/python/create_db_rest.py
@@ -1,18 +1,28 @@
import taosrest
-conn = taosrest.connect(url="http://localhost:6041")
+conn = None
+try:
+ conn = taosrest.connect(url="http://localhost:6041",
+ user="root",
+ password="taosdata",
+ timeout=30)
-db = "power"
+ db = "power"
+ # create database
+ rowsAffected = conn.execute(f"CREATE DATABASE IF NOT EXISTS {db}")
+ assert rowsAffected == 0
-conn.execute(f"DROP DATABASE IF EXISTS {db}")
-conn.execute(f"CREATE DATABASE {db}")
+ # create super table
+ rowsAffected = conn.execute(
+ f"CREATE TABLE IF NOT EXISTS `{db}`.`meters` (`ts` TIMESTAMP, `current` FLOAT, `voltage` INT, `phase` FLOAT) TAGS (`groupid` INT, `location` BINARY(16))"
+ )
+ assert rowsAffected == 0
+ # create table
+ rowsAffected = conn.execute(f"CREATE TABLE IF NOT EXISTS `{db}`.`d0` USING `{db}`.`meters` (groupid, location) TAGS(0, 'Los Angles')")
+ assert rowsAffected == 0
-# create super table
-conn.execute(
- f"CREATE TABLE `{db}`.`meters` (`ts` TIMESTAMP, `current` FLOAT, `voltage` INT, `phase` FLOAT) TAGS (`groupid` INT, `location` BINARY(16))"
-)
-
-# create table
-conn.execute(f"CREATE TABLE `{db}`.`d0` USING `{db}`.`meters` TAGS(0, 'Los Angles')")
-
-conn.close()
+except Exception as err:
+ print(err)
+finally:
+ if conn:
+ conn.close()
diff --git a/docs/examples/python/create_db_ws.py b/docs/examples/python/create_db_ws.py
index 844f7a56e3..8c43af8db2 100644
--- a/docs/examples/python/create_db_ws.py
+++ b/docs/examples/python/create_db_ws.py
@@ -1,22 +1,34 @@
import taosws
-dsn = "taosws://root:taosdata@localhost:6041"
-conn = taosws.connect(dsn)
+conn = None
-db = "power"
+try:
+ conn = taosws.connect(user="root",
+ password="taosdata",
+ host="localhost",
+ port=6041)
-conn.execute(f"DROP DATABASE IF EXISTS {db}")
-conn.execute(f"CREATE DATABASE {db}")
+ db = "power"
+ # create database
+ rowsAffected = conn.execute(f"CREATE DATABASE IF NOT EXISTS {db}")
+ assert rowsAffected == 0
-# change database.
-conn.execute(f"USE {db}")
+ # change database.
+ rowsAffected = conn.execute(f"USE {db}")
+ assert rowsAffected == 0
+
+ # create super table
+ rowsAffected = conn.execute(
+ "CREATE TABLE IF NOT EXISTS `meters` (`ts` TIMESTAMP, `current` FLOAT, `voltage` INT, `phase` FLOAT) TAGS (`groupid` INT, `location` BINARY(16))"
+ )
+ assert rowsAffected == 0
-# create super table
-conn.execute(
- "CREATE TABLE `meters` (`ts` TIMESTAMP, `current` FLOAT, `voltage` INT, `phase` FLOAT) TAGS (`groupid` INT, `location` BINARY(16))"
-)
+ # create table
+ rowsAffected = conn.execute("CREATE TABLE IF NOT EXISTS `d0` USING `meters` (groupid, location) TAGS(0, 'Los Angles')")
+ assert rowsAffected == 0
-# create table
-conn.execute("CREATE TABLE `d0` USING `meters` TAGS(0, 'Los Angles')")
-
-conn.close()
+except Exception as err:
+ print(err)
+finally:
+ if conn:
+ conn.close()
diff --git a/docs/examples/python/insert_native.py b/docs/examples/python/insert_native.py
index 37bbb807ec..faf4554437 100644
--- a/docs/examples/python/insert_native.py
+++ b/docs/examples/python/insert_native.py
@@ -1,76 +1,26 @@
import taos
-conn = taos.connect(
- host="localhost",
- user="root",
- password="taosdata",
- port=6030,
-)
+conn = None
-db = "power"
+try:
+ conn = taos.connect(user="root",
+ password="taosdata",
+ host="localhost",
+ port=6041)
-conn.execute(f"DROP DATABASE IF EXISTS {db}")
-conn.execute(f"CREATE DATABASE {db}")
+ sql = """
+ INSERT INTO
+ power.d1001 USING power.meters (groupid, location) TAGS(2, 'California.SanFrancisco')
+ VALUES (NOW + 1a, 10.30000, 219, 0.31000)
+ (NOW + 2a, 12.60000, 218, 0.33000) (NOW + 3a, 12.30000, 221, 0.31000)
+ power.d1002 USING power.meters (groupid, location) TAGS(3, 'California.SanFrancisco')
+ VALUES (NOW + 1a, 10.30000, 218, 0.25000)
+ """
+ inserted = conn.execute(sql)
+ print("inserted into {affectedRows} rows to power.meters successfully.")
-# change database. same as execute "USE db"
-conn.select_db(db)
-
-# create super table
-conn.execute(
- "CREATE STABLE power.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)"
-)
-
-# ANCHOR: insert
-# insert data
-sql = """
-INSERT INTO
-power.d1001 USING power.meters TAGS('California.SanFrancisco', 2)
- VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000)
- ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000)
-power.d1002 USING power.meters TAGS('California.SanFrancisco', 3)
- VALUES ('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000)
-power.d1003 USING power.meters TAGS('California.LosAngeles', 2)
- VALUES ('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000) ('2018-10-03 14:38:16.600', 13.40000, 223, 0.29000)
-power.d1004 USING power.meters TAGS('California.LosAngeles', 3)
- VALUES ('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000) ('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)
-"""
-
-inserted = conn.execute(sql)
-assert inserted == 8
-# ANCHOR_END: insert
-
-# ANCHOR: query
-# Execute a sql and get its result set. It's useful for SELECT statement
-result = conn.query("SELECT * from meters")
-
-# Get fields from result
-fields = result.fields
-for field in fields:
- print(field)
-
-"""
-output:
-{name: ts, type: 9, bytes: 8}
-{name: current, type: 6, bytes: 4}
-{name: voltage, type: 4, bytes: 4}
-{name: phase, type: 6, bytes: 4}
-{name: location, type: 8, bytes: 64}
-{name: groupid, type: 4, bytes: 4}
-"""
-
-# Get data from result as list of tuple
-data = result.fetch_all()
-for row in data:
- print(row)
-
-"""
-output:
-(datetime.datetime(2018, 10, 3, 14, 38, 16, 650000), 10.300000190734863, 218, 0.25, 'California.SanFrancisco', 3)
-...
-"""
-# ANCHOR_END: query
-
-# ANCHOR: req_id
-result = conn.query("SELECT * from meters", req_id=1)
-# ANCHOR_END: req_id
-conn.close()
+except Exception as err:
+ print(err)
+finally:
+ if conn:
+ conn.close()
diff --git a/docs/examples/python/insert_rest.py b/docs/examples/python/insert_rest.py
index 16b8fe669c..c43a6a6d17 100644
--- a/docs/examples/python/insert_rest.py
+++ b/docs/examples/python/insert_rest.py
@@ -1,48 +1,26 @@
import taosrest
-conn = taosrest.connect(url="http://localhost:6041")
+conn = None
-db = "power"
+try:
+ conn = taosrest.connect(url="http://localhost:6041",
+ user="root",
+ password="taosdata",
+ timeout=30)
-conn.execute(f"DROP DATABASE IF EXISTS {db}")
-conn.execute(f"CREATE DATABASE {db}")
+ sql = """
+ INSERT INTO
+ power.d1001 USING power.meters (groupid, location) TAGS(2, 'California.SanFrancisco')
+ VALUES (NOW + 1a, 10.30000, 219, 0.31000)
+ (NOW + 2a, 12.60000, 218, 0.33000) (NOW + 3a, 12.30000, 221, 0.31000)
+ power.d1002 USING power.meters (groupid, location) TAGS(3, 'California.SanFrancisco')
+ VALUES (NOW + 1a, 10.30000, 218, 0.25000)
+ """
+ affectedRows = conn.execute(sql)
+ print(f"inserted into {affectedRows} rows to power.meters successfully.")
-# create super table
-conn.execute(
- "CREATE STABLE power.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)"
-)
-
-# ANCHOR: insert
-# rest insert data
-sql = """
-INSERT INTO
-power.d1001 USING power.meters TAGS('California.SanFrancisco', 2)
- VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000)
- ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000)
-power.d1002 USING power.meters TAGS('California.SanFrancisco', 3)
- VALUES ('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000)
-power.d1003 USING power.meters TAGS('California.LosAngeles', 2)
- VALUES ('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000) ('2018-10-03 14:38:16.600', 13.40000, 223, 0.29000)
-power.d1004 USING power.meters TAGS('California.LosAngeles', 3)
- VALUES ('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000) ('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)
-"""
-
-inserted = conn.execute(sql)
-assert inserted == 8
-# ANCHOR_END: insert
-
-# ANCHOR: query
-client = taosrest.RestClient("http://localhost:6041")
-result = client.sql(f"SELECT * from {db}.meters")
-print(result)
-
-"""
-output:
-{'code': 0, 'column_meta': [['ts', 'TIMESTAMP', 8], ['current', 'FLOAT', 4], ['voltage', 'INT', 4], ['phase', 'FLOAT', 4], ['location', 'VARCHAR', 64], ['groupid', 'INT', 4]], 'data': [[datetime.datetime(2018, 10, 3, 14, 38, 5), 10.3, 219, 0.31, 'California.SanFrancisco', 2], [datetime.datetime(2018, 10, 3, 14, 38, 15), 12.6, 218, 0.33, 'California.SanFrancisco', 2], [datetime.datetime(2018, 10, 3, 14, 38, 16, 800000), 12.3, 221, 0.31, 'California.SanFrancisco', 2], [datetime.datetime(2018, 10, 3, 14, 38, 16, 650000), 10.3, 218, 0.25, 'California.SanFrancisco', 3], [datetime.datetime(2018, 10, 3, 14, 38, 5, 500000), 11.8, 221, 0.28, 'California.LosAngeles', 2], [datetime.datetime(2018, 10, 3, 14, 38, 16, 600000), 13.4, 223, 0.29, 'California.LosAngeles', 2], [datetime.datetime(2018, 10, 3, 14, 38, 5), 10.8, 223, 0.29, 'California.LosAngeles', 3], [datetime.datetime(2018, 10, 3, 14, 38, 6, 500000), 11.5, 221, 0.35, 'California.LosAngeles', 3]], 'rows': 8}
-"""
-# ANCHOR_END: query
-
-# ANCHOR: req_id
-result = client.sql(f"SELECT * from {db}.meters", req_id=1)
-# ANCHOR_END: req_id
-conn.close()
+except Exception as err:
+ print(err)
+finally:
+ if conn:
+ conn.close()
diff --git a/docs/examples/python/insert_ws.py b/docs/examples/python/insert_ws.py
index ef3ae3ea99..1d7aa7fc5d 100644
--- a/docs/examples/python/insert_ws.py
+++ b/docs/examples/python/insert_ws.py
@@ -1,71 +1,26 @@
import taosws
-dsn = "taosws://root:taosdata@localhost:6041"
-conn = taosws.connect(dsn)
+conn = None
-db = "power"
+try:
+ conn = taosws.connect(user="root",
+ password="taosdata",
+ host="localhost",
+ port=6041)
-conn.execute(f"DROP DATABASE IF EXISTS {db}")
-conn.execute(f"CREATE DATABASE {db}")
+ sql = """
+ INSERT INTO
+ power.d1001 USING power.meters (groupid, location) TAGS(2, 'California.SanFrancisco')
+ VALUES (NOW + 1a, 10.30000, 219, 0.31000)
+ (NOW + 2a, 12.60000, 218, 0.33000) (NOW + 3a, 12.30000, 221, 0.31000)
+ power.d1002 USING power.meters (groupid, location) TAGS(3, 'California.SanFrancisco')
+ VALUES (NOW + 1a, 10.30000, 218, 0.25000)
+ """
+ inserted = conn.execute(sql)
+ print("inserted into {affectedRows} rows to power.meters successfully.")
-# change database.
-conn.execute(f"USE {db}")
-
-# create super table
-conn.execute(
- "CREATE STABLE power.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)"
-)
-
-# ANCHOR: insert
-# ws insert data
-sql = """
-INSERT INTO
-power.d1001 USING power.meters TAGS('California.SanFrancisco', 2)
- VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000)
- ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000)
-power.d1002 USING power.meters TAGS('California.SanFrancisco', 3)
- VALUES ('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000)
-power.d1003 USING power.meters TAGS('California.LosAngeles', 2)
- VALUES ('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000) ('2018-10-03 14:38:16.600', 13.40000, 223, 0.29000)
-power.d1004 USING power.meters TAGS('California.LosAngeles', 3)
- VALUES ('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000) ('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)
-"""
-
-inserted = conn.execute(sql)
-assert inserted == 8
-# ANCHOR_END: insert
-
-# ANCHOR: query
-# Execute a sql and get its result set. It's useful for SELECT statement
-result = conn.query("SELECT * from meters")
-
-# Get fields from result
-fields = result.fields
-for field in fields:
- print(field)
-
-"""
-output:
-{name: ts, type: TIMESTAMP, bytes: 8}
-{name: current, type: FLOAT, bytes: 4}
-{name: voltage, type: INT, bytes: 4}
-{name: phase, type: FLOAT, bytes: 4}
-{name: location, type: BINARY, bytes: 64}
-{name: groupid, type: INT, bytes: 4}
-"""
-
-# Get rows from result
-for row in result:
- print(row)
-
-"""
-output:
-('2018-10-03 14:38:05 +08:00', 10.300000190734863, 219, 0.3100000023841858, 'California.SanFrancisco', 2)
-...
-"""
-# ANCHOR_END: query
-
-# ANCHOR: req_id
-result = conn.query_with_req_id("SELECT * from meters", req_id=1)
-# ANCHOR_END: req_id
-conn.close()
+except Exception as err:
+ print(err)
+finally:
+ if conn:
+ conn.close()
diff --git a/docs/zh/08-develop/01-connect/index.md b/docs/zh/08-develop/01-connect/index.md
index 5a0732f92b..21d11df23c 100644
--- a/docs/zh/08-develop/01-connect/index.md
+++ b/docs/zh/08-develop/01-connect/index.md
@@ -536,7 +536,7 @@ DSN 的详细说明和如何使用详见 [连接功能](../../reference/connecto
```python
-{{#include docs/examples/python/connect_rest_examples.py:connect}}
+{{#include docs/examples/python/connect_rest_example.py:connect}}
```
diff --git a/docs/zh/08-develop/02-sql.md b/docs/zh/08-develop/02-sql.md
index 2bc428bebf..8871dee786 100644
--- a/docs/zh/08-develop/02-sql.md
+++ b/docs/zh/08-develop/02-sql.md
@@ -33,8 +33,18 @@ REST API:通过 `curl` 命令进行数据写入和查询操作。
-- Websocket 连接
+```python title="Websocket 连接"
+{{#include docs/examples/python/create_db_ws.py}}
+```
+
+```python title="原生连接"
+{{#include docs/examples/python/create_db_native.py}}
+```
+
+```python title="Rest 连接"
+{{#include docs/examples/python/create_db_rest.py}}
+```
```go
@@ -47,6 +57,11 @@ REST API:通过 `curl` 命令进行数据写入和查询操作。
{{#include docs/examples/rust/nativeexample/examples/query.rs:create_db_and_table}}
```
+
+
+```js
+{{#include docs/examples/node/websocketexample/sql_example.js:create_db_and_table}}
+```
```csharp
@@ -98,6 +113,19 @@ NOW 为系统内部函数,默认为客户端所在计算机当前时间。 NOW
+
+```python title="Websocket 连接"
+{{#include docs/examples/python/insert_ws.py}}
+```
+
+```python title="原生连接"
+{{#include docs/examples/python/insert_native.py}}
+```
+
+```python title="Rest 连接"
+{{#include docs/examples/python/insert_rest.py}}
+```
+
```go
@@ -110,6 +138,11 @@ NOW 为系统内部函数,默认为客户端所在计算机当前时间。 NOW
{{#include docs/examples/rust/nativeexample/examples/query.rs:insert_data}}
```
+
+
+```js
+{{#include docs/examples/node/websocketexample/sql_example.js:insertData}}
+```
```csharp
@@ -154,6 +187,18 @@ curl --location -uroot:taosdata 'http://127.0.0.1:6041/rest/sql' \
+
+```python title="Websocket 连接"
+{{#include docs/examples/python/query_ws.py}}
+```
+
+```python title="原生连接"
+{{#include docs/examples/python/query_native.py}}
+```
+
+```python title="Rest 连接"
+{{#include docs/examples/python/query_rest.py}}
+```
```go
@@ -166,6 +211,11 @@ curl --location -uroot:taosdata 'http://127.0.0.1:6041/rest/sql' \
{{#include docs/examples/rust/nativeexample/examples/query.rs:query_data}}
```
+
+
+```js
+{{#include docs/examples/node/websocketexample/sql_example.js:queryData}}
+```
```csharp
@@ -227,6 +277,11 @@ reqId 可用于请求链路追踪,reqId 就像分布式系统中的 traceId
{{#include docs/examples/rust/nativeexample/examples/query.rs:query_with_req_id}}
```
+
+
+```js
+{{#include docs/examples/node/websocketexample/sql_example.js:sqlWithReqid}}
+```
```csharp
diff --git a/docs/zh/08-develop/04-schemaless.md b/docs/zh/08-develop/04-schemaless.md
index 71c9a5e1bd..611878960d 100644
--- a/docs/zh/08-develop/04-schemaless.md
+++ b/docs/zh/08-develop/04-schemaless.md
@@ -189,6 +189,11 @@ writer.write(lineDemo, SchemalessProtocolType.LINE, SchemalessTimestampType.NANO
{{#include docs/examples/rust/restexample/examples/schemaless.rs}}
```
+
+
+```js
+{{#include docs/examples/node/websocketexample/line_example.js}}
+```
```csharp
diff --git a/docs/zh/08-develop/05-stmt.md b/docs/zh/08-develop/05-stmt.md
index b8c3c60d47..d3e71eed63 100644
--- a/docs/zh/08-develop/05-stmt.md
+++ b/docs/zh/08-develop/05-stmt.md
@@ -52,9 +52,9 @@ import TabItem from "@theme/TabItem";
- ```js
- {{#include docs/examples/node/websocketexample/sql_example.js:createConnect}}
- ```
+```js
+ {{#include docs/examples/node/websocketexample/stmt_example.js:createConnect}}
+```
```csharp
diff --git a/docs/zh/08-develop/07-tmq.md b/docs/zh/08-develop/07-tmq.md
index 36ff09d0f4..2c033026ad 100644
--- a/docs/zh/08-develop/07-tmq.md
+++ b/docs/zh/08-develop/07-tmq.md
@@ -142,6 +142,9 @@ Rust 连接器创建消费者的参数为 DSN, 可以设置的参数列表请
+```js
+ {{#include docs/examples/node/websocketexample/tmq_example.js:create_consumer}}
+```