Skip to content

An Eloquent model and Query builder with support for Clickhouse using the SeasClick (https://github.com/seasx/seasclick) extension.

License

Notifications You must be signed in to change notification settings

patoui/laravel-clickhouse

Repository files navigation

Laravel Clickhouse

Latest Version on Packagist Build Status Quality Score Total Downloads

An Eloquent model and Query builder with support for Clickhouse using the SeasClick extension.

⚠️ WARNING ⚠️

This package/repository is in active development, use at your own risk.

Requirements

SeasClick extension

Installation

You can install the package via composer:

{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/patoui/laravel-clickhouse"
        }
    ],
    "require": {
        "patoui/laravel-clickhouse": "dev-master"
    }
}

Add service provider

'providers' => [
    // Other Service Providers
    Patoui\LaravelClickhouse\LaravelClickhouseServiceProvider::class,
],

Add connection details

'connections' => [
    'clickhouse' => [
        'host'     => '127.0.0.1',
        'port'     => '9000',
        'username' => 'default',
        'password' => '',
    ]
],

Usage

Use as you normally would an eloquent model or query builder.

See tests directory for additional examples

Below is a list of currently untested methods or functionality. This does not mean that they won't work, just that there is currently no test coverage.

  • union
  • orWhere
  • JSON where clause ->where('meta->name', 'foobar')
  • whereJsonContains
  • whereJsonLength
  • whereBetween
  • whereNotBetween
  • whereIn or whereNotIn
  • whereNull or whereNotNull
  • whereDate, whereMonth, whereDay, whereYear, whereTime
  • orWhereColumn
  • whereExists
  • Subquery Where Clauses
  • Upserts
  • updateOrInsert
  • Updating JSON Columns ->update(['options->enabled' => true]);
  • increment or decrement
DB::connection('clickhouse')->insert(
    'analytics',
    ['ts' => time(), 'analytic_id' => mt_rand(1000, 9999), 'status' => mt_rand(200, 599)]
);
        
DB::connection('clickhouse')->table('analytics')->insert([
    'ts'          => time(),
    'analytic_id' => 321,
    'status'      => 204,
]);

DB::connection('clickhouse')
    ->table('analytics')
    ->where('ts', '>', strtotime('-1 day'))
    ->count();
    
class Analytic extends ClickhouseModel
{
    public $guarded = []; // optional, added for brevity
}

Analytic::create(['ts' => time(), 'analytic_id' => mt_rand(1000, 9999), 'status' => 204, 'name' => 'page_view']);

Analytic::where('ts', '>', strtotime('-1 day'))->count();

Analytic::where('name', 'page_view')->update(['name' => 'page_visit']);

Testing

Testing is done within docker to simplify setting up Clickhouse

docker-compose up --build

Run the tests:

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email patrique.ouimet@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.

About

An Eloquent model and Query builder with support for Clickhouse using the SeasClick (https://github.com/seasx/seasclick) extension.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published