docClient.query(params, function(err, data) { if (err) { console.error("Unable to query. Error:", JSON.stringify(err, null, 2)); } else { console.log("Query succeeded."); data.Items.forEach(function(item) { console.log(" -", item.year + ": " + item.title); }); } });
async find(orderId) { const params = { TableName: this.tableName, KeyConditionExpression: "orderId = :orderId", ExpressionAttributeValues: { ":orderId": orderId } }; const data = await this.documentClient.query(params).promise(); return data.Items[0]; }
async findSocketsBySubscription(subscription) { const queryParams = { TableName: CONSTANTS.DYNAMODB_SOCKETS_TABLE, IndexName: CONSTANTS.DYNAMODB_SOCKETS_TYPE_GSI, KeyConditionExpression: '#type = :type', ExpressionAttributeNames: { '#type': 'type', }, ExpressionAttributeValues: { ':type': subscription } }; return await this._connector.query(queryParams).promise(); }
constructor({ dynamoDB, cache, cacheTableName = 'nd-geohash_HashKeyCache', hashKey = 'hash', geohashKey = 'geohash', geohashIndex = 'index.geohash', locationKey = 'location', hashKeyLength = 6}) { // initialize instance variables this.geohashService = new Geohash({ hashKeyLength: hashKeyLength }); this.dbClient = new AWS.DynamoDB.DocumentClient({ service: dynamoDB}); this.cache = cache; this.cacheTableName = cacheTableName; this.hashKey = hashKey; this.geohashKey = geohashKey; this.geohashIndex = geohashIndex; this.locationKey = locationKey; // promisify as required this.dbClient.putAsync = Promise.promisify(this.dbClient.put, { context: this.dbClient }); this.dbClient.queryAsync = Promise.promisify(this.dbClient.query, { context: this.dbClient }); this.dbClient.updateAsync = Promise.promisify(this.dbClient.update, { context: this.dbClient }); }
//get item API app.get('/api/getuser', function (req, res){ var body = req.query; var params = { TableName : "dynamodb-example-node", KeyConditionExpression: "#expattrname = :expattrvalue", ExpressionAttributeNames:{ "#expattrname": "user_id" }, ExpressionAttributeValues: { ":expattrvalue": Number(body.user_id) } }; docClient.query(params, function(err, data) { if (err) { console.error("Unable to query. Error:", JSON.stringify(err, null, 2)); } else { if(data.Count == 0){ res.status(200).json({ "status": 1, "message": "No Data" }); } else{ res.status(200).json({ "status": 1, "message": "user exists", "data": data.Items[0] }); } } }); });
app.get('/ServerlessReactExample/:ID', function(req, res) { var condition = {} condition[partitionKeyName] = { ComparisonOperator: 'EQ' } if (userIdPresent && req.apiGateway) { condition[partitionKeyName]['AttributeValueList'] = [req.apiGateway.event.requestContext.identity.cognitoIdentityId || UNAUTH ]; } else { try { condition[partitionKeyName]['AttributeValueList'] = [ convertUrlType(req.params[partitionKeyName], partitionKeyType) ]; } catch(err) { res.json({error: 'Wrong column type ' + err}); } } let queryParams = { TableName: tableName, KeyConditions: condition } dynamodb.query(queryParams, (err, data) => { if (err) { res.json({error: 'Could not load items: ' + err}); } else { res.json(data.Items); } }); });
docClient.query(params, function(err, data) { if (err) { console.log("Unable to query. Error:", JSON.stringify(err, null, 2)); } else { console.log("Query succeeded."); data.Items.forEach(function(item) { console.log(" -", item.year + ": " + item.title + " ... " + item.info.genres + " ... " + item.info.actors[0]); }); } });
docClient.query(params, function(err, data) { if (err) { console.error("Unable to query. Error:", JSON.stringify(err, null, 2)); } else { console.log("Query succeeded."); data.Items.forEach(function(item) { console.log(" -", item.year + ": " + item.title); }); } });
async find(orderId) { const params = { TableName: this.tableName, KeyConditionExpression: "orderId = :orderId", ExpressionAttributeValues: { ":orderId": orderId } }; const data = await this.documentClient.query(params).promise(); return data.Items[0]; }
//putData(); //getData(); //updateData(); //queryData(); /** データを検索する */ function queryData() { var params = { TableName: "Movies", KeyConditionExpression: "#yr = :yyyy", ExpressionAttributeNames: { "#yr": "year" }, ExpressionAttributeValues: { ":yyyy": 1985 } }; docClient.query(params, function (err, data) { if (err) { console.error("Unable to query. Error:", JSON.stringify(err, null, 2)); } else { console.log("Query succeeded."); data.Items.forEach(function (item) { console.log(" -", item.year + ": " + item.title); }); } }); }