Eloquent model for ClickHouse
- php 7.1
- clickhouse server
Update composer.json and run composer update
"require": {
"esazykin/laravel-clickhouse": "*"
},
"repositories": [
{
"url": "https://github.com/akkyoh/laravel-clickhouse",
"type": "git"
}
]
Then add the code above into your config/app.php file providers section
Esazykin\LaravelClickHouse\ClickHouseServiceProvider::class,
And add new connection into your config/database.php file. Something like this:
'connections' => [
'clickhouse' => [
'driver' => 'clickhouse',
'servers' => [
[
'host' => '127.0.0.1',
'port' => '8123',
'database' => 'default',
'username' => 'default',
'password' => '',
'options' => [
'timeout' => 10,
'protocol' => 'http'
]
]
]
]
]
Then create model
<?php
use Esazykin\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();
- more tests
- Model::with() method
- relations