Code Monkey home page Code Monkey logo

tdengine-orm's Introduction

tdengine-orm

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]);

tdengine-orm's People

Contributors

yurunsoft avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

tdengine-orm's Issues

[Semantical Error] Annotation @Table is not allowed to be declared

[WARNING] Doctrine\Common\Annotations\AnnotationException: [Semantical Error] Annotation @table is not allowed to be declared on class App\Model\TD\AlertLog. You may only use this annotation on these code elements: CLASS.(0) in /home/www/hyperf-skeleton/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php:40

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.