bavix/clickhouse-builder
PHP 7.1+ query builder for ClickHouse. Build and execute SELECT queries with a fluent API: select columns with aliases, closures for complex expressions or subqueries, and integrate with the-tinderbox/clickhouse-php-client for execution.
SAMPLE, ARRAY JOIN, dictGetString, LIMIT BY), which are critical for analytical workloads.TempTable) address ClickHouse’s strengths (e.g., bulk operations, distributed processing) but may introduce complexity for teams unfamiliar with these patterns.ClickhouseServiceProvider for seamless Laravel integration, with config options mirroring Laravel’s database.php. This reduces boilerplate for connecting to ClickHouse clusters or standalone servers.clickhouse-php-client: Requires the-tinderbox/clickhouse-php-client (v7.1+), which must be installed separately. This adds a minor dependency risk but ensures compatibility with ClickHouse’s PHP client.where clauses). Laravel’s query builder already handles this via binding parameters, but ClickHouse’s syntax (e.g., dictGetString) may need additional sanitization.sumIf) are "not stable and under development," which could break queries in future updates.DateTime64, Nullable)?where/join clauses? If not, how should Laravel’s query binding be adapted?ClickhouseServiceProvider) enables ClickHouse to be treated as a first-class database connection alongside MySQL/PostgreSQL.ARRAY JOIN).composer require the-tinderbox/clickhouse-builder the-tinderbox/clickhouse-php-client
config/app.php:
\Tinderbox\ClickhouseBuilder\Integrations\Laravel\ClickhouseServiceProvider::class
config/database.php:
'clickhouse' => [
'driver' => 'clickhouse',
'servers' => [...], // Cluster or single server
'options' => [...],
]
// Before
DB::select("SELECT * FROM events WHERE user_id = ?", [$userId]);
// After
DB::connection('clickhouse')->query()
->from('events')
->where('user_id', $userId)
->get();
// Temporary tables for large IN clauses
$builder->addFile(new TempTable('user_ids', 'users.tsv', ['id' => 'UInt64']))
->from('events')
->whereIn('user_id', 'user_ids')
->get();
// Async queries
$builder->asyncWithQuery(function($q) {
$q->from('events')->limit(1000);
})->get();
dictGetString) may not work with older ClickHouse versions.select, from, join, where, groupBy, orderBy, limit, union, subqueries.cursor, chunk, or Eloquent relationships (would need custom implementation).SELECT/INSERT queries with the builder.TempTable, ARRAY JOIN).whereEventType).clickhouse-php-client for updates (breaking changes possible).composer.json to avoid surprises.DB::connection('clickhouse')->enableQueryLog();
->toSql() to inspect queries before execution.insertFile for bulk data loading or raw SQL for schema changes.Code: 1001, e.displayText(): DB::Exception). Log raw errors for debugging.dd($builder->toSql()) for inspection.LIMIT BY, ARRAY JOIN). Async queries reduce latency for parallel workloads.system.processes table for long-running queries.servers config. Ensure load balancing is configured in ClickHouse.| Scenario | Risk | Mitigation |
|---|---|---|
| ClickHouse server down | Query failures | Implement retry logic with exponential backoff. |
| Malformed SQL | Syntax errors |
How can I help you explore Laravel packages today?