Download the PHP package glushkovds/phpclickhouse-laravel without Composer
On this page you can find all versions of the php package glushkovds/phpclickhouse-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download glushkovds/phpclickhouse-laravel
More information about glushkovds/phpclickhouse-laravel
Files in glushkovds/phpclickhouse-laravel
Package phpclickhouse-laravel
Short Description Adapter of the most popular library https://github.com/smi2/phpClickHouse to Laravel
License MIT
Homepage https://github.com/glushkovds/phpClickHouse-laravel
Informations about the package phpclickhouse-laravel
phpClickHouse-laravel
Laravel and Lumen adapter for popular ClickHouse libraries:
- https://github.com/smi2/phpClickHouse - connections and query execution
- https://github.com/the-tinderbox/ClickhouseBuilder - query builder
Features
Requires only the PHP cURL extension. PHP 8.0 or higher is supported.
See phpClickHouse features for more details: https://github.com/smi2/phpClickHouse#features
Prerequisites
- PHP 8.0
- Laravel/Lumen 7+
- ClickHouse server
Installation
Install via Composer:
Laravel will discover the package service provider automatically.
The package registers a clickhouse database connection with sensible defaults. Set only the environment values you need to override:
If your application uses cached configuration, rebuild the cache after changing ClickHouse environment values.
The package registers this connection as database.connections.clickhouse automatically when the application does not already define it in config/database.php.
If you need to override the defaults or add advanced options, define the connection in config/database.php:
If you use Lumen or have disabled Laravel package discovery, register the service provider manually:
Usage
You can use smi2/phpClickHouse functionality directly:
See the phpClickHouse documentation for more details: https://github.com/smi2/phpClickHouse/blob/master/README.md
Lightweight Eloquent-like model layer
1. Add a model
2. Add a migration
You can also use the Schema Builder:
3. Insert data
Single row
Bulk insert
4. Query data
Known issues
Known issues are described in docs/known_issues.md.
Advanced usage
Column casting
Before insertion, columns are converted to the data types defined in $casts.
This feature does not apply to data selection.
Supported cast types: boolean.
Events
Events work like Eloquent model events.
Available events: creating, created, saved.
Retries
You may enable request retries for non-200 responses, for example when temporary network issues occur.
Add the value to your .env file:
CLICKHOUSE_RETRIES is optional. The default value is 0.
0 means one attempt.
1 means one attempt plus one retry on error, for a total of two attempts.
Working with huge rows
You can chunk results like in Laravel:
Buffer engine for insert queries
See https://clickhouse.tech/docs/en/engines/table-engines/special/buffer/
If you also want to read from the buffer table, set $table to the buffer table name:
OPTIMIZE Statement
See https://clickhouse.com/docs/ru/sql-reference/statements/optimize/
TRUNCATE Statement
Removes all data from a table.
Deletions
See https://clickhouse.com/docs/en/sql-reference/statements/alter/delete/
When using the Buffer engine, OPTIMIZE and ALTER TABLE DELETE can target the source table:
Updates
See https://clickhouse.com/docs/ru/sql-reference/statements/alter/update/
Helpers for inserting different data types
Working with multiple ClickHouse instances in a project
1. Add a second connection to config/database.php:
2. Add a model
3. Add a migration
Cluster mode
Important!
- Each ClickHouse node must use the same database name, username, and password.
- Reads and writes use the first available node.
- Migrations run on all nodes. If one node is unavailable, the migration will throw an exception.
Your config/database.php should look like this:
Migration example:
You can get the current node host and switch the active connection to the next node:
All versions of phpclickhouse-laravel with dependencies
smi2/phpclickhouse Version ^1.4.2
glushkovds/clickhouse-builder Version ^7
illuminate/support Version >=7
illuminate/database Version >=7
glushkovds/php-clickhouse-schema-builder Version ^1.0.2