Skip to content

Commit 4ecbf67

Browse files
committed
groupBy and having changed
1 parent 12c3048 commit 4ecbf67

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -607,8 +607,8 @@ The Query API allows to define grouping result sets and restricting the returned
607607
// List the number of books that authors published whose names begin with 'John'
608608
$bookQuery
609609
->setColumns(Projections::property('author'), Projections::rowCount('cnt'))
610-
->addGroupBy(Projections::property('author'))
611-
->addHaving(Restrictions::like('author', 'John%'))
610+
->groupBy(Projections::property('author'))
611+
->having(Restrictions::like('author', 'John%'))
612612
->list();
613613
```
614614

src/TgDatabase/Criterion/QueryImpl.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function addColumns(Expression ...$expressions) {
100100
/**
101101
* Add group by columns for the query.
102102
*/
103-
public function addGroupBy(Expression ...$expressions) {
103+
public function groupBy(Expression ...$expressions) {
104104
foreach ($expressions AS $c) {
105105
if ($c != NULL) $this->groupBy[] = $c;
106106
}
@@ -111,7 +111,7 @@ public function addGroupBy(Expression ...$expressions) {
111111
* Add a restriction to constrain the group by result.
112112
* @return Query - this query for method chaining.
113113
*/
114-
public function addHaving(Criterion ...$criterions) {
114+
public function having(Criterion ...$criterions) {
115115
foreach ($criterions AS $criterion) $this->having[] = $criterion;
116116
return $this;
117117
}

src/TgDatabase/Query.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ public function setProjection(Expression ...$expressions);
5252
* Add group by column
5353
* @return Query - this query for method chaining.
5454
*/
55-
public function addGroupBy(Expression ...$expressions);
55+
public function groupBy(Expression ...$expressions);
5656

5757
/**
5858
* Add a restriction to constrain the group by result.
5959
* @return Query - this query for method chaining.
6060
*/
61-
public function addHaving(Criterion ...$criterions);
61+
public function having(Criterion ...$criterions);
6262

6363
/**
6464
* Set the index of the first result to be retrieved.

tests/TgDatabase/Criterion/QueryImplTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function testGroupBySql(): void {
163163
$query
164164
->addColumns(Projections::property('attr1'), Projections::rowCount('cnt'))
165165
->add(Restrictions::eq('attr3', 'value3'))
166-
->addGroupBy(Projections::property('attr1'));
166+
->groupBy(Projections::property('attr1'));
167167
$this->assertEquals("SELECT `attr1`, COUNT(*) AS `cnt` FROM `dual` GROUP BY `attr1` WHERE (`attr3` = 'value3')", $query->getSelectSql());
168168
}
169169
}
@@ -175,8 +175,8 @@ public function testHavingSql(): void {
175175
$query
176176
->addColumns(Projections::property('attr1'), Projections::rowCount('cnt'))
177177
->add(Restrictions::eq('attr3', 'value3'))
178-
->addGroupBy(Projections::property('attr1'))
179-
->addHaving(Restrictions::eq('attr1', 'value1'));
178+
->groupBy(Projections::property('attr1'))
179+
->having(Restrictions::eq('attr1', 'value1'));
180180
$this->assertEquals("SELECT `attr1`, COUNT(*) AS `cnt` FROM `dual` GROUP BY `attr1` HAVING (`attr1` = 'value1') WHERE (`attr3` = 'value3')", $query->getSelectSql());
181181
}
182182
}

0 commit comments

Comments
 (0)