bashkarev/clickhouse

适用于列式数据库ClickHouse的yii2驱动程序。

安装数量: 94,352

依赖项: 0

建议者: 0

安全性: 0

星标: 22

关注者: 3

分支: 15

公开问题: 4

类型:yii2-extension

2.0.5 2021-09-17 11:03 UTC

This package is auto-updated.

Last update: 2024-09-17 17:35:49 UTC


README

此扩展为ClickHouse集成Yii框架2.0。主要功能

  • SQL命令
  • 查询构建器
  • 模式构建器
  • 迁移
  • 批量插入
  • 并行从大型CSV文件中插入
  • 在PHP中正确处理UInt64类型
  • 支持十进制和可空字段

Build Status

安装

安装此扩展的首选方法是通过composer

运行以下命令之一

composer require bashkarev/clickhouse

配置

要使用此扩展,只需将以下代码添加到您的应用程序配置中

return [
    //....
    'clickhouse' => [
        'class' => 'bashkarev\clickhouse\Connection',
        'dsn' => 'host=localhost;port=8123;database=default;connect_timeout_with_failover_ms=10',
        'username' => 'default',
        'password' => '',
    ],
];

所有设置

使用DebugPanel

将以下内容添加到您的应用程序配置中以启用它(如果已启用debug模块,则只需添加面板配置即可)

    // ...
    'bootstrap' => ['debug'],
    'modules' => [
        'debug' => [
            'class' => 'yii\\debug\\Module',
            'panels' => [
                'clickhouse' => [
                    'class' => 'bashkarev\clickhouse\debug\Panel',
                    // 'db' => 'clickhouse', // ClickHouse component ID, defaults to `db`. Uncomment and change this line, if you registered component with a different ID.
                ],
            ],
        ],
    ],
    // ...

使用迁移

为了启用此命令,您应调整控制台应用程序的配置

return [
    // ...
    'controllerMap' => [
        'clickhouse-migrate' => 'bashkarev\clickhouse\console\controllers\MigrateController'
    ],
];
# creates a new migration named 'create_target'
yii clickhouse-migrate/create create_target

# applies ALL new migrations
yii clickhouse-migrate

# reverts the last applied migration
yii clickhouse-migrate/down

访问原生的SMI2 ClickHouse客户端

$client = \Yii::$app->clickhouse->getClient();

插入csv文件

文件并行上传。

$db = \Yii::$app->clickhouse;
$client = $db->getClient();

$results = $client->insertBatchFiles('table_name', ['file_with_data.csv']);

$state = $results['file_with_data.csv'];
$isSuccess = !$state->isError();
$uploadInfo = $state->responseInfo();

print_r($uploadInfo);