influxdb-orm v1.1.0 发布,时序数据库 InfluxDB 的 ORM
介绍
一个用于 InfluxDB 时序数据库的 ORM,终结没有 InfluxDB ORM 的时代。
常用操作一把梭,支持 php-fpm、Swoole 环境,一键轻松切换。
可以用于所有传统框架、所有 Swoole 框架中!
码云:https://gitee.com/yurunsoft/influxdb-orm
Github:https://github.com/Yurunsoft/influxdb-orm
更新日志
-
新增测试用例
-
新增 travis 自动化测试
-
完善注释和参数返回值类型
-
修复 ResultSet->getScalar() 默认值错误
-
查询构建器查询后时区复原
-
新增模型测试和查询器测试
-
修复 or 条件问题
-
QueryBuilder 支持设定 timezone()
-
新增支持日期时间格式化
-
模型新增 toArray() 方法
-
为
@Value
注解增加字段类型属性
Composer
本项目可以使用composer安装,遵循psr-4自动加载规则,在你的 composer.json
中加入下面的内容:
{ "require": { "yurunsoft/influxdb-orm": "^1.1.0" } }
然后执行 composer update
安装。
使用
Swoole 支持
在 WorkerStart
事件中执行:
\Yurun\Util\YurunHttp::setDefaultHandler(\Yurun\Util\YurunHttp\Handler\Swoole::class);
定义模型
具体可参考
example/test.php
<?php namespace Yurun\InfluxDB\ORM\Example\Model; use Yurun\InfluxDB\ORM\BaseModel; use Yurun\InfluxDB\ORM\Annotation\Tag; use Yurun\InfluxDB\ORM\Annotation\Field; use Yurun\InfluxDB\ORM\Annotation\Value; use Yurun\InfluxDB\ORM\Annotation\Timestamp; use Yurun\InfluxDB\ORM\Annotation\Measurement; /** * @Measurement(name="aaa") */ class A extends BaseModel { /** * @Tag(name="id", type="int") * * @var int */ private $id; /** * @Field(name="name", type="string") * * @var string */ private $name; /** * @Timestamp(precision="s") * * @var int|string */ private $time; /** * @Value * * @var int */ private $value; public static function create($id, $name, $time, $value) { return new static(compact('id', 'name', 'time', 'value')); } /** * Get the value of time * * @return int|string */ public function getTime() { return $this->time; } /** * Set the value of time * * @param int|string $time * * @return self */ public function setTime($time) { $this->time = $time; return $this; } /** * Get the value of id * * @return int */ public function getId() { return $this->id; } /** * Set the value of id * * @param int $id * * @return self */ public function setId(int $id) { $this->id = $id; return $this; } /** * Get the value of name * * @return string */ public function getName() { return $this->name; } /** * Set the value of name * * @param string $name * * @return self */ public function setName(string $name) { $this->name = $name; return $this; } /** * Get the value of value * * @return int */ public function getValue() { return $this->value; } /** * Set the value of value * * @param int $value * * @return self */ public function setValue(int $value) { $this->value = $value; return $this; } }
数据写入
use Yurun\InfluxDB\ORM\InfluxDBManager; // 设置客户端名称为test,默认数据库为db_test InfluxDBManager::setClientConfig('test', '127.0.0.1', 8086, '', '', false, false, 0, 0, 'db_test'); // 设置默认数据库为test InfluxDBManager::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);
模型快捷查询
适合用于查询记录而不是统计数据
use Yurun\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();
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
java并发编程入门
1、入门介绍 1.1、实现线程的2种方式 package chapter2; /** * @author calebzhao<9 3 9 3 4 7 5 0 7 @ qq.com> * 2019/6/29 14:05 */ public class MyThreadDemo1 { public static void main(String[] args) { new Thread1().start(); new Thread(new Thread2()).start(); } } class Thread1 extends Thread{ @Override public void run() { System.out.println(Thread.currentThread().getName()); } } class Thread2 implements Runnable{ @Override public void run() { System.out.println(Thread.currentThread().getName()); } } 1...
- 下一篇
MaxCompute中Struct复杂数据类型的UDF编写、兼容HIVE的GenericUDF编写
一、背景介绍:MaxCompute 2.0版本升级后,Java UDF支持的数据类型从原来的BIGINT、STRING、DOUBLE、BOOLEAN扩展了更多基本的数据类型,同时还扩展支持了ARRAY、MAP、STRUCT等复杂类型,以及Writable参数。Java UDF使用复杂数据类型的方法,STRUCT对应com.aliyun.odps.data.Struct。com.aliyun.odps.data.Struct从反射看不出Field Name和Field Type,所以需要用@Resolve注解来辅助。即如果需要在UDF中使用STRUCT,要求在UDF Class上也标注上@Resolve注解。但是当我们Struct类型中的field有很多字段的时候,这个时候需要我们去手动的添加@Resolve注解就不是那么的友好。针
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
-
Docker使用Oracle官方镜像安装(12C,18C,19C)
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- CentOS8编译安装MySQL8.0.19
- Docker快速安装Oracle11G,搭建oracle11g学习环境
- SpringBoot2配置默认Tomcat设置,开启更多高级功能
- MySQL8.0.19开启GTID主从同步CentOS8
- CentOS7,8上快速安装Gitea,搭建Git服务器
- Jdk安装(Linux,MacOS,Windows),包含三大操作系统的最全安装
- SpringBoot2编写第一个Controller,响应你的http请求并返回结果
推荐阅读
最新文章
- CentOS6,7,8上安装Nginx,支持https2.0的开启
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- Docker使用Oracle官方镜像安装(12C,18C,19C)
- CentOS6,CentOS7官方镜像安装Oracle11G
- SpringBoot2整合Redis,开启缓存,提高访问速度
- Jdk安装(Linux,MacOS,Windows),包含三大操作系统的最全安装
- SpringBoot2配置默认Tomcat设置,开启更多高级功能
- SpringBoot2整合MyBatis,连接MySql数据库做增删改查操作
- Hadoop3单机部署,实现最简伪集群
- MySQL8.0.19开启GTID主从同步CentOS8