-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathUpdate.php
More file actions
132 lines (109 loc) · 2.29 KB
/
Update.php
File metadata and controls
132 lines (109 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
namespace Harp\Query;
use Harp\Query\Compiler;
use Harp\Query\SQL;
use Harp\Query\Arr;
/**
* @author Ivan Kerin <ikerin@gmail.com>
* @copyright (c) 2014 Clippings Ltd.
* @license http://spdx.org/licenses/BSD-3-Clause
*/
class Update extends AbstractWhere
{
/**
* @var SQL\Aliased[]|null
*/
protected $table;
/**
* @var SQL\Set[]|null
*/
protected $set;
/**
* @return SQL\Aliased[]|null
*/
public function getTable()
{
return $this->table;
}
/**
* @param SQL\Aliased[] $table
*/
public function setTable(array $table)
{
$this->table = $table;
return $this;
}
public function clearTable()
{
$this->table = null;
return $this;
}
/**
* @return SQL\Set[]|null
*/
public function getSet()
{
return $this->set;
}
/**
* @param SQL\Set[] $set
*/
public function setSet(array $set)
{
$this->set = $set;
return $this;
}
public function clearSet()
{
$this->set = null;
return $this;
}
/**
* @param string|SQL\SQL $table
* @param string $alias
* @return Update $this
*/
public function table($table, $alias = null)
{
$this->table []= new SQL\Aliased($table, $alias);
return $this;
}
/**
* @param array $values
* @return Update $this
*/
public function set(array $values)
{
foreach ($values as $column => $value) {
$this->set []= new SQL\Set($column, $value);
}
return $this;
}
/**
* @param array $values
* @param string $key
* @return Update $this
*/
public function setMultiple(array $values, $key = 'id')
{
$values = Arr::flipNested($values);
foreach ($values as $column => $changes) {
$this->set []= new SQL\SetMultiple($column, $changes, $key);
}
return $this;
}
/**
* @return string
*/
public function sql()
{
return Compiler\Update::render($this);
}
/**
* @return array
*/
public function getParameters()
{
return Compiler\Update::parameters($this);
}
}