-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 48c780b
Showing
23 changed files
with
1,206 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
root = true | ||
|
||
[*.php] | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 4 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.md] | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 4 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
* text=auto eol=lf | ||
|
||
/.gitattributes export-ignore | ||
/.gitignore export-ignore | ||
/.github export-ignore | ||
/tests export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
vendor | ||
composer.lock | ||
.runtime | ||
*.log | ||
/.idea | ||
*.cache | ||
*.lock | ||
/.vscode | ||
*.pid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
if (!file_exists(__DIR__ . '/src')) | ||
{ | ||
exit(0); | ||
} | ||
|
||
return (new PhpCsFixer\Config()) | ||
->setRules([ | ||
'@Symfony' => true, | ||
'@Symfony:risky' => true, | ||
'php_unit_dedicate_assert' => ['target' => '5.6'], | ||
'array_syntax' => ['syntax' => 'short'], | ||
'array_indentation' => true, | ||
'binary_operator_spaces' => [ | ||
'operators' => [ | ||
'=>' => 'align_single_space', | ||
], | ||
], | ||
'concat_space' => [ | ||
'spacing' => 'one', | ||
], | ||
'fopen_flags' => false, | ||
'protected_to_private' => false, | ||
'native_constant_invocation' => true, | ||
'combine_nested_dirname' => true, | ||
'single_quote' => true, | ||
'braces' => [ | ||
'position_after_control_structures' => 'next', | ||
], | ||
'single_line_comment_style' => false, | ||
'phpdoc_to_comment' => false, | ||
'declare_strict_types' => true, | ||
]) | ||
->setRiskyAllowed(true) | ||
->setFinder( | ||
PhpCsFixer\Finder::create() | ||
->exclude(__DIR__ . '/vendor') | ||
->in(__DIR__ . '/src') | ||
->in(__DIR__ . '/tests') | ||
->append([__FILE__]) | ||
) | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
木兰宽松许可证, 第2版 | ||
|
||
2020年1月 http://license.coscl.org.cn/MulanPSL2 | ||
|
||
您对“软件”的复制、使用、修改及分发受木兰宽松许可证,第2版(“本许可证”)的如下条款的约束: | ||
|
||
0. 定义 | ||
|
||
“软件” 是指由“贡献”构成的许可在“本许可证”下的程序和相关文档的集合。 | ||
|
||
“贡献” 是指由任一“贡献者”许可在“本许可证”下的受版权法保护的作品。 | ||
|
||
“贡献者” 是指将受版权法保护的作品许可在“本许可证”下的自然人或“法人实体”。 | ||
|
||
“法人实体” 是指提交贡献的机构及其“关联实体”。 | ||
|
||
“关联实体” 是指,对“本许可证”下的行为方而言,控制、受控制或与其共同受控制的机构,此处的控制是指有受控方或共同受控方至少50%直接或间接的投票权、资金或其他有价证券。 | ||
|
||
1. 授予版权许可 | ||
|
||
每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的版权许可,您可以复制、使用、修改、分发其“贡献”,不论修改与否。 | ||
|
||
2. 授予专利许可 | ||
|
||
每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的(根据本条规定撤销除外)专利许可,供您制造、委托制造、使用、许诺销售、销售、进口其“贡献”或以其他方式转移其“贡献”。前述专利许可仅限于“贡献者”现在或将来拥有或控制的其“贡献”本身或其“贡献”与许可“贡献”时的“软件”结合而将必然会侵犯的专利权利要求,不包括对“贡献”的修改或包含“贡献”的其他结合。如果您或您的“关联实体”直接或间接地,就“软件”或其中的“贡献”对任何人发起专利侵权诉讼(包括反诉或交叉诉讼)或其他专利维权行动,指控其侵犯专利权,则“本许可证”授予您对“软件”的专利许可自您提起诉讼或发起维权行动之日终止。 | ||
|
||
3. 无商标许可 | ||
|
||
“本许可证”不提供对“贡献者”的商品名称、商标、服务标志或产品名称的商标许可,但您为满足第4条规定的声明义务而必须使用除外。 | ||
|
||
4. 分发限制 | ||
|
||
您可以在任何媒介中将“软件”以源程序形式或可执行形式重新分发,不论修改与否,但您必须向接收者提供“本许可证”的副本,并保留“软件”中的版权、商标、专利及免责声明。 | ||
|
||
5. 免责声明与责任限制 | ||
|
||
“软件”及其中的“贡献”在提供时不带任何明示或默示的担保。在任何情况下,“贡献者”或版权所有者不对任何人因使用“软件”或其中的“贡献”而引发的任何直接或间接损失承担责任,不论因何种原因导致或者基于何种法律理论,即使其曾被建议有此种损失的可能性。 | ||
|
||
6. 语言 | ||
|
||
“本许可证”以中英文双语表述,中英文版本具有同等法律效力。如果中英文版本存在任何冲突不一致,以中文版为准。 | ||
|
||
条款结束 | ||
|
||
Mulan Permissive Software License,Version 2 (Mulan PSL v2) | ||
|
||
January 2020 http://license.coscl.org.cn/MulanPSL2 | ||
|
||
Your reproduction, use, modification and distribution of the Software shall be subject to Mulan PSL v2 (this License) with the following terms and conditions: | ||
|
||
0. Definition | ||
|
||
Software means the program and related documents which are licensed under this License and comprise all Contribution(s). | ||
|
||
Contribution means the copyrightable work licensed by a particular Contributor under this License. | ||
|
||
Contributor means the Individual or Legal Entity who licenses its copyrightable work under this License. | ||
|
||
Legal Entity means the entity making a Contribution and all its Affiliates. | ||
|
||
Affiliates means entities that control, are controlled by, or are under common control with the acting entity under this License, ‘control’ means direct or indirect ownership of at least fifty percent (50%) of the voting power, capital or other securities of controlled or commonly controlled entity. | ||
|
||
1. Grant of Copyright License | ||
|
||
Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable copyright license to reproduce, use, modify, or distribute its Contribution, with modification or not. | ||
|
||
2. Grant of Patent License | ||
|
||
Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (except for revocation under this Section) patent license to make, have made, use, offer for sale, sell, import or otherwise transfer its Contribution, where such patent license is only limited to the patent claims owned or controlled by such Contributor now or in future which will be necessarily infringed by its Contribution alone, or by combination of the Contribution with the Software to which the Contribution was contributed. The patent license shall not apply to any modification of the Contribution, and any other combination which includes the Contribution. If you or your Affiliates directly or indirectly institute patent litigation (including a cross claim or counterclaim in a litigation) or other patent enforcement activities against any individual or entity by alleging that the Software or any Contribution in it infringes patents, then any patent license granted to you under this License for the Software shall terminate as of the date such litigation or activity is filed or taken. | ||
|
||
3. No Trademark License | ||
|
||
No trademark license is granted to use the trade names, trademarks, service marks, or product names of Contributor, except as required to fulfill notice requirements in section 4. | ||
|
||
4. Distribution Restriction | ||
|
||
You may distribute the Software in any medium with or without modification, whether in source or executable forms, provided that you provide recipients with a copy of this License and retain copyright, patent, trademark and disclaimer statements in the Software. | ||
|
||
5. Disclaimer of Warranty and Limitation of Liability | ||
|
||
THE SOFTWARE AND CONTRIBUTION IN IT ARE PROVIDED WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED. IN NO EVENT SHALL ANY CONTRIBUTOR OR COPYRIGHT HOLDER BE LIABLE TO YOU FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO ANY DIRECT, OR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING FROM YOUR USE OR INABILITY TO USE THE SOFTWARE OR THE CONTRIBUTION IN IT, NO MATTER HOW IT’S CAUSED OR BASED ON WHICH LEGAL THEORY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. | ||
|
||
6. Language | ||
|
||
THIS LICENSE IS WRITTEN IN BOTH CHINESE AND ENGLISH, AND THE CHINESE VERSION AND ENGLISH VERSION SHALL HAVE THE SAME LEGAL EFFECT. IN THE CASE OF DIVERGENCE BETWEEN THE CHINESE AND ENGLISH VERSIONS, THE CHINESE VERSION SHALL PREVAIL. | ||
|
||
END OF THE TERMS AND CONDITIONS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,225 @@ | ||
# imi-tdengine | ||
|
||
<p align="center"> | ||
<a href="https://www.imiphp.com" target="_blank"> | ||
<img src="https://cdn.jsdelivr.net/gh/imiphp/imi@2.0/res/logo.png" alt="imi" /> | ||
</a> | ||
</p> | ||
|
||
[![Latest Version](https://img.shields.io/packagist/v/imiphp/imi-tdengine.svg)](https://packagist.org/packages/imiphp/imi-tdengine) | ||
![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/imiphp/imi-tdengine/ci/dev) | ||
[![Php Version](https://img.shields.io/badge/php-%3E=7.4-brightgreen.svg)](https://secure.php.net/) | ||
[![Swoole Version](https://img.shields.io/badge/swoole-%3E=4.7.0-brightgreen.svg)](https://github.com/swoole/swoole-src) | ||
[![imi Doc](https://img.shields.io/badge/docs-passing-green.svg)](https://doc.imiphp.com/v2.0/) | ||
[![imi License](https://img.shields.io/badge/license-MulanPSL%201.0-brightgreen.svg)](https://github.com/imiphp/imi-tdengine/blob/2.0/LICENSE) | ||
|
||
## 介绍 | ||
|
||
封装 tdengine 连接池,支持在 imi 框架中使用。 | ||
|
||
本组件支持 RESTful 和扩展两种方式实现。 | ||
|
||
扩展安装请移步:<https://github.com/Yurunsoft/php-tdengine> | ||
|
||
imi 框架交流群:17916227 [![点击加群](https://pub.idqqimg.com/wpa/images/group.png "点击加群")](https://jq.qq.com/?_wv=1027&k=5wXf4Zq) | ||
|
||
## 使用 | ||
|
||
引入本组件:`composer require imiphp/imi-tdengine` | ||
|
||
### 配置 | ||
|
||
项目配置文件:(config/config.php) | ||
|
||
```php | ||
// Swoole 连接池配置,非 Swoole 不要配 | ||
// 连接池必须使用扩展 | ||
'pools' => [ | ||
'连接池名' => [ | ||
'pool' => [ | ||
'class' => \Imi\TDengine\Pool\TDengineExtensionCoroutinePool::class, | ||
'config' => [ | ||
'maxResources' => 10, | ||
'minResources' => 0, | ||
], | ||
], | ||
'resource' => [ | ||
'host' => '127.0.0.1', | ||
'port' => 6030, | ||
'user' => 'root', | ||
'password' => 'taosdata', | ||
'db' => 'db_test', | ||
], | ||
], | ||
], | ||
|
||
'beans' => [ | ||
// db 配置 | ||
'TDengine' => [ | ||
'defaultPoolName' => '默认连接名', | ||
'connections' => [ | ||
// 扩展配置,不需要可不配 | ||
'连接名1' => [ | ||
'extension' => true, // 必须设为 true | ||
'host' => '127.0.0.1', | ||
'port' => 6030, | ||
'user' => 'root', | ||
'password' => 'taosdata', | ||
'db' => 'db_test', | ||
], | ||
// restful 配置,不需要可不配 | ||
'连接名2' => [ | ||
'host' => '127.0.0.1', | ||
'hostName' => '', // 域名,没有可不填 | ||
'port' => 6041, | ||
'user' => 'root', | ||
'password' => 'taosdata', | ||
'db' => 'db_test' | ||
'ssl' => false, | ||
'timestampFormat' => \Yurun\TDEngine\Constants\TimeStampFormat::LOCAL_STRING, | ||
'keepAlive' => true, | ||
], | ||
], | ||
], | ||
], | ||
``` | ||
|
||
### 模型 | ||
|
||
使用参考:<https://github.com/Yurunsoft/tdengine-orm> | ||
|
||
### 连接操作 | ||
|
||
直接操作连接对象,执行 SQL 语句 | ||
|
||
#### 获取连接对象 | ||
|
||
```php | ||
// 获取默认连接名的连接 | ||
$connection = \Imi\TDengine\Pool\TDengine::getConnection(); | ||
// 获取指定连接名的连接 | ||
$connection = \Imi\TDengine\Pool\TDengine::getConnection('连接名123'); | ||
// 如果是扩展,$connection 类型为 \TDengine\Connection | ||
// 如果是 restful,$connection 类型为 \Yurun\TDEngine\Client | ||
``` | ||
|
||
#### 扩展用法 | ||
|
||
**查询:** | ||
|
||
```php | ||
// 查询 | ||
$resource = $connection->query($sql); // 支持查询和插入 | ||
// 获取结果集时间戳字段的精度,0 代表毫秒,1 代表微秒,2 代表纳秒 | ||
$resource->getResultPrecision(); | ||
// 获取所有数据 | ||
$resource->fetch(); | ||
// 获取一行数据 | ||
$resource->fetchRow(); | ||
// 获取字段数组 | ||
$resource->fetchFields(); | ||
// 获取列数 | ||
$resource->getFieldCount(); | ||
// 获取影响行数 | ||
$resource->affectedRows(); | ||
// 获取 SQL 语句 | ||
$resource->getSql(); | ||
// 获取连接对象 | ||
$resource->getConnection(); | ||
// 关闭资源(一般不需要手动关闭,变量销毁时会自动释放) | ||
$resource->close(); | ||
``` | ||
|
||
**参数绑定:** | ||
|
||
```php | ||
// 查询 | ||
$stmt = $connection->prepare($sql); // 支持查询和插入,参数用?占位 | ||
// 绑定参数方法1 | ||
$stmt->bindParams( | ||
// [字段类型, 值] | ||
[TDengine\TSDB_DATA_TYPE_TIMESTAMP, $time1], | ||
[TDengine\TSDB_DATA_TYPE_INT, 36], | ||
[TDengine\TSDB_DATA_TYPE_FLOAT, 44.5], | ||
); | ||
// 绑定参数方法2 | ||
$stmt->bindParams([ | ||
// ['type' => 字段类型, 'value' => 值] | ||
['type' => TDengine\TSDB_DATA_TYPE_TIMESTAMP, 'value' => $time2], | ||
['type' => TDengine\TSDB_DATA_TYPE_INT, 'value' => 36], | ||
['type' => TDengine\TSDB_DATA_TYPE_FLOAT, 'value' => 44.5], | ||
]); | ||
// 执行 SQL,返回 Resource,使用方法同 query() 返回值 | ||
$resource = $stmt->execute(); | ||
// 获取 SQL 语句 | ||
$stmt->getSql(); | ||
// 获取连接对象 | ||
$stmt->getConnection(); | ||
// 关闭(一般不需要手动关闭,变量销毁时会自动释放) | ||
$stmt->close(); | ||
``` | ||
|
||
**字段类型:** | ||
|
||
| 参数名称 | 说明 | | ||
| ------------ | ------------ | ||
| `TDengine\TSDB_DATA_TYPE_NULL` | null | | ||
| `TDengine\TSDB_DATA_TYPE_BOOL` | bool | | ||
| `TDengine\TSDB_DATA_TYPE_TINYINT` | tinyint | | ||
| `TDengine\TSDB_DATA_TYPE_SMALLINT` | smallint | | ||
| `TDengine\TSDB_DATA_TYPE_INT` | int | | ||
| `TDengine\TSDB_DATA_TYPE_BIGINT` | bigint | | ||
| `TDengine\TSDB_DATA_TYPE_FLOAT` | float | | ||
| `TDengine\TSDB_DATA_TYPE_DOUBLE` | double | | ||
| `TDengine\TSDB_DATA_TYPE_BINARY` | binary | | ||
| `TDengine\TSDB_DATA_TYPE_TIMESTAMP` | timestamp | | ||
| `TDengine\TSDB_DATA_TYPE_NCHAR` | nchar | | ||
| `TDengine\TSDB_DATA_TYPE_UTINYINT` | utinyint | | ||
| `TDengine\TSDB_DATA_TYPE_USMALLINT` | usmallint | | ||
| `TDengine\TSDB_DATA_TYPE_UINT` | uint | | ||
| `TDengine\TSDB_DATA_TYPE_UBIGINT` | ubigint | | ||
|
||
#### restful 用法 | ||
|
||
```php | ||
// 通过 sql 方法执行 sql 语句 | ||
var_dump($connection->sql('create database if not exists db_test')); | ||
var_dump($connection->sql('show databases')); | ||
var_dump($connection->sql('create table if not exists db_test.tb (ts timestamp, temperature int, humidity float)')); | ||
var_dump($connection->sql(sprintf('insert into db_test.tb values(%s,%s,%s)', time() * 1000, mt_rand(), mt_rand() / mt_rand()))); | ||
|
||
$result = $connection->sql('select * from db_test.tb'); | ||
|
||
$result->getResponse(); // 获取接口原始返回数据 | ||
|
||
// 获取列数据 | ||
foreach ($result->getColumns() as $column) | ||
{ | ||
$column->getName(); // 列名 | ||
$column->getType(); // 列类型值 | ||
$column->getTypeName(); // 列类型名称 | ||
$column->getLength(); // 类型长度 | ||
} | ||
|
||
// 获取数据 | ||
foreach ($result->getData() as $row) | ||
{ | ||
echo $row['列名']; // 经过处理,可以直接使用列名获取指定列数据 | ||
} | ||
|
||
$result->getStatus(); // 告知操作结果是成功还是失败;同接口返回格式 | ||
|
||
$result->getHead(); // 表的定义,如果不返回结果集,则仅有一列“affected_rows”。(从 2.0.17 版本开始,建议不要依赖 head 返回值来判断数据列类型,而推荐使用 column_meta。在未来版本中,有可能会从返回值中去掉 head 这一项。);同接口返回格式 | ||
|
||
$result->getRow(); // 表明总共多少行数据;同接口返回格式 | ||
``` | ||
|
||
## 版权信息 | ||
|
||
imi 遵循 木兰宽松许可证(Mulan PSL v2) 开源协议发布,并提供免费使用。 | ||
|
||
## 捐赠 | ||
|
||
![捐赠](https://cdn.jsdelivr.net/gh/imiphp/imi@2.0/res/pay.png) | ||
|
||
开源不求盈利,多少都是心意,生活不易,随缘随缘…… |
Oops, something went wrong.