jeremydaly / data-api-client

A "DocumentClient" for the Amazon Aurora Serverless Data API
MIT License
444 stars 63 forks source link

error updating "name" column #98

Open ksAvinash opened 3 years ago

ksAvinash commented 3 years ago

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: 'test@gmail.com' });

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: '', statusCode: 400, retryable: false, retryDelay: 51.27294113391956 }

lucas-subli commented 3 years ago

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: 'test@gmail.com', dummy: 'dummy' });

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

brian-learningpool commented 2 years ago

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

mrbayrmagnai commented 2 years ago

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: 'test@gmail.com' });

Should work

jansila commented 2 years ago

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.