Completed
Pull Request — master (#34)
by Rasmus
05:13
created

Returning::getIndexer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace mindplay\sql\model\components;
4
5
use mindplay\sql\model\schema\Column;
6
use mindplay\sql\model\schema\Table;
7
use mindplay\sql\model\schema\Type;
8
9
/**
10
 * This trait implements support for the `RETURNING` clause of Postgres `INSERT`, `UPDATE` and `DELETE` queries.
11
 */
12
trait Returning
13
{
14
    use Mappers;
15
16
    /**
17
     * @var ReturnVars
18
     */
19
    protected $return_vars;
20
    
21
    /**
22
     * Add all the Columns of a full Table to be selected and returned
23
     *
24
     * @param Table $table Table to select and return
25
     *
26
     * @return $this
27
     */
28
    public function returningTable(Table $table)
29
    {
30
        $this->return_vars->addTable($table);
31
32
        return $this;
33
    }
34
35
    /**
36
     * Add one or more Columns to select and return
37
     *
38
     * @param Column|Column[] $cols one or more Columns to select and return
39
     *
40
     * @return $this
41
     */
42 1
    public function returningColumns($cols)
43
    {
44 1
        $this->return_vars->addColumns($cols);
45
46 1
        return $this;
47
    }
48
49
    /**
50
     * Add an SQL expression to select and return
51
     *
52
     * @param string           $expr return expression
53
     * @param string|null      $name return variable name (optional, but usually required)
54
     * @param Type|string|null $type optional Type (or Type class-name)
55
     *
56
     * @return $this
57
     */
58
    public function returningValue($expr, $name = null, $type = null)
59
    {
60
        $this->return_vars->addValue($expr, $name, $type);
61
62
        return $this;
63
    }
64
65
    /**
66
     * @inheritdoc
67
     */
68 1
    public function getMappers()
69
    {
70 1
        return array_merge([$this->return_vars->createTypeMapper()], $this->mappers);
71
    }
72
73
    /**
74
     * @inheritdoc
75
     */
76
    public function getIndexer()
77
    {
78
        return $this->indexer;
79
    }
80
}
81