mirror of https://gitee.com/bigwinds/arangodb
The cursor now returns VPackSlices instead of TRI_json_t
This commit is contained in:
parent
19cfa3429c
commit
7360cba43a
|
@ -97,13 +97,11 @@ bool JsonCursor::hasNext() {
|
|||
/// @brief return the next element
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TRI_json_t* JsonCursor::next() {
|
||||
VPackSlice JsonCursor::next() {
|
||||
TRI_ASSERT_EXPENSIVE(_json != nullptr);
|
||||
TRI_ASSERT_EXPENSIVE(_position < _size);
|
||||
VPackSlice slice = _json->slice();
|
||||
// TODO FIX THIS by returning the slice.
|
||||
return arangodb::basics::VelocyPackHelper::velocyPackToJson(
|
||||
slice.at(_position++));
|
||||
return slice.at(_position++);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -143,14 +141,18 @@ void JsonCursor::dump(arangodb::basics::StringBuffer& buffer) {
|
|||
}
|
||||
|
||||
auto row = next();
|
||||
if (row == nullptr) {
|
||||
if (row.isNone()) {
|
||||
THROW_ARANGO_EXCEPTION(TRI_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
int res = TRI_StringifyJson(buffer.stringBuffer(), row);
|
||||
|
||||
if (res != TRI_ERROR_NO_ERROR) {
|
||||
THROW_ARANGO_EXCEPTION(res);
|
||||
arangodb::basics::VPackStringBufferAdapter bufferAdapter(
|
||||
buffer.stringBuffer());
|
||||
VPackDumper dumper(&bufferAdapter);
|
||||
try {
|
||||
dumper.dump(row);
|
||||
} catch (...) {
|
||||
/// TODO correct error Handling!
|
||||
THROW_ARANGO_EXCEPTION(TRI_ERROR_INTERNAL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -233,9 +235,10 @@ bool ExportCursor::hasNext() {
|
|||
/// @brief return the next element (not implemented)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TRI_json_t* ExportCursor::next() {
|
||||
VPackSlice ExportCursor::next() {
|
||||
// should not be called directly
|
||||
return nullptr;
|
||||
VPackSlice slice;
|
||||
return slice;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
#include "Basics/StringBuffer.h"
|
||||
#include "VocBase/voc-types.h"
|
||||
|
||||
struct TRI_json_t;
|
||||
struct TRI_vocbase_t;
|
||||
|
||||
namespace arangodb {
|
||||
|
@ -91,7 +90,7 @@ class Cursor {
|
|||
|
||||
virtual bool hasNext() = 0;
|
||||
|
||||
virtual struct TRI_json_t* next() = 0;
|
||||
virtual arangodb::velocypack::Slice next() = 0;
|
||||
|
||||
virtual size_t count() const = 0;
|
||||
|
||||
|
@ -124,7 +123,7 @@ class JsonCursor : public Cursor {
|
|||
public:
|
||||
bool hasNext() override final;
|
||||
|
||||
struct TRI_json_t* next() override final;
|
||||
arangodb::velocypack::Slice next() override final;
|
||||
|
||||
size_t count() const override final;
|
||||
|
||||
|
@ -154,7 +153,7 @@ class ExportCursor : public Cursor {
|
|||
public:
|
||||
bool hasNext() override final;
|
||||
|
||||
struct TRI_json_t* next() override final;
|
||||
arangodb::velocypack::Slice next() override final;
|
||||
|
||||
size_t count() const override final;
|
||||
|
||||
|
|
|
@ -156,11 +156,11 @@ static void JS_JsonCursor(v8::FunctionCallbackInfo<v8::Value> const& args) {
|
|||
|
||||
auto row = cursor->next();
|
||||
|
||||
if (row == nullptr) {
|
||||
if (row.isNone()) {
|
||||
TRI_V8_THROW_EXCEPTION(TRI_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
docs->Set(static_cast<uint32_t>(i), TRI_ObjectJson(isolate, row));
|
||||
docs->Set(static_cast<uint32_t>(i), TRI_VPackToV8(isolate, row));
|
||||
}
|
||||
|
||||
result->ForceSet(TRI_V8_ASCII_STRING("result"), docs);
|
||||
|
|
Loading…
Reference in New Issue