提交 0b09143f 编写于 作者: D dingbo

add python examples

上级 c39ae688
```py
{{#include docs-examples/python/native_insert_example.py}}
```
```py
{{#include docs-examples/python/bind_param_example.py}}
```
\ No newline at end of file
```py
{{#include docs-examples/python/query_example.py}}
```
```py
{{#include docs-examples/python/async_query_example.py}}
```
import taos
\ No newline at end of file
import taos
\ No newline at end of file
......@@ -9,16 +9,18 @@ lines = [[{"metric": "meters.current", "timestamp": 1648432611249, "value": 10.3
{"metric": "meters.voltage", "timestamp": 1648432611250, "value": 221, "tags": {"location": "Beijing.Haidian", "groupid": 1}}]
]
# create connection use firstEP in taos.cfg.
conn = taos.connect()
def get_connection():
# create connection use firstEp in taos.cfg.
return taos.connect()
def create_database():
def create_database(conn):
conn.execute("create database test")
conn.execute("use test")
def insert_lines():
def insert_lines(conn):
global lines
lines = [json.dumps(line) for line in lines]
print(lines)
......@@ -27,5 +29,7 @@ def insert_lines():
if __name__ == '__main__':
create_database()
insert_lines()
connection = get_connection()
create_database(connection)
insert_lines(connection)
connection.close()
......@@ -11,21 +11,25 @@ lines = ["meters,location=Beijing.Chaoyang,groupid=2 current=10.3,voltage=219,ph
"meters,location=Beijing.Haidian,groupid=3 current=11.3,voltage=221,phase=0.35 1648432611249800",
]
# create connection use firstEP in taos.cfg.
conn = taos.connect()
def get_connection():
# create connection use firstEP in taos.cfg.
return taos.connect()
def create_database():
def create_database(conn):
# the default precision is ms (microsecond), but we use us(microsecond) here.
conn.execute("create database test precision 'us'")
conn.execute("use test")
def insert_lines():
def insert_lines(conn):
affected_rows = conn.schemaless_insert(lines, SmlProtocol.LINE_PROTOCOL, SmlPrecision.MICRO_SECONDS)
print(affected_rows) # 8
if __name__ == '__main__':
create_database()
insert_lines()
connection = get_connection()
create_database(connection)
insert_lines(connection)
connection.close()
import taos
\ No newline at end of file
import taos
conn = taos.connect()
def print_all():
result = conn.query()
......@@ -12,20 +12,24 @@ lines = ["meters.current 1648432611249 10.3 location=Beijing.Chaoyang groupid=2"
"meters.voltage 1648432611250 217 location=Beijing.Haidian groupid=3",
]
# create connection use firstEP in taos.cfg.
conn = taos.connect()
# create connection use firstEp in taos.cfg.
def get_connection():
return taos.connect()
def create_database():
def create_database(conn):
conn.execute("create database test")
conn.execute("use test")
def insert_lines():
def insert_lines(conn):
affected_rows = conn.schemaless_insert(lines, SmlProtocol.TELNET_PROTOCOL, SmlPrecision.NOT_CONFIGURED)
print(affected_rows) # 8
if __name__ == '__main__':
create_database()
insert_lines()
connection = get_connection()
create_database(connection)
insert_lines(connection)
connection.close()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册