tensai-eleven/amphp-clickhouse

Simple asynchronous ClickHouse client based on amphp/artax

dev-master 2021-02-19 12:14 UTC

This package is not auto-updated.

Last update: 2021-02-19 12:15:58 UTC


README

Create table

\Amp\Loop::run(function () {
    $client = new Client();
    
    $sql = "create table t (date Date, array Array(UInt8), data Nullable(String), bool UInt8) ENGINE = Memory";
    
    yield $client->query($sql);
});

Insert

\Amp\Loop::run(function () {
    $client = new Client();
    
    $values = [
        ['1970-01-01', [1, 2], "Hello\tworld\n", false],
        ['1980-07-19', [203, 21], "foo\\bar", true],
    ];
    
    yield $client->insert('t', $values);
});

Select

\Amp\Loop::run(function () {
    $client = new Client();
    
    $sql = 'select * from table t';
    
    $response = yield $client->query($sql);
    $iterator = $response->iterate();
    
    while (yield $iterator->advance()) {
        $values = $iterator->getCurrent();
        // Do something with $values
    }
});