Skip to content

Commit b8aef4c

Browse files
committed
optional session params
1 parent 19b6e1e commit b8aef4c

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/addon.cc

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,22 @@ Napi::Value ExecuteWrapped(const Napi::CallbackInfo& info) {
110110
Napi::Value SessionWrapped(const Napi::CallbackInfo& info) {
111111
Napi::Env env = info.Env();
112112

113-
if (info.Length() < 3 || !info[0].IsString() || !info[1].IsString() || !info[2].IsString()) {
114-
Napi::TypeError::New(env, "String expected").ThrowAsJavaScriptException();
113+
if (info.Length() < 1 || !info[0].IsString()) {
114+
Napi::TypeError::New(env, "Query expected").ThrowAsJavaScriptException();
115115
return env.Null();
116116
}
117117

118118
std::string query = info[0].As<Napi::String>();
119-
std::string format = info[1].As<Napi::String>();
120-
std::string path = info[2].As<Napi::String>();
119+
std::string format = "CSV";
120+
std::string path = "/tmp/";
121+
122+
if (info[1].IsString()) {
123+
format = info[1].As<Napi::String>();
124+
}
125+
126+
if (info[2].IsString()) {
127+
path = info[2].As<Napi::String>();
128+
}
121129

122130
char *result = ExecuteSession((char *)query.c_str(), (char *)format.c_str(), (char *)path.c_str());
123131
if (result == NULL) {

0 commit comments

Comments
 (0)