1 | <?php |
||
26 | class Table implements \JsonSerializable, \IteratorAggregate |
||
27 | { |
||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | private $name = ''; |
||
32 | |||
33 | /** |
||
34 | * @var Database |
||
35 | */ |
||
36 | protected $database = null; |
||
37 | |||
38 | /** |
||
39 | * @param Database $database Parent DBAL database. |
||
40 | * @param string $name Table name without prefix. |
||
41 | */ |
||
42 | public function __construct(Database $database, string $name) |
||
47 | |||
48 | /** |
||
49 | * {@inheritdoc} |
||
50 | * |
||
51 | * @return Database |
||
52 | */ |
||
53 | public function getDatabase(): Database |
||
57 | |||
58 | /** |
||
59 | * {@inheritdoc} |
||
60 | * |
||
61 | * @return AbstractTable |
||
62 | */ |
||
63 | public function getSchema(): AbstractTable |
||
67 | |||
68 | /** |
||
69 | * {@inheritdoc} |
||
70 | */ |
||
71 | public function getName(): string |
||
75 | |||
76 | /** |
||
77 | * Real table name, will include database prefix. |
||
78 | * |
||
79 | * @return string |
||
80 | */ |
||
81 | public function fullName(): string |
||
85 | |||
86 | /** |
||
87 | * Check if table exists. |
||
88 | * |
||
89 | * @return bool |
||
90 | */ |
||
91 | public function exists(): bool |
||
95 | |||
96 | /** |
||
97 | * {@inheritdoc} |
||
98 | */ |
||
99 | public function truncateData() |
||
103 | |||
104 | /** |
||
105 | * Get list of column names associated with their abstract types. |
||
106 | * |
||
107 | * @return array |
||
108 | */ |
||
109 | public function getColumns(): array |
||
118 | |||
119 | /** |
||
120 | * Insert one fieldset into table and return last inserted id. |
||
121 | * |
||
122 | * Example: |
||
123 | * $table->insertOne(["name" => "Wolfy-J", "balance" => 10]); |
||
124 | * |
||
125 | * @param array $rowset |
||
126 | * |
||
127 | * @return int |
||
128 | * |
||
129 | * @throws BuilderException |
||
130 | */ |
||
131 | public function insertOne(array $rowset = []): int |
||
135 | |||
136 | /** |
||
137 | * Perform batch insert into table, every rowset should have identical amount of values matched |
||
138 | * with column names provided in first argument. Method will return lastInsertID on success. |
||
139 | * |
||
140 | * Example: |
||
141 | * $table->insertMultiple(["name", "balance"], array(["Bob", 10], ["Jack", 20])) |
||
142 | * |
||
143 | * @param array $columns Array of columns. |
||
144 | * @param array $rowsets Array of rowsets. |
||
145 | */ |
||
146 | public function insertMultiple(array $columns = [], array $rowsets = []) |
||
151 | |||
152 | /** |
||
153 | * Get SelectQuery builder with pre-populated from tables. |
||
154 | * |
||
155 | * @param string $columns |
||
156 | * |
||
157 | * @return SelectQuery |
||
158 | */ |
||
159 | public function select($columns = '*'): SelectQuery |
||
163 | |||
164 | /** |
||
165 | * Get DeleteQuery builder with pre-populated table name. This is NOT table delete method, use |
||
166 | * schema()->drop() for this purposes. If you want to remove all records from table use |
||
167 | * Table->truncate() method. Call ->run() to perform query. |
||
168 | * |
||
169 | * @param array $where Initial set of where rules specified as array. |
||
170 | * |
||
171 | * @return DeleteQuery |
||
172 | */ |
||
173 | public function delete(array $where = []): DeleteQuery |
||
177 | |||
178 | /** |
||
179 | * Get UpdateQuery builder with pre-populated table name and set of columns to update. Columns |
||
180 | * can be scalar values, Parameter objects or even SQLFragments. Call ->run() to perform query. |
||
181 | * |
||
182 | * @param array $values Initial set of columns associated with values. |
||
183 | * @param array $where Initial set of where rules specified as array. |
||
184 | * |
||
185 | * @return UpdateQuery |
||
186 | */ |
||
187 | public function update(array $values = [], array $where = []): UpdateQuery |
||
191 | |||
192 | /** |
||
193 | * Count number of records in table. |
||
194 | * |
||
195 | * @return int |
||
196 | */ |
||
197 | public function count(): int |
||
201 | |||
202 | /** |
||
203 | * Retrieve an external iterator, SelectBuilder will return PDOResult as iterator. |
||
204 | * |
||
205 | * @link http://php.net/manual/en/iteratoraggregate.getiterator.php |
||
206 | * |
||
207 | * @return SelectQuery |
||
208 | */ |
||
209 | public function getIterator(): SelectQuery |
||
213 | |||
214 | /** |
||
215 | * A simple alias for table query without condition (returns array of rows). |
||
216 | * |
||
217 | * @return array |
||
218 | */ |
||
219 | public function fetchAll(): array |
||
223 | |||
224 | /** |
||
225 | * {@inheritdoc} |
||
226 | */ |
||
227 | public function jsonSerialize() |
||
231 | |||
232 | /** |
||
233 | * Bypass call to SelectQuery builder. |
||
234 | * |
||
235 | * @param string $method |
||
236 | * @param array $arguments |
||
237 | * |
||
238 | * @return SelectQuery|mixed |
||
239 | */ |
||
240 | public function __call($method, array $arguments) |
||
244 | } |
||
245 |