data-api-client icon indicating copy to clipboard operation
data-api-client copied to clipboard

error updating "name" column

Open ksAvinash opened this issue 3 years ago • 4 comments

const rds = require('data-api-client')({ secretArn: process.env.rdsSecretArn, resourceArn: process.env.rdsArn, database: process.env.rdsDatabase, region: process.env.awsRegion, });

await rds.query('update users set name = :name where email = :email', { name: 'Test User', email: '[email protected]' });

BadRequestException: Cannot find parameter: name at Object.extractError (/<>/node_modules/aws-sdk/lib/protocol/json.js:52:27) at Request.extractError (/<>/node_modules/aws-sdk/lib/protocol/rest_json.js:55:8) at Request.callListeners (/<>/node_modules/aws-sdk/lib/sequential_executor.js:106:20) at Request.emit (/<>/node_modules/aws-sdk/lib/sequential_executor.js:78:10) at Request.emit (/<>/node_modules/aws-sdk/lib/request.js:688:14) at Request.transition (/<>/node_modules/aws-sdk/lib/request.js:22:10) at AcceptorStateMachine.runTo (/<>/node_modules/aws-sdk/lib/state_machine.js:14:12) at /<>/node_modules/aws-sdk/lib/state_machine.js:26:10 at Request. (/<>/node_modules/aws-sdk/lib/request.js:38:9) at Request. (/<>/node_modules/aws-sdk/lib/request.js:690:12) { code: 'BadRequestException', time: 2021-06-18T02:03:16.626Z, requestId: '<requestId>', statusCode: 400, retryable: false, retryDelay: 51.27294113391956 }

ksAvinash avatar Jun 18 '21 02:06 ksAvinash

After hours and hours on the same problem here is the fix:

DO NOT pass two params, pass 1 or 3+ Any query with 2 params will fail

await rds.query('update users set name = :name where email = :email', { name: 'Test User', email: '[email protected]', dummy: 'dummy' });

Should work. There seems to be a fix on master that has not been uploaded to NPM yet.

lucas-subli avatar Jul 15 '21 22:07 lucas-subli

I've just stumbled upon the same bug. Any ideas when this will be patched on NPM?

brian-learningpool avatar Nov 17 '21 12:11 brian-learningpool

Don't use name, value, cast as property name of params. These keywords are already used in library for other purposes.

await rds.query('update users set name = :cu_name where email = :email', { cu_name : 'Test User', email: '[email protected]' });

Should work

mrbayrmagnai avatar Nov 26 '21 16:11 mrbayrmagnai

Oh, it was driving me mad for an hour, because I have a table with columns note, name and the error for query await db.query(`INSERT INTO InternalNotes (note, name) VALUES ( :note, :name);`, props) is BadRequestException: Cannot find parameter: note, so that was quite confusing as to what is going on.

jansila avatar Jul 10 '22 20:07 jansila