Skip to content

Commit

Permalink
Merge pull request #57 from Metevier/feature/json-datatype
Browse files Browse the repository at this point in the history
  • Loading branch information
yamatatsu authored Nov 9, 2023
2 parents 85e8e46 + 75fa8d8 commit 39d959b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ function addDataType(
case "double":
updatedObjectWithDataType[key] = Number(input[key]);
break;
case "json":
updatedObjectWithDataType[key] = JSON.parse(input[key]);
break;
default:
updatedObjectWithDataType[key] = input[key];
}
Expand Down
9 changes: 9 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ test("parse to json following ColumnInfo", async () => {
{ Name: "score4", Type: "int" },
{ Name: "rate1", Type: "float" },
{ Name: "rate2", Type: "double" },
{ Name: "metadata", Type: "json" },
],
},
Rows: [
Expand All @@ -52,6 +53,7 @@ test("parse to json following ColumnInfo", async () => {
{ VarCharValue: "score4" },
{ VarCharValue: "rate1" },
{ VarCharValue: "rate2" },
{ VarCharValue: "metadata" },
],
},
{
Expand All @@ -65,6 +67,12 @@ test("parse to json following ColumnInfo", async () => {
{ VarCharValue: "104" },
{ VarCharValue: "1.01" },
{ VarCharValue: "1.02" },
{
VarCharValue: JSON.stringify({
key1: "value1",
key2: "value2",
}),
},
],
},
],
Expand All @@ -86,6 +94,7 @@ test("parse to json following ColumnInfo", async () => {
score4: 104,
rate1: 1.01,
rate2: 1.02,
metadata: { key1: "value1", key2: "value2" },
});
});

Expand Down

0 comments on commit 39d959b

Please sign in to comment.