|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Rougin\Windstorm\Eloquent; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Collection; |
|
6
|
|
|
use Rougin\Windstorm\QueryInterface; |
|
7
|
|
|
use Rougin\Windstorm\ResultInterface; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Result |
|
11
|
|
|
* |
|
12
|
|
|
* @package Windstorm |
|
13
|
|
|
* @author Rougin Gutib <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
class Result implements ResultInterface |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var integer |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $affected = 0; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var \Illuminate\Support\Collection |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $result; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Returns a number of affected rows. |
|
29
|
|
|
* |
|
30
|
|
|
* @return integer |
|
31
|
|
|
*/ |
|
32
|
9 |
|
public function affected() |
|
33
|
|
|
{ |
|
34
|
9 |
|
return $this->affected; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Returns a result from a query instance. |
|
39
|
|
|
* |
|
40
|
|
|
* @param \Rougin\Windstorm\QueryInterface $query |
|
41
|
|
|
* @return \Rougin\Windstorm\ResultInterface |
|
42
|
|
|
*/ |
|
43
|
15 |
|
public function execute(QueryInterface $query) |
|
44
|
|
|
{ |
|
45
|
15 |
|
$builder = $query->instance(); |
|
46
|
|
|
|
|
47
|
15 |
|
if ($query->type() === QueryInterface::TYPE_SELECT) |
|
48
|
10 |
|
{ |
|
49
|
6 |
|
$this->result = $builder->get(); |
|
50
|
|
|
|
|
51
|
6 |
|
return $this; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
9 |
|
$bindings = $query->bindings(); |
|
55
|
|
|
|
|
56
|
9 |
|
switch ($query->type()) |
|
57
|
|
|
{ |
|
58
|
9 |
|
case QueryInterface::TYPE_INSERT: |
|
59
|
3 |
|
$this->affected = $builder->insert($bindings); |
|
60
|
|
|
|
|
61
|
3 |
|
break; |
|
62
|
6 |
|
case QueryInterface::TYPE_UPDATE: |
|
63
|
3 |
|
$this->affected = $builder->update($bindings); |
|
64
|
|
|
|
|
65
|
3 |
|
break; |
|
66
|
3 |
|
case QueryInterface::TYPE_DELETE: |
|
67
|
3 |
|
$this->affected = $builder->delete($bindings); |
|
68
|
|
|
|
|
69
|
3 |
|
break; |
|
70
|
6 |
|
} |
|
71
|
|
|
|
|
72
|
9 |
|
return $this; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Returns the first row from result. |
|
77
|
|
|
* |
|
78
|
|
|
* @return mixed |
|
79
|
|
|
*/ |
|
80
|
3 |
|
public function first() |
|
81
|
|
|
{ |
|
82
|
3 |
|
return $this->result->first(); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Returns the last inserted ID. |
|
87
|
|
|
* |
|
88
|
|
|
* @return integer |
|
89
|
|
|
*/ |
|
90
|
|
|
public function inserted() |
|
91
|
|
|
{ |
|
92
|
|
|
return 0; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Returns the first row from result. |
|
97
|
|
|
* |
|
98
|
|
|
* @return mixed |
|
99
|
|
|
*/ |
|
100
|
3 |
|
public function items() |
|
101
|
|
|
{ |
|
102
|
3 |
|
return $this->result; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|