bavix / laravel-clickhouse
Eloquent model for ClickHouse
3.0.3
2024-04-01 18:39 UTC
Requires
- php: ^8.2
- ext-json: *
- laravel/framework: ^10.0|^11.0
- the-tinderbox/clickhouse-builder: ^6.1
Requires (Dev)
- driftingly/rector-laravel: ^1.0
- ergebnis/phpstan-rules: ^2.1
- fakerphp/faker: ^1.23
- infection/infection: ~0.27
- larastan/larastan: ^2.8
- mockery/mockery: ^1.6
- nunomaduro/collision: ^8.0
- orchestra/testbench: ^9.0
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.5
- rector/rector: ^1.0
- symplify/easy-coding-standard: ^12.1
README
Laravel Clickhouse - Eloquent model for ClickHouse.
- Vendor: bavix
- Package: laravel-clickhouse
- Composer:
composer require bavix/laravel-wallet-uuid
Important
I recommend using the standard postgres/mysql interface for clickhouse. More details here: https://clickhouse.com/docs/en/interfaces/mysql
The implementation is provided as is. Further work with the library only through contributors. Added linters, tests and much more. To make it easier for you to send PR.
Get started
$ composer require bavix/laravel-clickhouse
Then add the code above into your config/app.php file providers section
Bavix\LaravelClickHouse\ClickHouseServiceProvider::class,
And add new connection into your config/database.php file. Something like this:
'connections' => [ 'bavix::clickhouse' => [ 'driver' => 'bavix::clickhouse', 'host' => '', 'port' => '', 'database' => '', 'username' => '', 'password' => '', 'options' => [ 'timeout' => 10, 'protocol' => 'https' ] ] ]
Or like this, if clickhouse runs in cluster
'connections' => [ 'bavix::clickhouse' => [ 'driver' => 'bavix::clickhouse', 'servers' => [ [ 'host' => 'ch-00.domain.com', 'port' => '', 'database' => '', 'username' => '', 'password' => '', 'options' => [ 'timeout' => 10, 'protocol' => 'https' ] ], [ 'host' => 'ch-01.domain.com', 'port' => '', 'database' => '', 'username' => '', 'password' => '', 'options' => [ 'timeout' => 10, 'protocol' => 'https' ] ] ] ] ],
Then create model
<?php use Bavix\LaravelClickHouse\Database\Eloquent\Model; class Payment extends Model { protected $table = 'payments'; }
And use it
Payment::select(raw('count() AS cnt'), 'payment_system') ->whereBetween('payed_at', [ Carbon\Carbon::parse('2017-01-01'), now(), ]) ->groupBy('payment_system') ->get();
Supported by