umbri/clickhouse

There is no license information available for the latest version (dev-master) of this package.

Async PHP Clickhouse Client

dev-master 2017-09-12 13:01 UTC

This package is not auto-updated.

Last update: 2020-08-08 05:39:33 UTC


README

Async PHP Clickhouse Client

based on:

TODO

  • tests
  • cluster support
  • add ReactPHP support
  • add Temporary tables support
  • add File support

raw example

\Amp\Loop::run(function () {

    try {
        $client = new \Umbri\Clickhouse\Client(new \Tinderbox\Clickhouse\Server("127.0.0.1"));

        $res = yield $client->statement("CREATE DATABASE test");

        yield $client->statement("CREATE TABLE test.table1 (
                      key Date DEFAULT today(),
                      msg String)
                  ENGINE = ReplacingMergeTree(key, (key, msg), 16)");

        yield $client->insert('INSERT INTO test.table1 (msg) values (?), (?)', ['string1', 'string2']);

        /**
         * @var $select \Tinderbox\Clickhouse\Query\Result
         */
        $select = yield $client->select("SELECT * FROM test.table1");

        echo print_r($select->getRows(), true) . PHP_EOL;
        
    } catch (Throwable $e) {
        echo $e;
    }
});

query builder example

\Amp\Loop::run(function () {

    try {
        $client = new \Umbri\Clickhouse\Client(new \Tinderbox\Clickhouse\Server("127.0.0.1"));
        $query = new \Umbri\Clickhouse\Query($client);

        yield $client->statement("DROP DATABASE IF EXISTS test");
        yield $client->statement("CREATE DATABASE test");
        yield $client->statement("CREATE TABLE test.table1 (
                      key Date DEFAULT today(),
                      msg String)
                  ENGINE = ReplacingMergeTree(key, (key, msg), 16)");

        /**
         * @var $res \Tinderbox\Clickhouse\Query\Result
         */
        $res = yield $query->table("system.databases")->get();

        print_r($res->getRows());

        yield $query->table('test.table1')->insert([
            ["msg" => "msg1"],
            ["msg" => "msg2"],
            ["msg" => "msg3"],
        ]);

        $res = yield $query->select("msg")->from("test.table1")->get();

        print_r($res->getRows());
        
    } catch (Throwable $e) {
        echo $e;
    }
});