allesx/laravel-clickhouse

Eloquent model for ClickHouse

3.0.0 2021-05-25 13:20 UTC

This package is auto-updated.

Last update: 2024-10-25 20:54:25 UTC


README

Latest Stable Version Latest Unstable Version License composer.lock

Laravel Clickhouse - Eloquent model for ClickHouse.

  • Vendor: allesx
  • Package: Laravel Clickhouse
  • Version: Latest Stable Version
  • Laravel Version: 5.8.x
  • PHP Version: 7.1.3+
  • Composer: composer require allesx/laravel-clickhouse

Get started

$ composer require allesx/laravel-clickhouse

Then add the code above into your config/app.php file providers section

Allesx\LaravelClickHouse\ClickHouseServiceProvider::class,

And add new connection into your config/database.php file. Something like this:

'connections' => [
    'allesx::clickhouse' => [
        'driver' => 'allesx::clickhouse',
        'host' => '',
        'port' => '',
        'database' => '',
        'username' => '',
        'password' => '',
        'options' => [
            'timeout' => 10,
            'protocol' => 'https'
        ]
    ]
]

Or like this, if clickhouse runs in cluster

'connections' => [
    'allesx::clickhouse' => [
        'driver' => 'allesx::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 Allesx\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();