Permalink
Browse files

API CHANGE: Added DataQuery::aggregate() to allow for aggregates beyo…

…nd Min, Max, Avg, Sum.
  • Loading branch information...
1 parent 5499079 commit 780f2d2b1645f876731e5f6f53958f9d1e4671f4 @sminnee sminnee committed May 28, 2012
Showing with 12 additions and 5 deletions.
  1. +12 −5 model/DataQuery.php
View
@@ -326,8 +326,8 @@ function count() {
*
* @param String $field Unquoted database column name (will be escaped automatically)
*/
- function max($field) {
- return $this->getFinalisedQuery()->aggregate(sprintf('MAX("%s")', Convert::raw2sql($field)))->execute()->value();
+function max($field) {
+ return $this->aggregate(sprintf('MAX("%s")', Convert::raw2sql($field)));
}
/**
@@ -336,7 +336,7 @@ function max($field) {
* @param String $field Unquoted database column name (will be escaped automatically)
*/
function min($field) {
- return $this->getFinalisedQuery()->aggregate(sprintf('MIN("%s")', Convert::raw2sql($field)))->execute()->value();
+ return $this->aggregate(sprintf('MIN("%s")', Convert::raw2sql($field)));
}
/**
@@ -345,7 +345,7 @@ function min($field) {
* @param String $field Unquoted database column name (will be escaped automatically)
*/
function avg($field) {
- return $this->getFinalisedQuery()->aggregate(sprintf('AVG("%s")', Convert::raw2sql($field)))->execute()->value();
+ return $this->aggregate(sprintf('AVG("%s")', Convert::raw2sql($field)));
}
/**
@@ -354,7 +354,14 @@ function avg($field) {
* @param String $field Unquoted database column name (will be escaped automatically)
*/
function sum($field) {
- return $this->getFinalisedQuery()->aggregate(sprintf('SUM("%s")', Convert::raw2sql($field)))->execute()->value();
+ return $this->aggregate(sprintf('SUM("%s")', Convert::raw2sql($field)));
+ }
+
+ /**
+ * Runs a raw aggregate expression. Please handle escaping yourself
+ */
+ function aggregate($expression) {
+ return $this->getFinalisedQuery()->aggregate($expression)->execute()->value();
}
/**

0 comments on commit 780f2d2

Please sign in to comment.