|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Mysql; |
|
6
|
|
|
|
|
7
|
|
|
use Yiisoft\Db\QueryBuilder\AbstractQueryBuilder; |
|
8
|
|
|
use Yiisoft\Db\Schema\ColumnSchemaBuilderInterface; |
|
9
|
|
|
use Yiisoft\Db\Schema\QuoterInterface; |
|
10
|
|
|
use Yiisoft\Db\Schema\SchemaInterface; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Implements the MySQL, MariaDb Server specific query builder. |
|
14
|
|
|
*/ |
|
15
|
|
|
final class QueryBuilder extends AbstractQueryBuilder |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @psalm-var string[] $typeMap Mapping from abstract column types (keys) to physical column types (values). |
|
19
|
|
|
*/ |
|
20
|
|
|
protected array $typeMap = [ |
|
21
|
|
|
SchemaInterface::TYPE_PK => 'int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY', |
|
22
|
|
|
SchemaInterface::TYPE_UPK => 'int(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY', |
|
23
|
|
|
SchemaInterface::TYPE_BIGPK => 'bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY', |
|
24
|
|
|
SchemaInterface::TYPE_UBIGPK => 'bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY', |
|
25
|
|
|
SchemaInterface::TYPE_CHAR => 'char(1)', |
|
26
|
|
|
SchemaInterface::TYPE_STRING => 'varchar(255)', |
|
27
|
|
|
SchemaInterface::TYPE_TEXT => 'text', |
|
28
|
|
|
SchemaInterface::TYPE_TINYINT => 'tinyint(3)', |
|
29
|
|
|
SchemaInterface::TYPE_SMALLINT => 'smallint(6)', |
|
30
|
|
|
SchemaInterface::TYPE_INTEGER => 'int(11)', |
|
31
|
|
|
SchemaInterface::TYPE_BIGINT => 'bigint(20)', |
|
32
|
|
|
SchemaInterface::TYPE_FLOAT => 'float', |
|
33
|
|
|
SchemaInterface::TYPE_DOUBLE => 'double', |
|
34
|
|
|
SchemaInterface::TYPE_DECIMAL => 'decimal(10,0)', |
|
35
|
|
|
SchemaInterface::TYPE_DATE => 'date', |
|
36
|
|
|
SchemaInterface::TYPE_BINARY => 'blob', |
|
37
|
|
|
SchemaInterface::TYPE_BOOLEAN => 'bit(1)', |
|
38
|
|
|
SchemaInterface::TYPE_MONEY => 'decimal(19,4)', |
|
39
|
|
|
SchemaInterface::TYPE_JSON => 'json', |
|
40
|
|
|
SchemaInterface::TYPE_DATETIME => 'datetime(0)', |
|
41
|
|
|
SchemaInterface::TYPE_TIMESTAMP => 'timestamp(0)', |
|
42
|
|
|
SchemaInterface::TYPE_TIME => 'time(0)', |
|
43
|
|
|
]; |
|
44
|
|
|
|
|
45
|
515 |
|
public function __construct( |
|
46
|
|
|
QuoterInterface $quoter, |
|
47
|
|
|
SchemaInterface $schema, |
|
48
|
|
|
) { |
|
49
|
515 |
|
$ddlBuilder = new DDLQueryBuilder($this, $quoter, $schema); |
|
50
|
515 |
|
$dmlBuilder = new DMLQueryBuilder($this, $quoter, $schema); |
|
51
|
515 |
|
$dqlBuilder = new DQLQueryBuilder($this, $quoter, $schema); |
|
52
|
515 |
|
parent::__construct($quoter, $schema, $ddlBuilder, $dmlBuilder, $dqlBuilder); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
48 |
|
public function getColumnType(ColumnSchemaBuilderInterface|string $type): string |
|
56
|
|
|
{ |
|
57
|
48 |
|
if ($type instanceof ColumnSchemaBuilder) { |
|
58
|
4 |
|
$type->setQuoter($this->quoter()); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
48 |
|
if ($type instanceof ColumnSchemaBuilderInterface && $type->getType() === SchemaInterface::TYPE_JSON) { |
|
62
|
2 |
|
$type->check('[[{name}]] is null or json_valid([[{name}]])'); |
|
63
|
2 |
|
$type = SchemaInterface::TYPE_JSON; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
48 |
|
return parent::getColumnType($type); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|