yurunsoft/tdengine-orm

Maintainers

👁 Yurunsoft

Package info

github.com/Yurunsoft/tdengine-orm

pkg:composer/yurunsoft/tdengine-orm

Statistics

Installs: 2 055

Dependents: 1

Suggesters: 0

Stars: 13

Open Issues: 1

v1.0.3 2022-01-13 08:39 UTC

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT d061fc26408986c97b9af759b6e1bac0cf8dd798

This package is auto-updated.

Last update: 2026-06-25 14:23:53 UTC


README

👁 Latest Version
👁 GitHub Workflow Status (branch)
👁 Php Version
👁 License

简介

基于 tdengine-restful-connectorphp-tdengine 开发的 TDEngine ORM。

支持创建超级表、创建表、批量插入数据。

此项目支持在 PHP >= 7.1 的项目中使用。

支持在 ThinkPHP、Laravel、Swooleimi 等项目中使用

在 Swoole 环境中支持协程化,不会阻塞!

技术支持 QQ 群: 17916227👁 点击加群
,如有问题可以及时解答和修复。

安装

composer require yurunsoft/tdengine-orm

使用

使用连接管理器:

// 增加名称为 test 的连接配置
\Yurun\TDEngine\TDEngineManager::setClientConfig('test', new \Yurun\TDEngine\ClientConfig([
 // 'host' => '127.0.0.1',
 // 'hostName' => '',
 // 'port' => 6041,
 // 'user' => 'root',
 // 'password' => 'taosdata',
 // 'ssl' => false,
 // 'timestampFormat' => \Yurun\TDEngine\Constants\TimeStampFormat::LOCAL_STRING,
 // 'keepAlive' => true,
]));
// 设置默认数据库为test
\Yurun\TDEngine\TDEngineManager::setDefaultClientName('test');
// 获取客户端对象(\Yurun\TDEngine\Client)
$client = \Yurun\TDEngine\TDEngineManager::getClient();
// 不设置连接驱动时,会判断安装扩展优先使用扩展
// 设置连接驱动为 RESTful
\Yurun\TDEngine\Orm\TDEngineOrm::setClientHandler(new \Yurun\TDEngine\Orm\ClientHandler\Restful\Handler());
// 设置连接驱动为 PHP 扩展
\Yurun\TDEngine\Orm\TDEngineOrm::setClientHandler(new \Yurun\TDEngine\Orm\ClientHandler\Extension\Handler());

定义模型:

<?php

declare(strict_types=1);

namespace Yurun\TDEngine\Orm\Test\Model;

use Yurun\TDEngine\Orm\Annotation\Field;
use Yurun\TDEngine\Orm\Annotation\Table;
use Yurun\TDEngine\Orm\Annotation\Tag;
use Yurun\TDEngine\Orm\BaseModel;
use Yurun\TDEngine\Orm\Enum\DataType;

/**
 * @Table(name="device_log", database="device")
 */
class DeviceLogModel extends BaseModel
{
 /**
 * @Field(type=DataType::TIMESTAMP)
 *
 * @var int
 */
 public $time;

 /**
 * @Tag(type=DataType::NCHAR, length=32, name="device_id")
 *
 * @var string
 */
 public $deviceId;

 /**
 * @Field(type=DataType::FLOAT)
 *
 * @var float
 */
 public $voltage;

 /**
 * @Field(type=DataType::FLOAT, name="electric_current")
 *
 * @var float
 */
 public $electricCurrent;
}

创建超级表:

DeviceLogModel::createSuperTable();

创建表:

$table = '表名';
$deviceId = '00000001'; // 这是 TAGS
DeviceLogModel::createTable($table, [$deviceId]);

插入数据:

$record = new DeviceLogModel([
 // 初始化模型数据
], '表名');
// $record->xxx = xxx; // 设置一些字段值
$record->insert();

批量插入数据:

$record1 = new DeviceLogModel([
 // 初始化模型数据
], '表名1');
$record2 = new DeviceLogModel([
 // 初始化模型数据
], '表名2');
DeviceLogModel::batchInsert([$record1, $record2]);