Skip to content

Commit

Permalink
Merge pull request #28 from zkelo/shortcuts
Browse files Browse the repository at this point in the history
Shortcut for UUID data type
  • Loading branch information
sartor authored Sep 17, 2021
2 parents 4d6a942 + 8fb6fff commit 0ff87e3
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
class Migration extends \yii\db\Migration
{
use SchemaBuilderTrait;

public $db = 'clickhouse';

Expand Down
5 changes: 5 additions & 0 deletions Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
*/
class Schema extends \yii\db\mysql\Schema
{
/**
* UUID columnd data type
*/
const TYPE_UUID = 'UUID';

public $columnSchemaClass = 'bashkarev\clickhouse\ColumnSchema';

/**
Expand Down
25 changes: 25 additions & 0 deletions SchemaBuilderTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace bashkarev\clickhouse;

/**
* Schema builder trait
*
* Provides some shortcuts for specific clickhouse data types and etc.
*
* @see \yii\db\SchemaBuilderTrait For better understanding about logic of this trait
* @method \yii\db\Connection getDb()
*/
trait SchemaBuilderTrait
{
/**
* Creates an UUID column
*
* @return ColumnSchemaBuilder
* @see https://clickhouse.tech/docs/en/sql-reference/data-types/uuid/ For more information about UUID columns
*/
public function uuid(): ColumnSchemaBuilder
{
return $this->getDb()->getSchema()->createColumnSchemaBuilder(Schema::TYPE_UUID);
}
}

0 comments on commit 0ff87e3

Please sign in to comment.