|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Lagdo\DbAdmin\Db\Traits; |
|
4
|
|
|
|
|
5
|
|
|
use Lagdo\DbAdmin\Db\Facades\SelectFacade; |
|
6
|
|
|
use Lagdo\DbAdmin\Db\Facades\Select\SelectEntity; |
|
7
|
|
|
use Exception; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Facade to table select functions |
|
11
|
|
|
*/ |
|
12
|
|
|
trait SelectTrait |
|
13
|
|
|
{ |
|
14
|
|
|
use AbstractTrait; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Get the facade |
|
18
|
|
|
* |
|
19
|
|
|
* @return SelectFacade |
|
20
|
|
|
*/ |
|
21
|
|
|
protected function selectFacade(): SelectFacade |
|
22
|
|
|
{ |
|
23
|
|
|
return $this->di()->g(SelectFacade::class); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Get required data for create/update on tables |
|
28
|
|
|
* |
|
29
|
|
|
* @param string $table The table name |
|
30
|
|
|
* @param array $queryOptions The query options |
|
31
|
|
|
* |
|
32
|
|
|
* @return SelectEntity |
|
33
|
|
|
* @throws Exception |
|
34
|
|
|
*/ |
|
35
|
|
|
public function getSelectData(string $table, array $queryOptions = []): SelectEntity |
|
36
|
|
|
{ |
|
37
|
|
|
$this->connectToSchema(); |
|
38
|
|
|
$this->utils->input->table = $table; |
|
39
|
|
|
$this->utils->input->values = $queryOptions; |
|
40
|
|
|
return $this->selectFacade()->getSelectData($table, $queryOptions); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Get required data for create/update on tables |
|
45
|
|
|
* |
|
46
|
|
|
* @param string $table The table name |
|
47
|
|
|
* @param array $queryOptions The query options |
|
48
|
|
|
* |
|
49
|
|
|
* @return int |
|
50
|
|
|
* @throws Exception |
|
51
|
|
|
*/ |
|
52
|
|
|
public function countSelect(string $table, array $queryOptions = []): int |
|
53
|
|
|
{ |
|
54
|
|
|
$this->connectToSchema(); |
|
55
|
|
|
$this->utils->input->table = $table; |
|
56
|
|
|
$this->utils->input->values = $queryOptions; |
|
57
|
|
|
return $this->selectFacade()->countSelect($table, $queryOptions); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Get required data for create/update on tables |
|
62
|
|
|
* |
|
63
|
|
|
* @param string $table The table name |
|
64
|
|
|
* @param array $queryOptions The query options |
|
65
|
|
|
* |
|
66
|
|
|
* @return array |
|
67
|
|
|
* @throws Exception |
|
68
|
|
|
*/ |
|
69
|
|
|
public function execSelect(string $table, array $queryOptions = []): array |
|
70
|
|
|
{ |
|
71
|
|
|
$this->connectToSchema(); |
|
72
|
|
|
$this->utils->input->table = $table; |
|
73
|
|
|
$this->utils->input->values = $queryOptions; |
|
74
|
|
|
return $this->selectFacade()->execSelect($table, $queryOptions); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|