0

Let's say I have the following object that contains a key (body) with a string object value:

{
  id:'xxyyzz',
  body:'{\'key1\':\'value1\',\'key2\':\'value2\'}'
}

There is any way to save it in DynamoDB with NodeJS PartiQL?

Because when I try to save it I get an error from the DynamoDB about the escaping in the string value of the body: Statement wasn't well formed, can't be processed.

Any solutions for that?

Maor agai
  • 221
  • 1
  • 3
  • 11

1 Answers1

1

You weren't clear on how you wanted to save the data, my guess was like the following:

const item = {
  id: 'xxyyzz',
  body: '{\'key1\':\'value1\',\'key2\':\'value2\'}'
}


const exStatement = statement => {
  ddb.executeStatement({
    Statement: statement, 
    ReturnConsumedCapacity: 'TOTAL'
  })
    .promise() // Promise
    .then(res => {
      console.log(JSON.stringify(res)) // On-response
    })
    .catch(err => console.log(err)) // On-error
}

exStatement(`INSERT INTO sotest VALUE {'id' : '${item.id}', 'body' : ${item.body}}`)

The outcome:

enter image description here

Update

const item = {
  id: 'lhnng-1',
  body: JSON.stringify({'key1':'value1','key2':'value2'})
}

exStatement(`INSERT INTO sotest VALUE {'id' : '${item.id}', 'body' : '${item.body}'}`)

enter image description here

Leeroy Hannigan
  • 11,409
  • 3
  • 14
  • 31