Git Product home page Git Product logo

clickhouse's Introduction

Extension ClickHouse for Yii 2

This extension provides the ClickHouse integration for the Yii framework 2.0. Main features:

  • SQL commands
  • Query builder
  • Schema builder
  • Migrations
  • Batch Insert
  • Parallel insert from large CSV files
  • Valid handling of UInt64 type in PHP
  • Supports Decimals and Nullable fields

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

Access to native SMI2 ClickHouse client

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

Insert csv files

Files are uploaded in parallel.

$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);

clickhouse's People

Contributors

bashkarev avatar sartor avatar zkelo avatar fgh151 avatar mysterydragon avatar arkhamvm avatar tyron098 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.