->query must return iterator


#1

The query method must return an iterator and not an array for memory usage when you get very large number of rows.


#2

There is no such option to stream rows on the fly like on MySQL, so we can’t do that.
So close this request :slight_smile:


#3

But returning an iterator instead of the array would be nice anyways. You could provide more information in properties to that iterator and could directly loop over the rows without having to ask for the rows explicitly.

You could then write

foreach ($cb->query(CouchbaseViewQuery::from("foo", "bar")) as $row) {
}

Instead of …

$res = $cb->query(CouchbaseViewQuery::from("foo", "bar"));

foreach ($res['rows'] as $row) {
}

So … you would skip that rows array-attribute :slightly_smiling: It gives you more the mind of working with objects intead of plain data - like you -kind-of- know what you get. Not just “an array”.


#4

Indeed, I’ll make a PR about that.


#5

This is the PR https://github.com/brett19/php-couchbase/pull/17


#6

CouchbaseResult is now Countable