ddkirawan/clickhouse

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

安装: 0

依赖: 0

建议者: 0

安全性: 0

星星: 0

关注者: 0

分支: 15

类型:yii2-extension

dev-master 2021-09-17 11:03 UTC

This package is auto-updated.

Last update: 2024-09-22 09:54:12 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

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

    // ...
    '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);