Completed
Push — master ( fe927c...366a13 )
by Rasmus
15:55
created

PostgresDatabase::quoteTableName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 2
crap 2
1
<?php
2
3
namespace mindplay\sql\postgres;
4
5
use mindplay\sql\model\Database;
6
use mindplay\sql\model\DatabaseContainer;
7
use mindplay\sql\model\DatabaseContainerFactory;
8
use mindplay\sql\model\Driver;
9
use mindplay\sql\model\schema\Table;
10
use mindplay\sql\model\types\BoolType;
11
use mindplay\sql\model\types\FloatType;
12
use PDO;
13
14
class PostgresDatabase extends Database implements Driver
15
{
16 1
    protected function bootstrap(DatabaseContainerFactory $factory)
17
    {
18 1
        $factory->set(Driver::class, $this);
19
        
20 1
        $factory->register(BoolType::class, function () {
21 1
            return BoolType::get(true, false);
22 1
        });
23
        
24 1
        $factory->alias("scalar.boolean", BoolType::class);
25
26 1
        $factory->register("scalar.double", FloatType::class);
27 1
    }
28
29
    /**
30
     * @param PDO $pdo
31
     *
32
     * @return PostgresConnection
33
     */
34 1
    public function createConnection(PDO $pdo)
35
    {
36 1
        return $this->container->create(PostgresConnection::class, ['pdo' => $pdo]);
37
    }
38
39
    /**
40
     * @inheritdoc
41
     */
42 1
    public function quoteName($name)
43
    {
44 1
        return '"' . $name . '"';
45
    }
46
47
    /**
48
     * @inheritdoc
49
     */
50 1
    public function quoteTableName($schema, $table)
51
    {
52 1
        return $schema
53 1
            ? '"' . $schema . '"."' . $table . '"'
54 1
            : '"' . $table . '"';
55
    }
56
57
    /**
58
     * @param Table $from
59
     *
60
     * @return PostgresSelectQuery
61
     */
62
    public function select(Table $from)
63
    {
64
        return $this->container->create(PostgresSelectQuery::class, ['root' => $from]);
65
    }
66
    
67
    /**
68
     * @param Table $into
69
     *
70
     * @return PostgresInsertQuery
71
     */
72 1
    public function insert(Table $into)
73
    {
74 1
        return $this->container->create(PostgresInsertQuery::class, ['table' => $into]);
75
    }
76
77
    /**
78
     * @param Table $table
79
     *
80
     * @return PostgresUpdateQuery
81
     */
82 1
    public function update(Table $table)
83
    {
84 1
        return $this->container->create(PostgresUpdateQuery::class, ['table' => $table]);
85
    }
86
87
    /**
88
     * @param Table $table
89
     *
90
     * @return PostgresDeleteQuery
91
     */
92 1
    public function delete(Table $table)
93
    {
94 1
        return $this->container->create(PostgresDeleteQuery::class, ['table' => $table]);
95
    }
96
}
97