@@ 13-44 (lines=32) @@ | ||
10 | * @property string $table |
|
11 | * @property QueryInterface $query |
|
12 | */ |
|
13 | trait DeleteMethod |
|
14 | { |
|
15 | /** |
|
16 | * @return static |
|
17 | * |
|
18 | * @throws LogicException |
|
19 | */ |
|
20 | public function delete() |
|
21 | { |
|
22 | if (!isset($this->table)) { |
|
23 | throw new LogicException("delete() called before table()"); |
|
24 | } |
|
25 | ||
26 | $query = $this->factory()->newDelete(); |
|
27 | $query->from($this->table); |
|
28 | ||
29 | return $this->cloneWith("query", $query); |
|
30 | } |
|
31 | ||
32 | /** |
|
33 | * @return QueryFactory |
|
34 | */ |
|
35 | abstract protected function factory(); |
|
36 | ||
37 | /** |
|
38 | * @param string $key |
|
39 | * @param mixed $value |
|
40 | * |
|
41 | * @return static |
|
42 | */ |
|
43 | abstract protected function cloneWith($key, $value); |
|
44 | } |
|
45 |
@@ 13-47 (lines=35) @@ | ||
10 | * @property string $table |
|
11 | * @property QueryInterface $query |
|
12 | */ |
|
13 | trait InsertMethod |
|
14 | { |
|
15 | /** |
|
16 | * @param array $data |
|
17 | * |
|
18 | * @return static |
|
19 | * |
|
20 | * @throws LogicException |
|
21 | */ |
|
22 | public function insert(array $data) |
|
23 | { |
|
24 | if (!isset($this->table)) { |
|
25 | throw new LogicException("insert() called before table()"); |
|
26 | } |
|
27 | ||
28 | $query = $this->factory()->newInsert(); |
|
29 | $query->into($this->table); |
|
30 | $query->cols($data); |
|
31 | ||
32 | return $this->cloneWith("query", $query); |
|
33 | } |
|
34 | ||
35 | /** |
|
36 | * @return QueryFactory |
|
37 | */ |
|
38 | abstract protected function factory(); |
|
39 | ||
40 | /** |
|
41 | * @param string $key |
|
42 | * @param mixed $value |
|
43 | * |
|
44 | * @return static |
|
45 | */ |
|
46 | abstract protected function cloneWith($key, $value); |
|
47 | } |
|
48 |
@@ 13-47 (lines=35) @@ | ||
10 | * @property string $table |
|
11 | * @property QueryInterface $query |
|
12 | */ |
|
13 | trait UpdateMethod |
|
14 | { |
|
15 | /** |
|
16 | * @param array $data |
|
17 | * |
|
18 | * @return static |
|
19 | * |
|
20 | * @throws LogicException |
|
21 | */ |
|
22 | public function update(array $data) |
|
23 | { |
|
24 | if (!isset($this->table)) { |
|
25 | throw new LogicException("update() called before table()"); |
|
26 | } |
|
27 | ||
28 | $query = $this->factory()->newUpdate(); |
|
29 | $query->table($this->table); |
|
30 | $query->cols($data); |
|
31 | ||
32 | return $this->cloneWith("query", $query); |
|
33 | } |
|
34 | ||
35 | /** |
|
36 | * @return QueryFactory |
|
37 | */ |
|
38 | abstract protected function factory(); |
|
39 | ||
40 | /** |
|
41 | * @param string $key |
|
42 | * @param mixed $value |
|
43 | * |
|
44 | * @return static |
|
45 | */ |
|
46 | abstract protected function cloneWith($key, $value); |
|
47 | } |
|
48 |