Skip to content

Commit ac01291

Browse files
committed
was realized condition and join methods in select class
1 parent 148d9c5 commit ac01291

File tree

1 file changed

+167
-0
lines changed

1 file changed

+167
-0
lines changed

src/sql/Select.php

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,171 @@ public function where(string $condition)
9797
return $this;
9898
}
9999

100+
/**
101+
* This is equivalent of ORDER BY statement in SQL
102+
*
103+
* Pass our SQL statement into sql array and
104+
* return references on this object
105+
*
106+
* @param string $column
107+
* @param string $sortOrder
108+
*
109+
* @return \Manipulator\SQL\Select
110+
*/
111+
public function orderBy(string $column, string $sortOrder)
112+
{
113+
$this->sql[] = " ORDER BY {$column} {$sortOrder}";
114+
return $this;
115+
}
116+
117+
/**
118+
* This is equivalent of DISTINCT sorter in SQL
119+
*
120+
* Pass SQL statement into sql array and return
121+
* reference on this object
122+
*
123+
* @param string $columns
124+
*
125+
* @return \Manipulator\SQL\Select
126+
*/
127+
public function distinct(string $columns)
128+
{
129+
$this->sql[] = "SELECT DISTINCT {$columns} FROM {$this->table}";
130+
return $this;
131+
}
132+
133+
/**
134+
* This is equivalent of LIMIT SQL statement
135+
*
136+
* Insert into sql array your SQL statement
137+
* and return reference on this object
138+
*
139+
* @param string $quantity
140+
*
141+
* @return \Manipulator\SQL\Select
142+
*/
143+
public function limit(string $quantity)
144+
{
145+
$this->sql[] = " LIMIT {$quantity}";
146+
return $this;
147+
}
148+
149+
/**
150+
* This is equivalent of AND SQL statement
151+
*
152+
* Can be used with WHERE, BETWEEN and etc... statements
153+
*
154+
* @param string $condition
155+
*
156+
* @return \Manipulator\SQL\Select
157+
*/
158+
public function and(string $condition)
159+
{
160+
$this->sql[] = " AND {$condition}";
161+
return $this;
162+
}
163+
164+
/**
165+
* This is equivalent of OR SQL statement
166+
*
167+
* Can be used with another SQL statements
168+
* like WHERE and etc
169+
*
170+
* @param string $condition
171+
*
172+
* @return \Manipulator\SQL\Select
173+
*/
174+
public function or(string $condition)
175+
{
176+
$this->sql[] = " OR {$condition}";
177+
return $this;
178+
}
179+
180+
/**
181+
* This is equivalent of BETWEEN SQL statement
182+
*
183+
* Usually its use when you need to get average value
184+
*
185+
* @param string $column
186+
* @param int $lowItem
187+
* @param int $highItem
188+
*
189+
* @return \Manipualator\SQL\Select
190+
*/
191+
public function between(string $column, int $lowItem, int $highItem)
192+
{
193+
$this->sql[] = " WHERE {$column} BETWEEN {$lowItem} AND {$highItem}";
194+
return $this;
195+
}
196+
197+
/**
198+
* This is equivalent of NOT SQL statement
199+
*
200+
* Can be used with IN SQL statement
201+
*
202+
* @return \Manipulator\SQL\Select
203+
*/
204+
public function not()
205+
{
206+
$this->sql[] = " NOT";
207+
return $this;
208+
}
209+
210+
/**
211+
* This is equivalent of IN SQL statement
212+
*
213+
* @param string $condition
214+
*
215+
* @return \Manipualtor\SQL\Select
216+
*/
217+
public function in(string $condition)
218+
{
219+
$this->sql[] = " IN ('{$condition}')";
220+
return $this;
221+
}
222+
223+
/**
224+
* Equivalent of INNER JOIN SQL statement
225+
*
226+
* @param string $columns
227+
* @param string $joinedTable
228+
* @param string $condition
229+
*
230+
* @return \Manipulator\SQL\Select
231+
*/
232+
public function join(string $columns, string $joinedTable, string $condition)
233+
{
234+
$this->sql[] = "SELECT {$columns} FROM {$this->table} INNER JOIN {$joinedTable} ON {$condition}";
235+
return $this;
236+
}
237+
238+
/**
239+
* Equivalent of LEFT JOIN SQL statement
240+
*
241+
* @param string $columns
242+
* @param string $joinedTable
243+
* @param string $condition
244+
*
245+
* @return \Manipulator\SQL\Select
246+
*/
247+
public function leftJoin(string $columns, string $joinedTable, string $condition)
248+
{
249+
$this->sql[] = "SELECT {$columns} FROM {$this->table} LEFT JOIN {$joinedTable} ON {$condition}";
250+
return $this;
251+
}
252+
253+
/**
254+
* Equivalent of RIGHT JOIN SQL statement
255+
*
256+
* @param string $columns
257+
* @param string $joinedTable
258+
* @param string $condition
259+
*
260+
* @return \Manipulator\SQL\Select
261+
*/
262+
public function rightJoin(string $columns, string $joinedTable, string $condition)
263+
{
264+
$this->sql[] = "SELECT {$columns} FROM {$this->table} RIGHT JOIN {$joinedTable} ON {$condition}";
265+
return $this;
266+
}
100267
}

0 commit comments

Comments
 (0)