+ function delete($txn = true) {
+ $txn = $txn ? $this->table->getConnection()->startTransaction() : false;
+ try {
+ foreach ($this->rows as $row) {
+ $row->delete();
+ }
+ } catch (\Exception $e) {
+ if ($txn) {
+ $txn->rollback();
+ }
+ throw $e;
+ }
+ if ($txn) {
+ $txn->commit();
+ }
+ return $this;
+ }
+
+ /**
+ * @implements JsonSerilaizable
+ */
+ function jsonSerialize() {
+ return array_map(function($row) {
+ return $row->jsonSerialize();
+ }, $this->rows);
+ }
+
+ /**
+ * @implements \Iterator
+ */
+ function rewind() {
+ $this->index = 0;
+ }
+
+ /**
+ * @implements \Iterator
+ */
+ function next() {
+ ++$this->index;
+ }
+
+ /**
+ * @implements \Iterator
+ * @return bool
+ */
+ function valid() {
+ return $this->index < count($this->rows);
+ }
+
+ /**
+ * @implements \Iterator
+ * @return \pq\Gateway\Row
+ */
+ function current() {
+ if (!$this->valid()) {
+ throw new \OutOfBoundsException("Invalid row index {$this->index}");
+ }
+ return $this->rows[$this->index];
+ }
+
+ /**
+ * @implements \Iterator
+ * @return int
+ */
+ function key() {
+ return $this->index;
+ }
+
+ /**
+ * @implements SeekableIterator
+ * @param mixed $pos
+ */
+ function seek($pos) {
+ /* only index for now */
+ $this->index = $pos;
+
+ if (!$this->valid()) {
+ throw new \OutOfBoundsException("Invalid seek position ($pos)");
+ }
+
+ return $this;
+ }
+
+ /**
+ * @implements \Countable
+ * @return int
+ */
+ function count() {
+ return count($this->rows);
+ }
+
+ /**
+ * Get the rows of this rowset
+ * @return array
+ */
+ function getRows() {
+ return $this->rows;
+ }
+
+ /**
+ * Apply a callback on each row of this rowset
+ * @param callable $cb
+ * @return \pq\Gateway\Rowset
+ */
+ function apply(callable $cb) {
+ array_walk($this->rows, $cb, $this);
+ return $this;