-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
235 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Db\Pgsql\Column; | ||
|
||
use Yiisoft\Db\Constant\ColumnType; | ||
use Yiisoft\Db\Schema\Column\ColumnSchemaInterface; | ||
|
||
final class ColumnBuilder extends \Yiisoft\Db\Schema\Column\ColumnBuilder | ||
{ | ||
public static function boolean(): ColumnSchemaInterface | ||
{ | ||
return new BooleanColumnSchema(ColumnType::BOOLEAN); | ||
} | ||
|
||
public static function bit(int|null $size = null): ColumnSchemaInterface | ||
{ | ||
return (new BitColumnSchema(ColumnType::BIT)) | ||
->size($size); | ||
} | ||
|
||
public static function tinyint(int|null $size = null): ColumnSchemaInterface | ||
{ | ||
return (new IntegerColumnSchema(ColumnType::TINYINT)) | ||
->size($size); | ||
} | ||
|
||
public static function smallint(int|null $size = null): ColumnSchemaInterface | ||
{ | ||
return (new IntegerColumnSchema(ColumnType::SMALLINT)) | ||
->size($size); | ||
} | ||
|
||
public static function integer(int|null $size = null): ColumnSchemaInterface | ||
{ | ||
return (new IntegerColumnSchema(ColumnType::INTEGER)) | ||
->size($size); | ||
} | ||
|
||
public static function bigint(int|null $size = null): ColumnSchemaInterface | ||
{ | ||
return (new IntegerColumnSchema(ColumnType::BIGINT)) | ||
->size($size); | ||
} | ||
|
||
public static function binary(int|null $size = null): ColumnSchemaInterface | ||
{ | ||
return (new BinaryColumnSchema(ColumnType::BINARY)) | ||
->size($size); | ||
} | ||
|
||
public static function array(ColumnSchemaInterface|null $column = null): ColumnSchemaInterface | ||
{ | ||
return (new ArrayColumnSchema(ColumnType::ARRAY)) | ||
->column($column); | ||
} | ||
|
||
/** | ||
* @param string|null $dbType The DB type of the column. | ||
* @param ColumnSchemaInterface[] $columns The columns (name -> instance) that the structured column should contain. | ||
* | ||
* @psalm-param array<string, ColumnSchemaInterface> $columns | ||
*/ | ||
public static function structured(string|null $dbType = null, array $columns = []): ColumnSchemaInterface | ||
{ | ||
return (new StructuredColumnSchema(ColumnType::STRUCTURED)) | ||
->dbType($dbType) | ||
->columns($columns); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Db\Pgsql\Tests; | ||
|
||
use Yiisoft\Db\Pgsql\Column\ColumnBuilder; | ||
use Yiisoft\Db\Pgsql\Tests\Support\TestTrait; | ||
use Yiisoft\Db\Tests\AbstractColumnBuilderTest; | ||
|
||
/** | ||
* @group pgsql | ||
*/ | ||
final class ColumnBuilderTest extends AbstractColumnBuilderTest | ||
{ | ||
use TestTrait; | ||
|
||
public function getColumnBuilderClass(): string | ||
{ | ||
return ColumnBuilder::class; | ||
} | ||
|
||
/** | ||
* @dataProvider \Yiisoft\Db\Pgsql\Tests\Provider\ColumnBuilderProvider::buildingMethods | ||
*/ | ||
public function testBuildingMethods( | ||
string $buildingMethod, | ||
array $args, | ||
string $expectedInstanceOf, | ||
string $expectedType, | ||
array $expectedMethodResults = [], | ||
): void { | ||
parent::testBuildingMethods($buildingMethod, $args, $expectedInstanceOf, $expectedType, $expectedMethodResults); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Db\Pgsql\Tests\Provider; | ||
|
||
use Yiisoft\Db\Constant\ColumnType; | ||
use Yiisoft\Db\Pgsql\Column\ArrayColumnSchema; | ||
use Yiisoft\Db\Pgsql\Column\BinaryColumnSchema; | ||
use Yiisoft\Db\Pgsql\Column\BitColumnSchema; | ||
use Yiisoft\Db\Pgsql\Column\BooleanColumnSchema; | ||
use Yiisoft\Db\Pgsql\Column\ColumnBuilder; | ||
use Yiisoft\Db\Pgsql\Column\IntegerColumnSchema; | ||
use Yiisoft\Db\Pgsql\Column\StructuredColumnSchema; | ||
use Yiisoft\Db\Schema\Column\DoubleColumnSchema; | ||
use Yiisoft\Db\Schema\Column\StringColumnSchema; | ||
|
||
class ColumnBuilderProvider extends \Yiisoft\Db\Tests\Provider\ColumnBuilderProvider | ||
{ | ||
public static function buildingMethods(): array | ||
{ | ||
return [ | ||
// building method, args, expected instance of, expected type, expected column method results | ||
...parent::buildingMethods(), | ||
['primaryKey', [], IntegerColumnSchema::class, ColumnType::INTEGER, ['isPrimaryKey' => true, 'isAutoIncrement' => true]], | ||
['primaryKey', [false], IntegerColumnSchema::class, ColumnType::INTEGER, ['isPrimaryKey' => true, 'isAutoIncrement' => false]], | ||
['smallPrimaryKey', [], IntegerColumnSchema::class, ColumnType::SMALLINT, ['isPrimaryKey' => true, 'isAutoIncrement' => true]], | ||
['smallPrimaryKey', [false], IntegerColumnSchema::class, ColumnType::SMALLINT, ['isPrimaryKey' => true, 'isAutoIncrement' => false]], | ||
['bigPrimaryKey', [], IntegerColumnSchema::class, ColumnType::BIGINT, ['isPrimaryKey' => true, 'isAutoIncrement' => true]], | ||
['bigPrimaryKey', [false], IntegerColumnSchema::class, ColumnType::BIGINT, ['isPrimaryKey' => true, 'isAutoIncrement' => false]], | ||
['boolean', [], BooleanColumnSchema::class, ColumnType::BOOLEAN], | ||
['bit', [], BitColumnSchema::class, ColumnType::BIT], | ||
['bit', [1], BitColumnSchema::class, ColumnType::BIT, ['getSize' => 1]], | ||
['tinyint', [], IntegerColumnSchema::class, ColumnType::TINYINT], | ||
['tinyint', [1], IntegerColumnSchema::class, ColumnType::TINYINT, ['getSize' => 1]], | ||
['smallint', [], IntegerColumnSchema::class, ColumnType::SMALLINT], | ||
['smallint', [1], IntegerColumnSchema::class, ColumnType::SMALLINT, ['getSize' => 1]], | ||
['integer', [], IntegerColumnSchema::class, ColumnType::INTEGER], | ||
['integer', [1], IntegerColumnSchema::class, ColumnType::INTEGER, ['getSize' => 1]], | ||
['bigint', [], IntegerColumnSchema::class, ColumnType::BIGINT], | ||
['bigint', [1], IntegerColumnSchema::class, ColumnType::BIGINT, ['getSize' => 1]], | ||
['float', [], DoubleColumnSchema::class, ColumnType::FLOAT], | ||
['float', [8], DoubleColumnSchema::class, ColumnType::FLOAT, ['getSize' => 8]], | ||
['float', [8, 2], DoubleColumnSchema::class, ColumnType::FLOAT, ['getSize' => 8, 'getScale' => 2]], | ||
['double', [], DoubleColumnSchema::class, ColumnType::DOUBLE], | ||
['double', [8], DoubleColumnSchema::class, ColumnType::DOUBLE, ['getSize' => 8]], | ||
['double', [8, 2], DoubleColumnSchema::class, ColumnType::DOUBLE, ['getSize' => 8, 'getScale' => 2]], | ||
['decimal', [], DoubleColumnSchema::class, ColumnType::DECIMAL, ['getSize' => 10, 'getScale' => 0]], | ||
['decimal', [8], DoubleColumnSchema::class, ColumnType::DECIMAL, ['getSize' => 8, 'getScale' => 0]], | ||
['decimal', [8, 2], DoubleColumnSchema::class, ColumnType::DECIMAL, ['getSize' => 8, 'getScale' => 2]], | ||
['money', [], DoubleColumnSchema::class, ColumnType::MONEY, ['getSize' => 19, 'getScale' => 4]], | ||
['money', [8], DoubleColumnSchema::class, ColumnType::MONEY, ['getSize' => 8, 'getScale' => 4]], | ||
['money', [8, 2], DoubleColumnSchema::class, ColumnType::MONEY, ['getSize' => 8, 'getScale' => 2]], | ||
['binary', [], BinaryColumnSchema::class, ColumnType::BINARY], | ||
['binary', [8], BinaryColumnSchema::class, ColumnType::BINARY, ['getSize' => 8]], | ||
['array', [], ArrayColumnSchema::class, ColumnType::ARRAY], | ||
['array', [$column = new StringColumnSchema()], ArrayColumnSchema::class, ColumnType::ARRAY, ['getColumn' => $column]], | ||
['structured', [], StructuredColumnSchema::class, ColumnType::STRUCTURED], | ||
['structured', ['money_currency'], StructuredColumnSchema::class, ColumnType::STRUCTURED, ['getDbType' => 'money_currency']], | ||
[ | ||
'structured', | ||
[ | ||
'money_currency', | ||
$columns = ['value' => ColumnBuilder::money(), 'currency' => ColumnBuilder::string(3)], | ||
], | ||
StructuredColumnSchema::class, | ||
ColumnType::STRUCTURED, | ||
['getDbType' => 'money_currency', 'getColumns' => $columns], | ||
], | ||
]; | ||
} | ||
} |
Oops, something went wrong.