Skip to content

Commit

Permalink
Moving bufferResults from the ORM to Database Query
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Jan 7, 2015
1 parent 00625f5 commit 6ce5609
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 35 deletions.
35 changes: 35 additions & 0 deletions src/Database/Query.php
Expand Up @@ -113,6 +113,14 @@ class Query implements ExpressionInterface, IteratorAggregate
*/
protected $_functionsBuilder;

/**
* Boolean for tracking whether or not buffered results
* are enabled.
*
* @var bool
*/
protected $_useBufferedResults = true;

/**
* Constructor.
*
Expand Down Expand Up @@ -1581,6 +1589,33 @@ public function valueBinder($binder = null)
return $this;
}

/**
* Enable/Disable buffered results.
*
* When enabled the results returned by this Query will be
* buffered. This enables you to iterate a result set multiple times, or
* both cache and iterate it.
*
* When disabled it will consume less memory as fetched results are not
* remembered for future iterations.
*
* If called with no arguments, it will return whether or not buffering is
* enabled.
*
* @param bool $enable whether or not to enable buffering
* @return bool|$this
*/
public function bufferResults($enable = null)
{
if ($enable === null) {
return $this->_useBufferedResults;
}

$this->_dirty();
$this->_useBufferedResults = (bool)$enable;
return $this;
}

/**
* Auxiliary function used to wrap the original statement from the driver with
* any registered callbacks.
Expand Down
35 changes: 0 additions & 35 deletions src/ORM/Query.php
Expand Up @@ -76,14 +76,6 @@ class Query extends DatabaseQuery implements JsonSerializable
*/
protected $_autoFields;

/**
* Boolean for tracking whether or not buffered results
* are enabled.
*
* @var bool
*/
protected $_useBufferedResults = true;

/**
* Whether to hydrate results into entity objects
*
Expand Down Expand Up @@ -343,33 +335,6 @@ public function matching($assoc, callable $builder = null)
return $this;
}

/**
* Enable/Disable buffered results.
*
* When enabled the ResultSet returned by this Query will be
* buffered. This enables you to iterate a ResultSet multiple times, or
* both cache and iterate the ResultSet.
*
* When disabled it will consume less memory as fetched results are not
* remembered in the ResultSet.
*
* If called with no arguments, it will return whether or not buffering is
* enabled.
*
* @param bool $enable whether or not to enable buffering
* @return bool|$this
*/
public function bufferResults($enable = null)
{
if ($enable === null) {
return $this->_useBufferedResults;
}

$this->_dirty();
$this->_useBufferedResults = (bool)$enable;
return $this;
}

/**
* Returns a key => value array representing a single aliased field
* that can be passed directly to the select() method.
Expand Down

0 comments on commit 6ce5609

Please sign in to comment.