Passed
Push — main ( 08974e...644444 )
by Thierry
02:28
created

QueryTrait::getInsertQuery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 6
rs 10
1
<?php
2
3
namespace Lagdo\DbAdmin\Db\Driver\Facades;
4
5
/**
6
 * Facade to table query functions
7
 */
8
trait QueryTrait
9
{
10
    use AbstractTrait;
11
12
    /**
13
     * Get the facade
14
     *
15
     * @return QueryFacade
16
     */
17
    protected function queryFacade(): QueryFacade
18
    {
19
        return $this->di()->g(QueryFacade::class);
20
    }
21
22
    /**
23
     * Get data for insert on a table
24
     *
25
     * @param string $table         The table name
26
     * @param array  $queryOptions  The query options
27
     *
28
     * @return array
29
     */
30
    public function getInsertData(string $table, array $queryOptions = []): array
31
    {
32
        $this->connectToSchema();
33
        $this->utils->input->table = $table;
34
        $this->utils->input->values = $queryOptions;
35
        return $this->queryFacade()->getInsertData($table, $queryOptions);
36
    }
37
38
    /**
39
     * Build the SQL query to insert a new item in a table
40
     *
41
     * @param string $table         The table name
42
     * @param array  $queryOptions  The query options
43
     * @param array  $values        The updated values
44
     *
45
     * @return array
46
     */
47
    public function getInsertQuery(string $table, array $queryOptions, array $values): array
48
    {
49
        $this->connectToSchema();
50
        $this->utils->input->table = $table;
51
        $this->utils->input->values = $values;
52
        return $this->queryFacade()->getInsertQuery($table, $queryOptions, $values);
53
    }
54
55
    /**
56
     * Insert a new item in a table
57
     *
58
     * @param string $table         The table name
59
     * @param array  $queryOptions  The query options
60
     * @param array  $values        The updated values
61
     *
62
     * @return array
63
     */
64
    public function insertItem(string $table, array $queryOptions, array $values): array
65
    {
66
        $this->connectToSchema();
67
        $this->utils->input->table = $table;
68
        $this->utils->input->values = $values;
69
        return $this->queryFacade()->insertItem($table, $queryOptions, $values);
70
    }
71
72
    /**
73
     * Get data for update/delete in a table
74
     *
75
     * @param string $table         The table name
76
     * @param array  $queryOptions  The query options
77
     *
78
     * @return array
79
     */
80
    public function getUpdateData(string $table, array $queryOptions = []): array
81
    {
82
        $this->connectToSchema();
83
        $this->utils->input->table = $table;
84
        $this->utils->input->values = $queryOptions;
85
        return $this->queryFacade()->getUpdateData($table, $queryOptions);
86
    }
87
88
    /**
89
     * Build the SQL query to update one or more items in a table
90
     *
91
     * @param string $table         The table name
92
     * @param array  $queryOptions  The query options
93
     * @param array  $values        The updated values
94
     *
95
     * @return array
96
     */
97
    public function getUpdateQuery(string $table, array $queryOptions, array $values): array
98
    {
99
        $this->connectToSchema();
100
        $this->utils->input->table = $table;
101
        $this->utils->input->values = $values;
102
        return $this->queryFacade()->getUpdateQuery($table, $queryOptions, $values);
103
    }
104
105
    /**
106
     * Update one or more items in a table
107
     *
108
     * @param string $table         The table name
109
     * @param array  $queryOptions  The query options
110
     * @param array  $values        The updated values
111
     *
112
     * @return array
113
     */
114
    public function updateItem(string $table, array $queryOptions, array $values): array
115
    {
116
        $this->connectToSchema();
117
        $this->utils->input->table = $table;
118
        $this->utils->input->values = $values;
119
        return $this->queryFacade()->updateItem($table, $queryOptions, $values);
120
    }
121
122
    /**
123
     * Build the SQL query to delete one or more items in a table
124
     *
125
     * @param string $table         The table name
126
     * @param array  $queryOptions  The query options
127
     *
128
     * @return array
129
     */
130
    public function getDeleteQuery(string $table, array $queryOptions): array
131
    {
132
        $this->connectToSchema();
133
        $this->utils->input->table = $table;
134
        $this->utils->input->values = $queryOptions;
135
        return $this->queryFacade()->getDeleteQuery($table, $queryOptions);
136
    }
137
138
    /**
139
     * Delete one or more items in a table
140
     *
141
     * @param string $table         The table name
142
     * @param array  $queryOptions  The query options
143
     *
144
     * @return array
145
     */
146
    public function deleteItem(string $table, array $queryOptions): array
147
    {
148
        $this->connectToSchema();
149
        $this->utils->input->table = $table;
150
        $this->utils->input->values = $queryOptions;
151
        return $this->queryFacade()->deleteItem($table, $queryOptions);
152
    }
153
}
154