diff --git a/src/Statement/SimdjsonHandler.php b/src/Statement/SimdjsonHandler.php new file mode 100644 index 0000000..9391a44 --- /dev/null +++ b/src/Statement/SimdjsonHandler.php @@ -0,0 +1,76 @@ +data[$this->fetches] = $stream->getContents(); + $this->length = \simdjson_key_count($this->data[$this->fetches], 'result'); + $this->batchSize = $this->length; + } + + /** + * Return the current result row + * + * @return array + */ + public function current(): array + { + return \simdjson_key_value( + $this->data[$this->fetches], + "result/" . ($this->position - ($this->batchSize * $this->fetches)), + true + ); + } + + public function result(): array + { + return \simdjson_key_value( + $this->data[$this->fetches], + "result", + true + ); + } + + public function raw(): array + { + return $this->data[$this->fetches]; + } + + public function completeResult() + { + $completeResult = [[]]; + + foreach ($this->data as $result) { + $completeResult[] = \simdjson_key_value($result, 'result', true); + } + return array_merge(...$completeResult); + } + + public function appendStream(StreamInterface $stream): void + { + $this->data[++$this->fetches] = $stream->getContents(); + $this->length += \simdjson_key_count($this->data[$this->fetches], 'result', true); + } + +} diff --git a/src/Statement/SimdjsonStreamHandlerFactory.php b/src/Statement/SimdjsonStreamHandlerFactory.php new file mode 100644 index 0000000..429f42f --- /dev/null +++ b/src/Statement/SimdjsonStreamHandlerFactory.php @@ -0,0 +1,22 @@ +data[$this->fetches], 'id', true); + } + + public function hasMore(): bool + { + return \simdjson_key_value($this->data[$this->fetches], 'hasMore', true); + } + + public function resultCount(): ?int + { + return \simdjson_key_value($this->data[$this->fetches], 'count', true); + } + + /** + * Get the total number of current loaded results. + * + * @return int Total number of laoded results + */ + public function count() + { + return $this->length; + } + + public function rewind(): void + { + $this->position = 0; + } + + public function key(): int + { + return $this->position; + } + + public function next(): void + { + $this->position++; + } + + /** + * @return bool + */ + public function valid(): bool + { + return $this->position <= $this->length - 1; + } + + public function writesExecuted(): ?int + { + return \simdjson_key_value($this->data[$this->fetches], "extra/stats/writesExecuted", true); + } + + public function writesIgnored(): ?int + { + return \simdjson_key_value($this->data[$this->fetches], "extra/stats/writesIgnored", true); + } + + public function scannedFull(): ?int + { + return \simdjson_key_value($this->data[$this->fetches], "extra/stats/scannedFull", true); + } + + public function scannedIndex(): ?int + { + return \simdjson_key_value($this->data[$this->fetches], "extra/stats/scannedIndex", true); + } + + public function filtered(): ?int + { + return \simdjson_key_value($this->data[$this->fetches], "extra/stats/filtered", true); + } + + public function fullCount(): ?int + { + return \simdjson_key_value($this->data[$this->fetches], "extra/stats/fullCount", true); + } + + public function warnings(): array + { + return \simdjson_key_value($this->data[$this->fetches], "extra/warnings", true); + } + + public function isCached(): bool + { + return \simdjson_key_value($this->data[$this->fetches], "cached", true); + } +} diff --git a/test/TestUtil.php b/test/TestUtil.php index c97f758..7c7d797 100644 --- a/test/TestUtil.php +++ b/test/TestUtil.php @@ -14,6 +14,7 @@ use ArangoDb\Http\Client; use ArangoDb\Exception\ArangoDbException; use ArangoDb\Statement\ArrayStreamHandlerFactory; +use ArangoDb\Statement\SimdjsonStreamHandlerFactory; use ArangoDb\Statement\StreamHandlerFactoryInterface; use ArangoDb\Type\Database; use ArangoDb\Http\ClientOptions; @@ -84,7 +85,8 @@ public static function getStreamFactory(): StreamFactoryInterface public static function getStreamHandlerFactory(): StreamHandlerFactoryInterface { - return new ArrayStreamHandlerFactory(); + return new SimdjsonStreamHandlerFactory(); +// return new ArrayStreamHandlerFactory(); } public static function createDatabase(): void