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.10
2024-09-05 10:55 UTC
Requires
- php: ^8.0
- bavix/laravel-clickhouse: ^2.0 | ^2.3
- illuminate/support: ^8.0 | ^10.0
Requires (Dev)
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.0
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
- PHP 8
- Laravel 8
- https://github.com/bavix/laravel-clickhouse
- https://github.com/MariosTheof/laravel-clickhouse-migrations
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.