1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Pgsql; |
6
|
|
|
|
7
|
|
|
use Yiisoft\Db\QueryBuilder\QueryBuilder as AbstractQueryBuilder; |
8
|
|
|
use Yiisoft\Db\Schema\QuoterInterface; |
9
|
|
|
use Yiisoft\Db\Schema\Schema; |
|
|
|
|
10
|
|
|
use Yiisoft\Db\Schema\SchemaInterface; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* The class QueryBuilder is the query builder for PostgresSQL databases. |
14
|
|
|
*/ |
15
|
|
|
final class QueryBuilder extends AbstractQueryBuilder |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Defines a B-tree index method for {@see createIndex()}. |
19
|
|
|
*/ |
20
|
|
|
public const INDEX_B_TREE = 'btree'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Defines a hash index method for {@see createIndex()}. |
24
|
|
|
*/ |
25
|
|
|
public const INDEX_HASH = 'hash'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Defines a GiST index method for {@see createIndex()}. |
29
|
|
|
*/ |
30
|
|
|
public const INDEX_GIST = 'gist'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Defines a GIN index method for {@see createIndex()}. |
34
|
|
|
*/ |
35
|
|
|
public const INDEX_GIN = 'gin'; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Defines a BRIN index method for {@see createIndex()}. |
39
|
|
|
*/ |
40
|
|
|
public const INDEX_BRIN = 'brin'; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var array mapping from abstract column types (keys) to physical column types (values). |
44
|
|
|
* |
45
|
|
|
* @psalm-var string[] |
46
|
|
|
*/ |
47
|
|
|
protected array $typeMap = [ |
48
|
|
|
Schema::TYPE_PK => 'serial NOT NULL PRIMARY KEY', |
49
|
|
|
Schema::TYPE_UPK => 'serial NOT NULL PRIMARY KEY', |
50
|
|
|
Schema::TYPE_BIGPK => 'bigserial NOT NULL PRIMARY KEY', |
51
|
|
|
Schema::TYPE_UBIGPK => 'bigserial NOT NULL PRIMARY KEY', |
52
|
|
|
Schema::TYPE_CHAR => 'char(1)', |
53
|
|
|
Schema::TYPE_STRING => 'varchar(255)', |
54
|
|
|
Schema::TYPE_TEXT => 'text', |
55
|
|
|
Schema::TYPE_TINYINT => 'smallint', |
56
|
|
|
Schema::TYPE_SMALLINT => 'smallint', |
57
|
|
|
Schema::TYPE_INTEGER => 'integer', |
58
|
|
|
Schema::TYPE_BIGINT => 'bigint', |
59
|
|
|
Schema::TYPE_FLOAT => 'double precision', |
60
|
|
|
Schema::TYPE_DOUBLE => 'double precision', |
61
|
|
|
Schema::TYPE_DECIMAL => 'numeric(10,0)', |
62
|
|
|
Schema::TYPE_DATETIME => 'timestamp(0)', |
63
|
|
|
Schema::TYPE_TIMESTAMP => 'timestamp(0)', |
64
|
|
|
Schema::TYPE_TIME => 'time(0)', |
65
|
|
|
Schema::TYPE_DATE => 'date', |
66
|
|
|
Schema::TYPE_BINARY => 'bytea', |
67
|
|
|
Schema::TYPE_BOOLEAN => 'boolean', |
68
|
|
|
Schema::TYPE_MONEY => 'numeric(19,4)', |
69
|
|
|
Schema::TYPE_JSON => 'jsonb', |
70
|
|
|
]; |
71
|
|
|
private DDLQueryBuilder $ddlBuilder; |
72
|
|
|
private DMLQueryBuilder $dmlBuilder; |
73
|
|
|
private DQLQueryBuilder $dqlBuilder; |
74
|
|
|
|
75
|
419 |
|
public function __construct(QuoterInterface $quoter, SchemaInterface $schema) |
76
|
|
|
{ |
77
|
419 |
|
$this->ddlBuilder = new DDLQueryBuilder($this, $quoter, $schema); |
78
|
419 |
|
$this->dmlBuilder = new DMLQueryBuilder($this, $quoter, $schema); |
79
|
419 |
|
$this->dqlBuilder = new DQLQueryBuilder($this, $quoter, $schema); |
80
|
419 |
|
parent::__construct($quoter, $schema, $this->ddlBuilder, $this->dmlBuilder, $this->dqlBuilder); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: