@@ -14,6 +14,8 @@ Napi::Object NodeQueryResult::Init(Napi::Env env, Napi::Object exports) {
1414 {
1515 InstanceMethod (" resetIterator" , &NodeQueryResult::ResetIterator),
1616 InstanceMethod (" hasNext" , &NodeQueryResult::HasNext),
17+ InstanceMethod (" hasNextQueryResult" , &NodeQueryResult::HasNextQueryResult),
18+ InstanceMethod (" getNextQueryResultAsync" , &NodeQueryResult::GetNextQueryResultAsync),
1719 InstanceMethod (" getNumTuples" , &NodeQueryResult::GetNumTuples),
1820 InstanceMethod (" getNextAsync" , &NodeQueryResult::GetNextAsync),
1921 InstanceMethod (" getColumnDataTypesAsync" , &NodeQueryResult::GetColumnDataTypesAsync),
@@ -27,8 +29,16 @@ Napi::Object NodeQueryResult::Init(Napi::Env env, Napi::Object exports) {
2729NodeQueryResult::NodeQueryResult (const Napi::CallbackInfo& info)
2830 : Napi::ObjectWrap<NodeQueryResult>(info) {}
2931
30- void NodeQueryResult::SetQueryResult (std::shared_ptr<kuzu::main::QueryResult>& queryResult) {
32+ NodeQueryResult::~NodeQueryResult () {
33+ if (this ->isOwned ) {
34+ delete this ->queryResult ;
35+ this ->queryResult = nullptr ;
36+ }
37+ }
38+
39+ void NodeQueryResult::SetQueryResult (QueryResult* queryResult, bool isOwned) {
3140 this ->queryResult = queryResult;
41+ this ->isOwned = isOwned;
3242}
3343
3444void NodeQueryResult::ResetIterator (const Napi::CallbackInfo& info) {
@@ -52,6 +62,28 @@ Napi::Value NodeQueryResult::HasNext(const Napi::CallbackInfo& info) {
5262 return info.Env ().Undefined ();
5363}
5464
65+ Napi::Value NodeQueryResult::HasNextQueryResult (const Napi::CallbackInfo& info) {
66+ Napi::Env env = info.Env ();
67+ Napi::HandleScope scope (env);
68+ try {
69+ return Napi::Boolean::New (env, this ->queryResult ->hasNextQueryResult ());
70+ } catch (const std::exception& exc) {
71+ Napi::Error::New (env, std::string (exc.what ())).ThrowAsJavaScriptException ();
72+ }
73+ return info.Env ().Undefined ();
74+ }
75+
76+ Napi::Value NodeQueryResult::GetNextQueryResultAsync (const Napi::CallbackInfo& info) {
77+ Napi::Env env = info.Env ();
78+ Napi::HandleScope scope (env);
79+ auto newQueryResult = Napi::ObjectWrap<NodeQueryResult>::Unwrap (info[0 ].As <Napi::Object>());
80+ auto callback = info[1 ].As <Napi::Function>();
81+ auto * asyncWorker =
82+ new NodeQueryResultGetNextQueryResultAsyncWorker (callback, this , newQueryResult);
83+ asyncWorker->Queue ();
84+ return info.Env ().Undefined ();
85+ }
86+
5587Napi::Value NodeQueryResult::GetNumTuples (const Napi::CallbackInfo& info) {
5688 Napi::Env env = info.Env ();
5789 Napi::HandleScope scope (env);
0 commit comments