{"id":13529491,"url":"https://github.com/Yurunsoft/tdengine-orm","last_synced_at":"2025-04-01T16:31:30.417Z","repository":{"id":43045181,"uuid":"436450907","full_name":"Yurunsoft/tdengine-orm","owner":"Yurunsoft","description":"基于 tdengine-restful-connector、php-tdengine 开发的 TDEngine ORM。","archived":false,"fork":false,"pushed_at":"2022-11-25T06:50:31.000Z","size":40,"stargazers_count":11,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-24T21:03:22.857Z","etag":null,"topics":["php","tdengine"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Yurunsoft.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-09T01:57:38.000Z","updated_at":"2024-03-08T01:46:03.000Z","dependencies_parsed_at":"2023-01-21T16:45:56.331Z","dependency_job_id":null,"html_url":"https://github.com/Yurunsoft/tdengine-orm","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yurunsoft%2Ftdengine-orm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yurunsoft%2Ftdengine-orm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yurunsoft%2Ftdengine-orm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yurunsoft%2Ftdengine-orm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Yurunsoft","download_url":"https://codeload.github.com/Yurunsoft/tdengine-orm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246670544,"owners_count":20815003,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["php","tdengine"],"created_at":"2024-08-01T07:00:36.810Z","updated_at":"2025-04-01T16:31:30.057Z","avatar_url":"https://github.com/Yurunsoft.png","language":"PHP","funding_links":[],"categories":["ORM"],"sub_categories":[],"readme":"# tdengine-orm\n\n[![Latest Version](https://poser.pugx.org/yurunsoft/tdengine-orm/v/stable)](https://packagist.org/packages/yurunsoft/tdengine-orm)\n![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/Yurunsoft/tdengine-orm/ci/master)\n[![Php Version](https://img.shields.io/badge/php-%3E=7.1-brightgreen.svg)](https://secure.php.net/)\n[![License](https://img.shields.io/github/license/Yurunsoft/tdengine-orm.svg)](https://github.com/Yurunsoft/tdengine-orm/blob/master/LICENSE)\n\n## 简介\n\n基于 [tdengine-restful-connector](https://github.com/Yurunsoft/tdengine-restful-connector)、[php-tdengine](https://github.com/Yurunsoft/php-tdengine) 开发的 TDEngine ORM。\n\n支持创建超级表、创建表、批量插入数据。\n\n此项目支持在 PHP \u003e= 7.1 的项目中使用。\n\n支持在 ThinkPHP、Laravel、[Swoole](https://github.com/swoole/swoole-src)、[imi](https://github.com/imiphp/imi) 等项目中使用\n\n在 Swoole 环境中支持协程化，不会阻塞！\n\n技术支持 QQ 群: 17916227[![点击加群](https://pub.idqqimg.com/wpa/images/group.png \"点击加群\")](https://jq.qq.com/?_wv=1027\u0026k=5wXf4Zq)，如有问题可以及时解答和修复。\n\n## 安装\n\n`composer require yurunsoft/tdengine-orm`\n\n## 使用\n\n**使用连接管理器：**\n\n```php\n// 增加名称为 test 的连接配置\n\\Yurun\\TDEngine\\TDEngineManager::setClientConfig('test', new \\Yurun\\TDEngine\\ClientConfig([\n    // 'host'            =\u003e '127.0.0.1',\n    // 'hostName'        =\u003e '',\n    // 'port'            =\u003e 6041,\n    // 'user'            =\u003e 'root',\n    // 'password'        =\u003e 'taosdata',\n    // 'ssl'             =\u003e false,\n    // 'timestampFormat' =\u003e \\Yurun\\TDEngine\\Constants\\TimeStampFormat::LOCAL_STRING,\n    // 'keepAlive'       =\u003e true,\n]));\n// 设置默认数据库为test\n\\Yurun\\TDEngine\\TDEngineManager::setDefaultClientName('test');\n// 获取客户端对象（\\Yurun\\TDEngine\\Client）\n$client = \\Yurun\\TDEngine\\TDEngineManager::getClient();\n// 不设置连接驱动时，会判断安装扩展优先使用扩展\n// 设置连接驱动为 RESTful\n\\Yurun\\TDEngine\\Orm\\TDEngineOrm::setClientHandler(new \\Yurun\\TDEngine\\Orm\\ClientHandler\\Restful\\Handler());\n// 设置连接驱动为 PHP 扩展\n\\Yurun\\TDEngine\\Orm\\TDEngineOrm::setClientHandler(new \\Yurun\\TDEngine\\Orm\\ClientHandler\\Extension\\Handler());\n```\n\n**定义模型：**\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nnamespace Yurun\\TDEngine\\Orm\\Test\\Model;\n\nuse Yurun\\TDEngine\\Orm\\Annotation\\Field;\nuse Yurun\\TDEngine\\Orm\\Annotation\\Table;\nuse Yurun\\TDEngine\\Orm\\Annotation\\Tag;\nuse Yurun\\TDEngine\\Orm\\BaseModel;\nuse Yurun\\TDEngine\\Orm\\Enum\\DataType;\n\n/**\n * @Table(name=\"device_log\", database=\"device\")\n */\nclass DeviceLogModel extends BaseModel\n{\n    /**\n     * @Field(type=DataType::TIMESTAMP)\n     *\n     * @var int\n     */\n    public $time;\n\n    /**\n     * @Tag(type=DataType::NCHAR, length=32, name=\"device_id\")\n     *\n     * @var string\n     */\n    public $deviceId;\n\n    /**\n     * @Field(type=DataType::FLOAT)\n     *\n     * @var float\n     */\n    public $voltage;\n\n    /**\n     * @Field(type=DataType::FLOAT, name=\"electric_current\")\n     *\n     * @var float\n     */\n    public $electricCurrent;\n}\n```\n\n**创建超级表：**\n\n```php\nDeviceLogModel::createSuperTable();\n```\n\n**创建表：**\n\n```php\n$table = '表名';\n$deviceId = '00000001'; // 这是 TAGS\nDeviceLogModel::createTable($table, [$deviceId]);\n```\n\n**插入数据：**\n\n```php\n$record = new DeviceLogModel([\n    // 初始化模型数据\n], '表名');\n// $record-\u003exxx = xxx; // 设置一些字段值\n$record-\u003einsert();\n```\n\n**批量插入数据：**\n\n```php\n$record1 = new DeviceLogModel([\n    // 初始化模型数据\n], '表名1');\n$record2 = new DeviceLogModel([\n    // 初始化模型数据\n], '表名2');\nDeviceLogModel::batchInsert([$record1, $record2]);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FYurunsoft%2Ftdengine-orm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FYurunsoft%2Ftdengine-orm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FYurunsoft%2Ftdengine-orm/lists"}