テーブルがあります: digital_asset、そのパーティション キーは: id です。これにはグローバル セカンダリ インデックスがあります: ean-index と partitioning-key: ean。dynastyjs を使用してセカンダリ インデックスを使用してテーブルをクエリできるようにしたいと考えています。aws-sdk を使用すると、次のようになります。
return new Promise(function (resolve, reject) {
var params = {
TableName: "digital_asset",
IndexName: "ean-index",
KeyConditionExpression: "ean = :ean",
ExpressionAttributeValues: {
":ean": ean
},
ProjectionExpression: "id, ean"
};
docClient.query(params, function(err, data) {
if (err)
console.error(JSON.stringify(err, null, 2));
else
console.log(JSON.stringify(data, null, 2));
if (!err) {
resolve(data.Items.map(function(item){return item.id}));
} else {
reject(err);
}
});
});
dynasty を使用する方がはるかに優れています。たとえば、プライマリ インデックスで検索したクエリは次のとおりです。
return new Promise(function (resolve) {
return digital_asset.find(asset_id).then(function (item) {
resolve(item.ean);
});
});
これは私が試したものですが、エラーが発生しました:
return new Promise(function (resolve, reject) {
return digital_asset.findAll({"ean-index":ean}).then(function (item) {
resolve(item.id);
}).catch(reject);
});
エラー:
InvalidParameterType: Expected params.KeyConditions['id'].AttributeValueList[0].S to be a string
at ParamValidator.fail (node_modules/aws-sdk/lib/param_validator.js:50:37)
at ParamValidator.validateType (node_modules/aws-sdk/lib/param_validator.js:218:10)
at ParamValidator.validateString (node_modules/aws-sdk/lib/param_validator.js:150:14)
at ParamValidator.validateScalar (node_modules/aws-sdk/lib/param_validator.js:130:21)
at ParamValidator.validateMember (node_modules/aws-sdk/lib/param_validator.js:94:21)
at ParamValidator.validateStructure (node_modules/aws-sdk/lib/param_validator.js:75:14)
at ParamValidator.validateMember (node_modules/aws-sdk/lib/param_validator.js:88:21)
at ParamValidator.validateList (node_modules/aws-sdk/lib/param_validator.js:103:14)
at ParamValidator.validateMember (node_modules/aws-sdk/lib/param_validator.js:90:21)
at ParamValidator.validateStructure (node_modules/aws-sdk/lib/param_validator.js:75:14)
at ParamValidator.validateMember (node_modules/aws-sdk/lib/param_validator.js:88:21)
at ParamValidator.validateMap (node_modules/aws-sdk/lib/param_validator.js:117:14)
at ParamValidator.validateMember (node_modules/aws-sdk/lib/param_validator.js:92:21)
at ParamValidator.validateStructure (node_modules/aws-sdk/lib/param_validator.js:75:14)
at ParamValidator.validateMember (node_modules/aws-sdk/lib/param_validator.js:88:21)
at ParamValidator.validate (node_modules/aws-sdk/lib/param_validator.js:34:10)
at Request.VALIDATE_PARAMETERS (node_modules/aws-sdk/lib/event_listeners.js:89:42)
at Request.callListeners (node_modules/aws-sdk/lib/sequential_executor.js:105:20)
at callNextListener (node_modules/aws-sdk/lib/sequential_executor.js:95:12)
at node_modules/aws-sdk/lib/event_listeners.js:75:9
at finish (node_modules/aws-sdk/lib/config.js:307:7)
at node_modules/aws-sdk/lib/config.js:323:9
at Credentials.get (node_modules/aws-sdk/lib/credentials.js:126:7)
at getAsyncCredentials (node_modules/aws-sdk/lib/config.js:317:24)
at Config.getCredentials (node_modules/aws-sdk/lib/config.js:337:9)
at Request.VALIDATE_CREDENTIALS (node_modules/aws-sdk/lib/event_listeners.js:70:26)
at Request.callListeners (node_modules/aws-sdk/lib/sequential_executor.js:101:18)
at Request.emit (node_modules/aws-sdk/lib/sequential_executor.js:77:10)
at Request.emit (node_modules/aws-sdk/lib/request.js:661: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 Request.runTo (node_modules/aws-sdk/lib/request.js:394:15)
at Request.send (node_modules/aws-sdk/lib/request.js:358:10)
at makeRequest (node_modules/aws-sdk/lib/service.js:180:27)
at svc.(anonymous function) [as query] (node_modules/aws-sdk/lib/service.js:437:23)
at tryCatcher (node_modules/dynasty/node_modules/bluebird/js/main/util.js:26:23)
at ret [as queryAsync] (eval at <anonymous> (node_modules/dynasty/node_modules/bluebird/js/main/promisify.js:163:12), <anonymous>:13:39)
at Table.module.exports.queryByHashKey (node_modules/dynasty/lib/lib/aws-translators.js:142:31)
at tryCatcher (node_modules/dynasty/node_modules/bluebird/js/main/util.js:26:23)
at Promise._settlePromiseFromHandler (node_modules/dynasty/node_modules/bluebird/js/main/promise.js:507:31)
at Promise._settlePromiseAt (node_modules/dynasty/node_modules/bluebird/js/main/promise.js:581:18)
at Promise._settlePromises (node_modules/dynasty/node_modules/bluebird/js/main/promise.js:697:14)
at Async._drainQueue (node_modules/dynasty/node_modules/bluebird/js/main/async.js:123:16)
at Async._drainQueues (node_modules/dynasty/node_modules/bluebird/js/main/async.js:133:10)
at Immediate.Async.drainQueues (node_modules/dynasty/node_modules/bluebird/js/main/async.js:15:14)