1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Quantum PHP Framework |
5
|
|
|
* |
6
|
|
|
* An open source software development framework for PHP |
7
|
|
|
* |
8
|
|
|
* @package Quantum |
9
|
|
|
* @author Arman Ag. <[email protected]> |
10
|
|
|
* @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) |
11
|
|
|
* @link http://quantum.softberg.org/ |
12
|
|
|
* @since 2.6.0 |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Quantum\Libraries\Database\Sleekdb\Statements; |
16
|
|
|
|
17
|
|
|
use Quantum\Libraries\Database\DbalInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Trait Result |
21
|
|
|
* @package Quantum\Libraries\Database\Sleekdb\Statements |
22
|
|
|
*/ |
23
|
|
|
trait Result |
24
|
|
|
{ |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @inheritDoc |
28
|
|
|
* @throws \Quantum\Exceptions\DatabaseException |
29
|
|
|
* @throws \SleekDB\Exceptions\IOException |
30
|
|
|
* @throws \SleekDB\Exceptions\InvalidArgumentException |
31
|
|
|
* @throws \SleekDB\Exceptions\InvalidConfigurationException |
32
|
|
|
*/ |
33
|
|
|
public function get() |
34
|
|
|
{ |
35
|
|
|
return $this->getBuilder()->getQuery()->fetch(); |
|
|
|
|
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @inheritDoc |
40
|
|
|
* @throws \Quantum\Exceptions\DatabaseException |
41
|
|
|
* @throws \SleekDB\Exceptions\IOException |
42
|
|
|
* @throws \SleekDB\Exceptions\InvalidArgumentException |
43
|
|
|
* @throws \SleekDB\Exceptions\InvalidConfigurationException |
44
|
|
|
*/ |
45
|
|
|
public function findOne(int $id): DbalInterface |
46
|
|
|
{ |
47
|
|
|
$result = $this->getOrmModel()->findById($id); |
|
|
|
|
48
|
|
|
|
49
|
|
|
$this->data = $result; |
|
|
|
|
50
|
|
|
$this->modifiedFields = $result; |
|
|
|
|
51
|
|
|
|
52
|
|
|
return $this; |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @inheritDoc |
57
|
|
|
* @throws \Quantum\Exceptions\DatabaseException |
58
|
|
|
* @throws \SleekDB\Exceptions\IOException |
59
|
|
|
* @throws \SleekDB\Exceptions\InvalidArgumentException |
60
|
|
|
* @throws \SleekDB\Exceptions\InvalidConfigurationException |
61
|
|
|
*/ |
62
|
|
|
public function findOneBy(string $column, $value): DbalInterface |
63
|
|
|
{ |
64
|
|
|
$result = $this->getOrmModel()->findOneBy([$column, '=', $value]); |
65
|
|
|
|
66
|
|
|
$this->data = $result; |
|
|
|
|
67
|
|
|
$this->modifiedFields = $result; |
|
|
|
|
68
|
|
|
|
69
|
|
|
return $this; |
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @inheritDoc |
74
|
|
|
* @throws \Quantum\Exceptions\DatabaseException |
75
|
|
|
* @throws \SleekDB\Exceptions\IOException |
76
|
|
|
* @throws \SleekDB\Exceptions\InvalidArgumentException |
77
|
|
|
* @throws \SleekDB\Exceptions\InvalidConfigurationException |
78
|
|
|
*/ |
79
|
|
|
public function first(): DbalInterface |
80
|
|
|
{ |
81
|
|
|
$result = $this->getBuilder()->getQuery()->first(); |
82
|
|
|
|
83
|
|
|
$this->data = $result; |
|
|
|
|
84
|
|
|
$this->modifiedFields = $result; |
|
|
|
|
85
|
|
|
|
86
|
|
|
return $this; |
|
|
|
|
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @inheritDoc |
91
|
|
|
* @throws \Quantum\Exceptions\DatabaseException |
92
|
|
|
* @throws \SleekDB\Exceptions\IOException |
93
|
|
|
* @throws \SleekDB\Exceptions\InvalidArgumentException |
94
|
|
|
* @throws \SleekDB\Exceptions\InvalidConfigurationException |
95
|
|
|
*/ |
96
|
|
|
public function count(): int |
97
|
|
|
{ |
98
|
|
|
return count($this->getBuilder()->getQuery()->fetch()); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @inheritDoc |
103
|
|
|
*/ |
104
|
|
|
public function asArray(): array |
105
|
|
|
{ |
106
|
|
|
return $this->data; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
} |