0

I'm trying to implement an API endpoint that handles PATCH or PUT requests, updating the relevant QLDB document with the request payload. I'm trying the following, but it doesn't seem to work:

await driver.executeLambda(async (txn) => {
  await txn.execute(
    `UPDATE People AS p BY p_id SET ? WHERE p_id = ?`,
    requestPayload,
    documentId,
  );
});

The error I get is:

BadRequestException: Parser Error: at line 1, column 32: Invalid path component, expecting either an IDENTIFIER or STAR, got: QUESTION_MARK with value: 
1; Expected identifier for simple path

(I have confirmed that the QLDB statement UPDATE People AS p BY p_id SET p.name = 'John Doe' WHERE p_id = '<document_id>', run in the QLDB web console, does in fact work as desired. I've also confirmed that the values of my variables are as I'd expect -- the first is an object and the second is a string.)

Is this kind of updating not supported by the QLDB Node.js driver?

mightimaus
  • 937
  • 2
  • 14
  • 26

1 Answers1

0

It looks like your query is missing the field name in the parameterization. It should be SET p.name = ?:

UPDATE People AS p BY p_id SET p.name = ? WHERE p.p_id = ?
  • I'm looking to update all of the root-level fields on an object. Is this not possible? Do I need to loop through all of the keys in `requestPayload` and do a `SET p.${key} = ?` for each? Something like `UPDATE People as p BY p_id SET ${Object.keys(requestPayload).map(k => \`p.${k} = ?\`).join(', ')} WHERE p_id = ?\`, ...Object.values(requestPayload), documentId)` – mightimaus Jul 22 '22 at 18:13
  • Indirectly referencing field names is not an intended use case of the query parameterization features. If you know the field names ahead of time then you can iterate over them as in your comment here. – amzn-paunort Jul 25 '22 at 21:15