封装了一个通过python访问TimeScaleDB的类,代码如下:
# 导入依赖包
# !/usr/bin/python3
import time
import datetime
import psycopg2
class TimeScaleDBVisiter():
def __init__(self):
self.beginTime = datetime.datetime.now()
#microsecond = self.beginTime + datetime.timedelta(microseconds=1000100)
#-- Do not forget to create timescaledb extension
#CREATE EXTENSION timescaledb;
# 创建表
# cur.execute("CREATE TABLE student(id integer,name varchar,sex varchar);")
strCreateTable = "CREATE TABLE conditions ( \
time TIMESTAMPTZ NOT NULL, \
location TEXT NOT NULL, \
temperature DOUBLE PRECISION NULL, \
humidity DOUBLE PRECISION NULL \
);"
strCreateTable = "CREATE TABLE AllPulses ( \
id integer NOT NULL, \
rd integer NOT NULL, \
paw integer NOT NULL, \
soa TIMESTAMPTZ NOT NULL, \
inp integer NOT NULL, \