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