Skip to content

Commit 0ff87e3

Browse files
authored
Merge pull request #28 from zkelo/shortcuts
Shortcut for UUID data type
2 parents 4d6a942 + 8fb6fff commit 0ff87e3

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

Migration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515
class Migration extends \yii\db\Migration
1616
{
17+
use SchemaBuilderTrait;
1718

1819
public $db = 'clickhouse';
1920

Schema.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
*/
1515
class Schema extends \yii\db\mysql\Schema
1616
{
17+
/**
18+
* UUID columnd data type
19+
*/
20+
const TYPE_UUID = 'UUID';
21+
1722
public $columnSchemaClass = 'bashkarev\clickhouse\ColumnSchema';
1823

1924
/**

SchemaBuilderTrait.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace bashkarev\clickhouse;
4+
5+
/**
6+
* Schema builder trait
7+
*
8+
* Provides some shortcuts for specific clickhouse data types and etc.
9+
*
10+
* @see \yii\db\SchemaBuilderTrait For better understanding about logic of this trait
11+
* @method \yii\db\Connection getDb()
12+
*/
13+
trait SchemaBuilderTrait
14+
{
15+
/**
16+
* Creates an UUID column
17+
*
18+
* @return ColumnSchemaBuilder
19+
* @see https://clickhouse.tech/docs/en/sql-reference/data-types/uuid/ For more information about UUID columns
20+
*/
21+
public function uuid(): ColumnSchemaBuilder
22+
{
23+
return $this->getDb()->getSchema()->createColumnSchemaBuilder(Schema::TYPE_UUID);
24+
}
25+
}

0 commit comments

Comments
 (0)