Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/mutation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ jobs:

- name: Run infection.
run: |
vendor/bin/roave-infection-static-analysis-plugin --threads=2 --ignore-msi-with-no-mutations --only-covered
vendor/bin/roave-infection-static-analysis-plugin --threads=2 --ignore-msi-with-no-mutations
env:
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
- Enh #387: Refactor `DMLQueryBuilder::upsert()` method (@Tigrov)
- Chg #391: Update expression namespaces according to changes in `yiisoft/db` package (@Tigrov)
- Chg #402: Throw exception on "unsigned" column usage (@vjik)
- Chg #405: Add `ColumnDefinitionParser` class (@vjik)

## 1.2.0 March 21, 2024

Expand Down
34 changes: 34 additions & 0 deletions src/Column/ColumnDefinitionParser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Db\Sqlite\Column;

use Yiisoft\Db\Syntax\AbstractColumnDefinitionParser;

final class ColumnDefinitionParser extends AbstractColumnDefinitionParser
{
protected function parseTypeParams(string $type, string $params): array
{
return match ($type) {
'bit',
'char',
'datetime',
'datetimetz',
'decimal',
'double',
'float',
'int',
'numeric',
'real',
'smallint',
'string',
'time',
'timestamp',
'timetz',
'tinyint',
'varchar' => $this->parseSizeInfo($params),
default => [],
};
Comment on lines +13 to +32
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's right to limit the number of possible types for parsing. What about integer, bigint, varbit, character, etc. Sqlite supports various type names.

}
}
6 changes: 6 additions & 0 deletions src/Column/ColumnFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Yiisoft\Db\Constant\ColumnType;
use Yiisoft\Db\Schema\Column\AbstractColumnFactory;
use Yiisoft\Db\Schema\Column\ColumnInterface;
use Yiisoft\Db\Syntax\ColumnDefinitionParserInterface;

use function str_replace;
use function substr;
Expand Down Expand Up @@ -85,4 +86,9 @@ protected function normalizeNotNullDefaultValue(string $defaultValue, ColumnInte

return parent::normalizeNotNullDefaultValue($defaultValue, $column);
}

protected function columnDefinitionParser(): ColumnDefinitionParserInterface
{
return new ColumnDefinitionParser();
}
}
20 changes: 20 additions & 0 deletions tests/ColumnDefinitionParserTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Db\Sqlite\Tests;

use Yiisoft\Db\Sqlite\Column\ColumnDefinitionParser;
use Yiisoft\Db\Syntax\ColumnDefinitionParserInterface;
use Yiisoft\Db\Tests\Common\CommonColumnDefinitionParserTest;

/**
* @group sqlite
*/
final class ColumnDefinitionParserTest extends CommonColumnDefinitionParserTest
{
protected function createColumnDefinitionParser(): ColumnDefinitionParserInterface
{
return new ColumnDefinitionParser();
}
}
Loading