Skip to content

Commit

Permalink
Fix #2174 for Node.js (#2183)
Browse files Browse the repository at this point in the history
  • Loading branch information
mewim committed Oct 11, 2023
1 parent b5a73a8 commit dad1b71
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tools/nodejs_api/src_cpp/node_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ Napi::Value Util::ConvertToNapiObject(const Value& value, Napi::Env env) {
case LogicalTypeID::INTERNAL_ID: {
return ConvertNodeIdToNapiObject(value.getValue<nodeID_t>(), env);
}
case LogicalTypeID::MAP: {
Napi::Object napiObj = Napi::Object::New(env);
for (auto i = 0u; i < NestedVal::getChildrenSize(&value); ++i) {
auto childVal = NestedVal::getChildVal(&value, i);
auto key = NestedVal::getChildVal(childVal, 0)->toString();
auto val = ConvertToNapiObject(*NestedVal::getChildVal(childVal, 1), env);
napiObj.Set(key, val);
}
return napiObj;
}
default:
throw Exception("Unsupported type: " + LogicalTypeUtils::dataTypeToString(*dataType));
}
Expand Down
14 changes: 14 additions & 0 deletions tools/nodejs_api/test/test_data_type.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,3 +416,17 @@ describe("RECURSIVE_REL", function () {
});
});
});

describe("MAP", function () {
it("should convert MAP type", async function () {
const queryResult = await conn.query(
"MATCH (m:movies) WHERE m.length = 2544 RETURN m.audience;"
);
const result = await queryResult.getAll();
assert.equal(result.length, 1);
assert.equal(Object.keys(result[0]).length, 1);
assert.isTrue("m.audience" in result[0]);
assert.equal(typeof result[0]["m.audience"], "object");
assert.deepEqual(result[0]["m.audience"], {'audience1': 33});
});
});

0 comments on commit dad1b71

Please sign in to comment.