PHP code example of glushkovds / php-clickhouse-schema-builder

1. Go to this page and download the library: Download glushkovds/php-clickhouse-schema-builder library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

glushkovds / php-clickhouse-schema-builder example snippets


use PhpClickHouseSchemaBuilder\Tables\MergeTree;

$ddl = (new MergeTree('some_table'))
    ->dbName('some_db') // optional, for replicated table engine 
    ->onCluster('some_cluster')
    ->columns(fn(MergeTree $t) => [
        $t->string('col_one')->default('5')->comment('some comment'),
        $t->datetime('at'),
    ])
    ->orderBy('col_one')
    ->partition('toDate(at)')
    ->ttl('at', '1 month')
    ->engine((new Engine(Engine::REPLACING_MERGE_TREE))->replicated(), 'col_one')
    ->settings(['ttl_only_drop_parts' => 1, 'index_granularity' => 8192])
    ->compile();