influxdb-orm v1.0.1 发布,时序数据库 InfluxDB 的 PHP ORM
介绍
一个用于 InfluxDB 时序数据库的 ORM,终结没有 InfluxDB ORM 的时代。
常用操作一把梭,支持 php-fpm、Swoole 环境,一键轻松切换。
可以用于所有传统框架、所有 Swoole 框架中!
码云:https://gitee.com/yurunsoft/influxdb-orm
Github:https://github.com/Yurunsoft/influxdb-orm
Composer
本项目可以使用composer安装,遵循psr-4自动加载规则,在你的 composer.json
中加入下面的内容:
{ "require": { "yurunsoft/influxdb-orm": "^1.0.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业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
-
上一篇
Python Weekly 419
文章,教程或讲座 如何用 Dropbox Security 构建用于日志系统的威胁检测和事件响应的工具 https://blogs.dropbox.com/tech/2019/10/how-dropbox-security-builds-better-tools-for-threat-detection-and-incident-response/ 传统上,构建威胁检测和响应工具的最常见方法是将自动化部分和调查部分分离。根据我们的经验,这可能会导致很多崩溃。在 Dropbox,我们已经为我们的日志系统构建了一个通用的基础抽象模型,该模型可在事件响应周期的各个阶段进行 Alertbox,Covenant 和 Forerunner 检测。集成利用强大的开源工具使我们能够快速浏览数据并自动执行警报,因此我们可以专注于更复杂的威胁。 Python 3.8 https://docs.python.org/3.8/whatsnew/3.8.html 本文介绍了与 3.7 相比,Python3.8 的新增功能。 完整的 Python 库导入指南:绝对导入,相对导入和其他方法 https://www....
-
下一篇
Jboot 2.3.1 发布,增加开发模式下对 SQL 的输出功能
Jboot 是一个基于 JFinal、JFinal-Undertow、Dubbo 等开发的微服务框架,帮助开发者降低微服务开发门槛。同时完美支持在 idea、eclipse 下多 maven 模块,对 java 代码、html、css、js 等资源文件进行热加载。爽爽开发,快乐生活。 这个版本主要是增加了在开发模式下,当我们对数据库进行操作时,输出完整的 sql ,其实对 sql 的输出,JFinal 本身已经支持,但是不显示参数,这个主要是增强了参数的完整显示的功能。 Jboot v2.3.1更新内容如下: 新增:新增 SqlDebugger,方便执行 SQL 时对完整 SQL 的输出 优化:升级 JFinal 和 JFinal-Undertow 到最新版本 优化:改进 Log 以支持 JFinal 最新的日志接口 优化:删除 JbootModel 的 auto_copy 特性,以提高性能 优化:修改 Sharding-JDBC 为 provided ,只有在需要的时候增加即可 优化:优化 pom.xml ,定义 DependencyManagement 以减少 Maven 传递依赖...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- CentOS7编译安装Cmake3.16.3,解决mysql等软件编译问题
- SpringBoot2整合MyBatis,连接MySql数据库做增删改查操作
- MySQL数据库在高并发下的优化方案
- Dcoker安装(在线仓库),最新的服务器搭配容器使用
- CentOS8编译安装MySQL8.0.19
- MySQL8.0.19开启GTID主从同步CentOS8
- CentOS8安装MyCat,轻松搞定数据库的读写分离、垂直分库、水平分库
- CentOS7,8上快速安装Gitea,搭建Git服务器
- SpringBoot2全家桶,快速入门学习开发网站教程
- Docker快速安装Oracle11G,搭建oracle11g学习环境