Skip to content

Commit e2141a3

Browse files
committed
Fix rds.toJsonObject method only supporting string values
Currently, the `toJsonObject` method from `rds` only supports `{ stringValue: string }`, but other value types can appear in payloads, such as `{ longValue: int }`. This PR changes it so it assumes value types of any kind, as long as the value type is an object with a key and the value we want to map.
1 parent d423871 commit e2141a3

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

__tests__/resolvers.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ describe("rds resolvers", () => {
242242
"numberOfRecordsUpdated": 0,
243243
"records": [
244244
[
245+
{
246+
"longValue": 12345
247+
},
245248
{
246249
"stringValue": "Mark Twain"
247250
},
@@ -253,6 +256,9 @@ describe("rds resolvers", () => {
253256
}
254257
],
255258
[
259+
{
260+
"longValue": 67890
261+
},
256262
{
257263
"stringValue": "Jack London"
258264
},
@@ -265,6 +271,21 @@ describe("rds resolvers", () => {
265271
]
266272
],
267273
"columnMetadata": [
274+
{
275+
"type": 4,
276+
"typeName": "serial",
277+
"label": "id",
278+
"schemaName": "",
279+
"tableName": "Books",
280+
"isAutoIncrement": true,
281+
"isSigned": true,
282+
"isCurrency": false,
283+
"isCaseSensitive": false,
284+
"nullable": 0,
285+
"precision": 10,
286+
"scale": 0,
287+
"arrayBaseColumnType": 0
288+
},
268289
{
269290
"isSigned": false,
270291
"isCurrency": false,

rds/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ export function toJsonObject(inputStr) {
2020
}
2121

2222
for (const colNo in record) {
23-
24-
// TODO: what if the column is not a string?
25-
const { stringValue } = record[colNo];
2623
const { label } = columnMetadata[colNo];
2724

28-
row[label] = stringValue;
25+
// We assume that the record is a simple object with a single key-value pair.
26+
// For example, `{ longValue: 1 }` or `{ stringValue: "Acme Corp" }`.
27+
row[label] = Object.values(record[colNo])[0];
2928
}
3029

3130
statement.push(row);

0 commit comments

Comments
 (0)