influxdb-orm 时序数据库 InfluxDB 的 ORM开源项目

我要开发同款
匿名用户2019年12月13日
37阅读
开发技术PHP
所属分类程序开发、ORM/持久层框架
授权协议MIT

作品详情

influxdb-orm是一个用于InfluxDB时序数据库的ORM,终结没有InfluxDBORM的时代。

常用操作一把梭,支持php-fpm、Swoole环境,一键轻松切换。

可以用于所有传统框架、所有Swoole框架中!

Composer

本项目可以使用composer安装,遵循psr-4自动加载规则,在你的 composer.json 中加入下面的内容:

{"require":{"yurunsoft/influxdb-orm":"^1.0.0"}}

然后执行 composerupdate 安装。

使用Swoole支持

在 WorkerStart 事件中执行:

\Yurun\Util\YurunHttp::setDefaultHandler(\Yurun\Util\YurunHttp\Handler\Swoole::class);定义模型

具体可参考 example/test.php

<?phpnamespaceYurun\InfluxDB\ORM\Example\Model;useYurun\InfluxDB\ORM\BaseModel;useYurun\InfluxDB\ORM\Annotation\Tag;useYurun\InfluxDB\ORM\Annotation\Field;useYurun\InfluxDB\ORM\Annotation\Value;useYurun\InfluxDB\ORM\Annotation\Timestamp;useYurun\InfluxDB\ORM\Annotation\Measurement;/***@Measurement(name="aaa")*/classAextendsBaseModel{/***@Tag(name="id",type="int")**@varint*/private$id;/***@Field(name="name",type="string")**@varstring*/private$name;/***@Timestamp(precision="s")**@varint|string*/private$time;/***@Value**@varint*/private$value;publicstaticfunctioncreate($id,$name,$time,$value){returnnewstatic(compact('id','name','time','value'));}/***Getthevalueoftime**@returnint|string*/publicfunctiongetTime(){return$this->time;}/***Setthevalueoftime**@paramint|string$time**@returnself*/publicfunctionsetTime($time){$this->time=$time;return$this;}/***Getthevalueofid**@returnint*/publicfunctiongetId(){return$this->id;}/***Setthevalueofid**@paramint$id**@returnself*/publicfunctionsetId(int$id){$this->id=$id;return$this;}/***Getthevalueofname**@returnstring*/publicfunctiongetName(){return$this->name;}/***Setthevalueofname**@paramstring$name**@returnself*/publicfunctionsetName(string$name){$this->name=$name;return$this;}/***Getthevalueofvalue**@returnint*/publicfunctiongetValue(){return$this->value;}/***Setthevalueofvalue**@paramint$value**@returnself*/publicfunctionsetValue(int$value){$this->value=$value;return$this;}}数据写入useYurun\InfluxDB\ORM\InfluxDBManager;//设置客户端名称为test,默认数据库为db_testInfluxDBManager::setClientConfig('test','127.0.0.1',8086,'','',false,false,0,0,'db_test');//设置默认数据库为testInfluxDBManager::setDefaultClientName('test');//写入数据,支持对象和数组$r=A::write([A::create(mt_rand(1,999999),time(),time(),mt_rand(1,100)),['id'=>1,'name'=>'aaa','time'=>time(),'value'=>mt_rand(1,100)],]);var_dump($r);数据查询//获取查询器$query=A::query();//常见用法,反正就那一套,不多说了$query->field('id,name')->from('table')->where(['id'=>1])->where('id','=',1)->orWhere('id','=',1)->order('time','desc')->group('id')->limit(0,10);//查询结果,与InfluxDB官方客户端一样用法$resultSet=$query->select();//查询结果转模型,适合用于查询记录而不是统计数据$model=$resultSet->getModel(A::class);//查询结果转模型列表,适合用于查询记录而不是统计数据$list=$resultSet->getModelList(A::class);模型快捷查询

适合用于查询记录而不是统计数据

useYurun\InfluxDB\ORM\Query\QueryBuilder;//查询结果转模型,适合用于查询记录而不是统计数据$model=A::find(function(QueryBuilder$query){$query->where('id','=',1)->limit(1);});//查询结果转模型列表,适合用于查询记录而不是统计数据$list=A::select(function(QueryBuilder$query){$query->where('id','=',1)->limit(2);});获取单个字段值$count=A::query()->field('count(value)')->select()->getScalar();
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论