Laravel ClickHouse is a database driver that integrates ClickHouse with Laravel, including Eloquent, the Query Builder, Schema Builder, and more:
- Eloquent models with non-incrementing ID support
- Query Builder with ClickHouse-specific clauses (i.e.,
FINAL,ARRAY JOIN,SAMPLE) - Schema Builder with
ENGINE,PARTITION BY,ORDER BY, 和LowCardinalitycolumn types - Laravel migration support via
artisan migrate - Concurrent query execution using Guzzle's async HTTP pool
- Dual HTTP transport options: Guzzle and Curl/phpclickhouse
ClickHouse is an open-source column-oriented database built for analytical workloads. It stores data by column rather than by row, making aggregations over large datasets fast—capable of querying billions of rows in seconds. It's a common choice for event tracking, time-series data, and analytics dashboards where read performance at scale is the priority.
Eloquent 模型
You can define Eloquent models pointing at ClickHouse the same way you would for any other database connection:
班级
事件
延伸
模型{
受保护
$连接
=
'clickhouse'
;}$事件
=
事件
::
在哪里
(
'用户身份'
,
1
)
->
得到
();
ClickHouse doesn't use auto-incrementing primary keys, so the driver configures models with non-incrementing IDs by default. Scopes and collections work as expected.
Query Builder with ClickHouse Extensions
The Query Builder covers standard Laravel methods and adds ClickHouse-specific clauses. The
final
parameter applies the
FINAL
modifier to a query, which forces ClickHouse to merge duplicate rows at read time—useful with the
ReplacingMergeTree
engine:
$事件
=
数据库
::
联系
(
'clickhouse'
)
->
桌子
(
“事件”
,
最终的
:
真的
)
->
在哪里
(
'用户身份'
,
1
)
->
得到
();
Other extensions include
PREWHERE
(ClickHouse's pre-filter for primary key columns),
ARRAY JOIN
,
SAMPLE
,
LIMIT BY
, 和
SEMI
/
ANTI
/
ASOF
join types.
Schema Builder and Migrations
The Schema Builder supports ClickHouse DDL via a
ClickHouseBlueprint
, letting you define table engines, partition keys, order keys, and column types like
LowCardinality
:
架构
::
联系
(
'clickhouse'
)
->
创造
(
“事件”
,
功能
(
ClickHouseBlueprint
$table) {$表
->
引擎
(
'MergeTree()'
(英文):$表
->
orderBy
([
'ID'
,
'created_at'
]);$表
->
partitionBy
(
'toYYYYMM(created_at)'
(英文):});
标准
artisan migrate
commands work with a ClickHouse-compatible migration repository, so you can manage schema changes alongside your other databases.
Concurrent Query Execution
The package includes a
Parallel
helper that runs multiple queries at the same time using Guzzle's async HTTP pool:
$结果
=
平行线
::
得到
([
“用户”
=>
用户
::
在哪里
(
'积极的'
,
1
),
“事件”
=>
事件
::
在哪里
(
'类型'
,
'点击'
),]);
两个都
users
和
events
execute concurrently, and the results are returned as a keyed array once all queries resolve.
You can find the full documentation and source on GitHub 。







