prageeth-peiris/laravel-query-builder-to-clickhouse

A Simple Package to execute the raw sql query provided by laravel query builder in yandex clickhouse databsae.

1.7.0 2024-04-29 10:15 UTC

This package is auto-updated.

Last update: 2024-04-29 10:17:05 UTC


README

You can install the package via composer:

composer require prageeth-peiris/laravel-query-builder-to-clickhouse

Usage

// Usage description here

//Add following database connections to config/database.php 

       'bavix::clickhouse' => [
            'driver' => 'bavix::clickhouse',
            'host' => env('CLICKHOUSE_HOST'),
            'port' => env('CLICKHOUSE_PORT',8123),
            'database' => env('CLICKHOUSE_DATABASE'),
            'username' => env('CLICKHOUSE_USER','default'),
            'password' => env('CLICKHOUSE_PASSWORD'),
            'options' => [
                'timeout' => 20,
                'protocol' => 'http'
            ]
        ],
        'clickhouse_custom' => [
            'driver' => 'bavix::clickhouse::custom',
            'host' => env('CLICKHOUSE_HOST'),
            'port' => env('CLICKHOUSE_PORT',8123),
            'database' => env('CLICKHOUSE_DATABASE'),
            'username' => env('CLICKHOUSE_USER','default'),
            'password' => env('CLICKHOUSE_PASSWORD'),
            'options' => [
                'timeout' => 20,
                'protocol' => 'http'
            ]
        ]

//extend from this model and start using clickhouse
use PrageethPeiris\LaravelQueryBuilderToClickhouse\Model;

Class CustomModel extends BaseClickHouseModel {

//this is required if you are doing sub query joining
      protected $tableJoinKey = 'page';

}

//use table with a suffix at runtime
CustomModel::useTableSuffix("in_memory")->insert($data)

//here comes a method to do sub query joining very easily
CustomModel::autoLeftJoinSubQuery(CustomModel::class,OtherModel::GroupBySomething())
->autoLeftJoinSubQuery(CustomModel::class,OtherModel::GroupBySomethingAndSomething())

NOTE

This is an opinionated package so this cache results by raw clickhosue sql query. It will use your default cache driver. to clear cache run php artisan cache:clear

Dependencies

Read related packages documentation to use their config.

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 glpspeiris@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.