Skip to content

arkhamvm/clickhouse

 
 

Repository files navigation

Extension ClickHouse for Yii 2

This extension provides the ClickHouse integration for the Yii framework 2.0.

Build Status

Installation

The preferred way to install this extension is through composer.

Either run

composer require bashkarev/clickhouse

Configuration

To use this extension, simply add the following code in your application configuration:

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

All settings

Using DebugPanel

Add the following to you application config to enable it (if you already have the debug module enabled, it is sufficient to just add the panels configuration):

    // ...
    '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.
                ],
            ],
        ],
    ],
    // ...

Using Migrations

In order to enable this command you should adjust the configuration of your console application:

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

Insert csv files

Files are uploaded in parallel.

/**
 * @var \bashkarev\clickhouse\InsertFiles $insert
 */
$insert = Yii::$app->clickhouse->createCommand()->batchInsertFiles('csv',[
    '@vendor/bashkarev/clickhouse/tests/data/csv/e1e747f9901e67ca121768b36921fbae.csv',
    '@vendor/bashkarev/clickhouse/tests/data/csv/ebe191dfc36d73aece91e92007d24e3e.csv',
]);
$insert
    ->setFiles(fopen('/csv/ebe191dfc36d73aece91e92007d24e3e.csv','rb'))
    ->setChunkSize(8192) // default 4096 bytes
    ->execute();

About

Extension ClickHouse for Yii 2

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%