-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathQueryAnalysisEntry.cpp
More file actions
99 lines (83 loc) · 3.17 KB
/
QueryAnalysisEntry.cpp
File metadata and controls
99 lines (83 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
Copyright (c) 2020 TOSHIBA Digital Solutions Corporation.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "QueryAnalysisEntry.h"
#include <assert.h>
namespace griddb {
#if NAPI_VERSION <= 5
Napi::FunctionReference QueryAnalysisEntry::constructor;
#endif
Napi::Object QueryAnalysisEntry::init(Napi::Env env, Napi::Object exports) {
Napi::HandleScope scope(env);
Napi::Function func = DefineClass(env, "QueryAnalysisEntry",
{ InstanceMethod("get", &QueryAnalysisEntry::get),
});
#if NAPI_VERSION > 5
Napi::FunctionReference* constructor = new Napi::FunctionReference();
*constructor = Napi::Persistent(func);
Util::setInstanceData(env, "QueryAnalysisEntry", constructor);
#else
constructor = Napi::Persistent(func);
constructor.SuppressDestruct();
#endif
exports.Set("QueryAnalysisEntry", func);
return exports;
}
QueryAnalysisEntry::QueryAnalysisEntry(const Napi::CallbackInfo &info) :
Napi::ObjectWrap<QueryAnalysisEntry>(info) {
Napi::Env env = info.Env();
if (info.Length() != 1 || !info[0].IsExternal()) {
// Throw error
THROW_EXCEPTION_WITH_STR(env, "Wrong arguments", NULL)
return;
}
GSQueryAnalysisEntry* queryAnalysPtr = info[0].As<Napi::External
<GSQueryAnalysisEntry>>().Data();
mQueryAnalysis.depth = queryAnalysPtr->depth;
mQueryAnalysis.id = queryAnalysPtr->id;
mQueryAnalysis.statement = Util::strdup(queryAnalysPtr->statement);
mQueryAnalysis.type = Util::strdup(queryAnalysPtr->type);
mQueryAnalysis.value = Util::strdup(queryAnalysPtr->value);
mQueryAnalysis.valueType = Util::strdup(queryAnalysPtr->valueType);
}
Napi::Value QueryAnalysisEntry::get(const Napi::CallbackInfo &info) {
Napi::Env env = info.Env();
if (info.Length() != 0) {
// Throw error
THROW_EXCEPTION_WITH_STR(env, "Wrong arguments", NULL)
return env.Null();
}
Napi::Array arrResult = Napi::Array::New(env);
arrResult.Set("0", mQueryAnalysis.id);
arrResult.Set("1", mQueryAnalysis.depth);
arrResult.Set("2", mQueryAnalysis.type);
arrResult.Set("3", mQueryAnalysis.valueType);
arrResult.Set("4", mQueryAnalysis.value);
arrResult.Set("5", mQueryAnalysis.statement);
return arrResult;
}
QueryAnalysisEntry::~QueryAnalysisEntry() {
// Free memory from Util::strdup
if (mQueryAnalysis.statement) {
delete mQueryAnalysis.statement;
}
if (mQueryAnalysis.type) {
delete mQueryAnalysis.type;
}
if (mQueryAnalysis.value) {
delete mQueryAnalysis.value;
}
if (mQueryAnalysis.valueType) {
delete mQueryAnalysis.valueType;
}
}
} // namespace griddb