PHP code example of akbarali1 / laravel-clickhouse-eloquent
1. Go to this page and download the library: Download akbarali1/laravel-clickhouse-eloquent 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/ */
akbarali1 / laravel-clickhouse-eloquent example snippets
namespace App\Models\Clickhouse;
use LaravelClickhouseEloquent\BaseModel;
class MyTable extends BaseModel
{
// Not necessary. Can be obtained from class name MyTable => my_table
protected $table = 'my_table';
}
namespace App\Models\Clickhouse;
use LaravelClickhouseEloquent\BaseModel;
class MyTable extends BaseModel
{
/**
* The columns that should be cast.
*
* @var array
*/
protected $casts = ['some_bool_column' => 'boolean'];
}
// Then you can insert the data like this:
MyTable::insertAssoc([
['some_param' => 1, 'some_bool_column' => false],
]);
// Split the result into chunks of 30 rows
$rows = MyTable::select(['field_one', 'field_two'])
->chunk(30, function ($rows) {
foreach ($rows as $row) {
echo $row['field_two'] . "\n";
}
});
namespace App\Models\Clickhouse;
use LaravelClickhouseEloquent\BaseModel;
class MyTable extends BaseModel
{
// Not necessary. Can be obtained from class name MyTable => my_table
protected $table = 'my_table';
// All inserts will be in the table $tableForInserts
// But all selects will be from $table
protected $tableForInserts = 'my_table_buffer';
}
namespace App\Models\Clickhouse;
use LaravelClickhouseEloquent\BaseModel;
class MyTable extends BaseModel
{
protected $table = 'my_table_buffer';
}
namespace App\Models\Clickhouse;
use LaravelClickhouseEloquent\BaseModel;
class MyTable extends BaseModel
{
// All SELECT's and INSERT's on $table
protected $table = 'my_table_buffer';
// OPTIMIZE and DELETE on $tableSources
protected $tableSources = 'my_table';
}
MyTable::where('field_one', 123)->update(['field_two' => 'new_val']);
// or expression
MyTable::where('field_one', 123)
->update(['field_two' => new RawColumn("concat(field_two,'new_val')")]);
// Array data type
MyTable::insertAssoc([[1, 'str', new InsertArray(['a','b'])]]);
namespace App\Models\Clickhouse;
use LaravelClickhouseEloquent\BaseModel;
class MyTable2 extends BaseModel
{
protected $connection = 'clickhouse2';
protected $table = 'my_table2';
}
return new class extends \LaravelClickhouseEloquent\Migration
{
protected $connection = 'clickhouse2';
public function up()
{
static::write('CREATE TABLE my_table2 ...');
}
public function down()
{
static::write('DROP TABLE my_table2');
}
};
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.