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

MySQLDatabase::insert()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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