同步操作将从 taosdata/TDengine 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
local driver = require "luaconnector"local config = {host = "127.0.0.1",port = 6030,database = "",user = "root",password = "taosdata",max_packet_size = 1024 * 1024}local connlocal res = driver.connect(config)if res.code ~=0 thenprint("connect--- failed: "..res.error)returnelseconn = res.connprint("connect--- pass.")endlocal res = driver.query(conn,"drop database if exists demo")res = driver.query(conn,"create database demo")if res.code ~=0 thenprint("create db--- failed: "..res.error)returnelseprint("create db--- pass.")endres = driver.query(conn,"use demo")if res.code ~=0 thenprint("select db--- failed: "..res.error)returnelseprint("select db--- pass.")endres = driver.query(conn,"create table m1 (ts timestamp, speed int, owner binary(20), mark nchar(30))")if res.code ~=0 thenprint("create table---failed: "..res.error)returnelseprint("create table--- pass.")endres = driver.query(conn,"insert into m1 values ('2019-09-01 00:00:00.001', 0, 'robotspace', '世界人民大团结万岁'), ('2019-09-01 00:00:00.002', 1, 'Hilink', '鬥鬯鬲鬼魚鳥鹵鹿麥麻黃黍黑黹黽鼎鼓鼠鼻齊齒龍龜龠'),('2019-09-01 00:00:00.003', 2, 'Harmony', '₠₡₢₣₤₥₦₧Rs₩₪₫€₭₮₯₰₱₲₳₴₵')")if res.code ~=0 thenprint("insert records failed: "..res.error)returnelseif(res.affected == 3) thenprint("insert records--- pass")elseprint("insert records---failed: expect 3 affected records, actually affected "..res.affected)endendres = driver.query(conn,"select * from m1")if res.code ~=0 thenprint("select failed: "..res.error)returnelseif (#(res.item) == 3) thenprint("select--- pass")print(res.item[1].mark)print(res.item[2].mark)print(res.item[3].mark)elseprint("select--- failed: expect 3 affected records, actually received "..#(res.item))endendres = driver.query(conn,"CREATE TABLE thermometer (ts timestamp, degree double) TAGS(location binary(20), type int)")if res.code ~=0 thenprint(res.error)returnelseprint("create super table--- pass")endres = driver.query(conn,"CREATE TABLE therm1 USING thermometer TAGS ('beijing', 1)")if res.code ~=0 thenprint(res.error)returnelseprint("create table--- pass")endres = driver.query(conn,"INSERT INTO therm1 VALUES ('2019-09-01 00:00:00.001', 20),('2019-09-01 00:00:00.002', 21)")if res.code ~=0 thenprint(res.error)returnelseif(res.affected == 2) thenprint("insert records--- pass")elseprint("insert records---failed: expect 2 affected records, actually affected "..res.affected)endendres = driver.query(conn,"SELECT COUNT(*) count, AVG(degree) AS av, MAX(degree), MIN(degree) FROM thermometer WHERE location='beijing' or location='tianjin' GROUP BY location, type")if res.code ~=0 thenprint("select from super table--- failed:"..res.error)returnelseprint("select from super table--- pass")for i = 1, #(res.item) doprint("res:"..res.item[i].count)endendfunction async_query_callback(res)if res.code ~=0 thenprint("async_query_callback--- failed:"..res.error)returnelseif(res.affected == 3) thenprint("async_query_callback, insert records--- pass")elseprint("async_query_callback, insert records---failed: expect 3 affected records, actually affected "..res.affected)endendenddriver.query_a(conn,"INSERT INTO therm1 VALUES ('2019-09-01 00:00:00.005', 100),('2019-09-01 00:00:00.006', 101),('2019-09-01 00:00:00.007', 102)", async_query_callback)function stream_callback(t)print("------------------------")print("continuous query result:")for key, value in pairs(t) doprint("key:"..key..", value:"..value)endendlocal streamres = driver.open_stream(conn,"SELECT COUNT(*) as count, AVG(degree) as avg, MAX(degree) as max, MIN(degree) as min FROM thermometer interval(2s) sliding(2s);)",0, stream_callback)if res.code ~=0 thenprint("open stream--- failed:"..res.error)returnelseprint("open stream--- pass")stream = res.streamendprint("From now on we start continous insert in an definite (infinite if you want) loop.")local loop_index = 0while loop_index < 30 dolocal t = os.time()*1000local v = loop_indexres = driver.query(conn,string.format("INSERT INTO therm1 VALUES (%d, %d)",t,v))if res.code ~=0 thenprint("continous insertion--- failed:" .. res.error)returnelse--print("insert successfully, affected:"..res.affected)endos.execute("sleep " .. 1)loop_index = loop_index + 1enddriver.close_stream(stream)driver.close(conn)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。