Introduction
laravel-clickhouse connects Laravel to ClickHouse. It sends the queries over HTTP with smi2/phpClickHouse. Apart from Laravel, smi2/phpClickHouse is the only dependency. The package contains its query builder, its schema builder and an enum base class. See Credits.
This documentation describes 3.0.0, the last release of 3.x.
Package names
3.0 renamed the package and its namespace:
| 2.x | 3.x | |
|---|---|---|
| Composer package | oralunal/phpclickhouse-laravel | oralunal/laravel-clickhouse |
| Namespace | PhpClickHouseLaravel\ | Oralunal\LaravelClickHouse\ |
The classes, the configuration, the SQL and the behavior are the same as in 2.0.2. See Upgrade.
Features
BaseModel, a model like Eloquent's:create(),save(),insertBulk(),insertAssoc(),where()and pagesOralunal\LaravelClickHouse\Migration, a base class for ClickHouse migrations, on one node or on a clusterphp artisan schema:dump [--prune]squashes the migrations into a schema filephp artisan clickhouse:install-skillsinstalls the upgrade skills for coding agents- A query builder with
settings(),chunk()and ClickHouse SQL - A
booleancast for inserts - The model events
creating,createdandsaved - Retries of failed requests
- Tables with the
Bufferengine:$tableForInsertsand$tableSources - Inserts in a buffer in PHP memory:
buffer()andflushBuffer() OPTIMIZE,TRUNCATE,ALTER TABLE ... DELETEandALTER TABLE ... UPDATE- Many ClickHouse servers, and clusters with node rotation
- A default configuration:
.envvalues are enough for most applications
The smi2 client uses curl, not PDO. See its features.
Requirements
| Software | Version |
|---|---|
| PHP | 8.5 or later |
| Laravel | 13 or later |
| ClickHouse | 24.x. Versions from 20 usually work, but the tests do not cover them. |
Credits
The package contains code from these MIT-licensed projects. Each directory keeps the original license.
| In the package | Origin |
|---|---|
Oralunal\LaravelClickHouse\ClickhouseBuilder | the-tinderbox/ClickhouseBuilder, through the glushkovds and oralunal forks (v1.0.0) |
Oralunal\LaravelClickHouse\ClickhouseSchemaBuilder | glushkovds/php-clickhouse-schema-builder 1.1.1 |
Oralunal\LaravelClickHouse\Enum\Enum | myclabs/php-enum 1.8.5 |
The package is a fork of glushkovds/phpclickhouse-laravel.