->query must return iterator

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

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:

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”.

Indeed, I’ll make a PR about that.

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

1 Like

CouchbaseResult is now Countable