我想在 NodeJs 中使用 PartiQL 在 DynamoDb 上执行 SELECT 查询,并出现错误。
一个简单的语句没有问题。
const r = await client.send(
new ExecuteStatementCommand({
Statement: `SELECT * FROM Users WHERE userId in ['abcd1234']`
})
)
但是当尝试使用参数执行语句时,我得到了一个错误。
代码
const r2 = await client.send(
new ExecuteStatementCommand({
Statement: `SELECT * FROM Users WHERE userId in ?`,
Parameters: [
['abcd1234']
]
})
)
错误
{
"errorType": "ValidationException",
"errorMessage": "1 validation error detected: Value '[]' at 'parameters' failed to satisfy constraint: Member must have length greater than or equal to 1",
"trace": [
"ValidationException: 1 validation error detected: Value '[]' at 'parameters' failed to satisfy constraint: Member must have length greater than or equal to 1",
" at deserializeAws_json1_0ExecuteStatementCommandError (/var/task/node_modules/@aws-sdk/client-dynamodb/dist/cjs/protocols/Aws_json1_0.js:2202:41)",
" at processTicksAndRejections (internal/process/task_queues.js:97:5)",
" at async /var/task/node_modules/@aws-sdk/middleware-serde/dist/cjs/deserializerMiddleware.js:6:20",
" at async /var/task/node_modules/@aws-sdk/middleware-signing/dist/cjs/middleware.js:12:24",
" at async StandardRetryStrategy.retry (/var/task/node_modules/@aws-sdk/middleware-retry/dist/cjs/defaultStrategy.js:56:46)",
" at async /var/task/node_modules/@aws-sdk/middleware-logger/dist/cjs/loggerMiddleware.js:6:22",
" at async /var/task/node_modules/@aws-sdk/lib-dynamodb/dist/cjs/commands/ExecuteStatementCommand.js:29:26",
" at async Runtime.handler (/var/task/save.js:39:16)"
]
}
有没有人有任何解决方案?
这是整个代码。
const client = DynamoDBDocumentClient.from(
new DynamoDBClient({})
);
// this works
const r = await client.send(
new ExecuteStatementCommand({
Statement: `SELECT * FROM Users WHERE userId in ['abcd1234']`
})
)
// this gets an error
const r2 = await client.send(
new ExecuteStatementCommand({
Statement: `SELECT * FROM Users WHERE userId in ?`,
Parameters: [
['abcd1234']
]
})
)