对于数据库操作的时候,我个人特别的倾向于用ORM这种对象映射模型, 可以让你最舒服的操作数据库,另外也可以最简单的实现数据库… 比如我写后端服务的时候,如果用mysqldb,那么想当的蛋疼… 来来回回的折腾的,在大量的参数下,很有可能会出各种各样的低级的问题… 如果你用python的peewee这种基于mysqldb的orm模型,那么会想当干练的操作mysql数据库。
在github上,看到一个帅哥老外分享的一个关于python influxdb orm的数据操作模型 , 代码虽然写的还很是精简干练 , 但是具体的功能也算是实现了。 其实这orm底层调用的也是python的influxdb接口,期初以为他的实现应该是语法树ast那种。 下面是他的项目,有兴趣的朋友也看下他的实现,还是有些灵巧的。
https://github.com/unaizalakain/qinfluxdb
qinfluxdb的安装配置 ~
pip install git+https://github.com/unaizalakain/qinfluxdb.git
下面是qinfluxdb的一个操作的例子
from qinfluxdb import Client
# The client is just a wrapper around InfluxDB's python client
client = Client(database='analytics', timeout=60)
query = client.q.from_series('temperature')
# Iterate over the results
for result in query:
print(result)
# List them all
query.all()
# Continue with the query and filter
query.where('value > 20').limit(20)
# Only select some of the values
query.values('time', 'mean(value)').group_by('time(1d)')
# Advanced filters
from qinfluxdb import Q
hot = Q('value > 30')
cold = Q('value < 0')
extreme = hot | cold
query.where(extreme)
大家觉得文章对你有些作用!
如果想赏钱,可以用微信扫描下面的二维码,感谢!
另外再次标注博客原地址 xiaorui.cc