modify python api
This commit is contained in:
parent
f82b92ed1b
commit
3ed7697218
|
@ -1,14 +1,21 @@
|
||||||
import taos
|
import taos
|
||||||
|
|
||||||
def test_connection():
|
def create_connection():
|
||||||
# all parameters are optional.
|
# all parameters are optional.
|
||||||
conn = taos.connect(host="localhost",
|
conn = None
|
||||||
port=6030,
|
try:
|
||||||
|
conn = taosws.connect(
|
||||||
user="root",
|
user="root",
|
||||||
password="taosdata")
|
password="taosdata",
|
||||||
print('client info:', conn.client_info)
|
host="192.168.1.98",
|
||||||
print('server info:', conn.server_info)
|
port=6041,
|
||||||
|
)
|
||||||
|
except Exception as err:
|
||||||
|
print(f'Exception {err}')
|
||||||
|
finally:
|
||||||
|
if conn:
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_connection()
|
create_connection()
|
||||||
|
|
|
@ -1,20 +1,47 @@
|
||||||
# ANCHOR: connect
|
|
||||||
import taosws
|
import taosws
|
||||||
|
|
||||||
conn = taosws.connect("taosws://root:taosdata@localhost:6041")
|
def create_connection():
|
||||||
|
conn = None
|
||||||
|
# ANCHOR: connect
|
||||||
|
try:
|
||||||
|
conn = taosws.connect(
|
||||||
|
user="root",
|
||||||
|
password="taosdata",
|
||||||
|
host="localhost",
|
||||||
|
port=6041,
|
||||||
|
)
|
||||||
|
except Exception as err:
|
||||||
|
print(f'Exception {err}')
|
||||||
# ANCHOR_END: connect
|
# ANCHOR_END: connect
|
||||||
|
return conn
|
||||||
|
|
||||||
# ANCHOR: basic
|
def create_db_table(conn):
|
||||||
conn.execute("drop database if exists connwspy")
|
# ANCHOR: create_db
|
||||||
conn.execute("create database if not exists connwspy wal_retention_period 3600 keep 36500 ")
|
try:
|
||||||
conn.execute("use connwspy")
|
conn.execute("CREATE DATABASE IF NOT EXISTS power")
|
||||||
conn.execute("create table if not exists stb (ts timestamp, c1 int) tags (t1 int)")
|
conn.execute("USE power")
|
||||||
conn.execute("create table if not exists tb1 using stb tags (1)")
|
conn.execute("CREATE STABLE IF NOT EXISTS meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (groupId INT, location BINARY(24))")
|
||||||
conn.execute("insert into tb1 values (now, 1)")
|
conn.execute("CREATE TABLE `d0` USING `meters` TAGS(0, 'Los Angles')")
|
||||||
conn.execute("insert into tb1 values (now+1s, 2)")
|
except Exception as err:
|
||||||
conn.execute("insert into tb1 values (now+2s, 3)")
|
print(f'Exception {err}')
|
||||||
|
# ANCHOR_END: create_db
|
||||||
|
|
||||||
r = conn.execute("select * from stb")
|
def insert(conn):
|
||||||
|
sql = """
|
||||||
|
INSERT INTO
|
||||||
|
power.d1001 USING power.meters TAGS('California.SanFrancisco', 2)
|
||||||
|
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 TAGS('California.SanFrancisco', 3)
|
||||||
|
VALUES (NOW + 1a, 10.30000, 218, 0.25000)
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
inserted = conn.execute(sql)
|
||||||
|
assert inserted == 8
|
||||||
|
except Exception as err:
|
||||||
|
print(f'Exception {err}')
|
||||||
|
|
||||||
|
def query(conn):
|
||||||
result = conn.query("select * from stb")
|
result = conn.query("select * from stb")
|
||||||
num_of_fields = result.field_count
|
num_of_fields = result.field_count
|
||||||
print(num_of_fields)
|
print(num_of_fields)
|
||||||
|
|
|
@ -25,6 +25,8 @@ TDengine 对 SQL 语言提供了全面的支持,允许用户以熟悉的 SQL
|
||||||
|
|
||||||
</TabItem>
|
</TabItem>
|
||||||
<TabItem label="Python" value="python">
|
<TabItem label="Python" value="python">
|
||||||
|
- Websocket 连接
|
||||||
|
|
||||||
</TabItem>
|
</TabItem>
|
||||||
<TabItem label="Go" value="go">
|
<TabItem label="Go" value="go">
|
||||||
</TabItem>
|
</TabItem>
|
||||||
|
|
Loading…
Reference in New Issue