dynamodb-admin
Advanced tools
Comparing version
62
index.js
@@ -8,2 +8,5 @@ const express = require('express') | ||
const bodyParser = require('body-parser') | ||
const pickBy = require('lodash/pickBy') | ||
const omit = require('lodash/omit') | ||
const yaml = require('js-yaml') | ||
@@ -31,10 +34,9 @@ require('es7-object-polyfill') | ||
const dynamodb = new AWS.DynamoDB() | ||
const documentClient = new AWS.DynamoDB.DocumentClient() | ||
const docClient = new AWS.DynamoDB.DocumentClient() | ||
const listTables = promisify(dynamodb.listTables.bind(dynamodb)) | ||
const describeTable = promisify(dynamodb.describeTable.bind(dynamodb)) | ||
const scan = promisify(documentClient.scan.bind(documentClient)) | ||
const getItem = promisify(documentClient.get.bind(documentClient)) | ||
const putItem = promisify(documentClient.put.bind(documentClient)) | ||
const deleteItem = promisify(documentClient.delete.bind(documentClient)) | ||
const getItem = promisify(docClient.get.bind(docClient)) | ||
const putItem = promisify(docClient.put.bind(docClient)) | ||
const deleteItem = promisify(docClient.delete.bind(docClient)) | ||
@@ -95,12 +97,40 @@ app.use(errorhandler()) | ||
const TableName = req.params.TableName | ||
Promise.all([ | ||
describeTable({TableName}), | ||
scan({ | ||
req.query = pickBy(req.query) | ||
const filters = omit(req.query, ['_hash', 'range']) | ||
describeTable({TableName}).then((description) => { | ||
let ExclusiveStartKey = {} | ||
const ExpressionAttributeNames = {} | ||
const ExpressionAttributeValues = {} | ||
const KeyConditionExpression = [] | ||
const FilterExpressions = [] | ||
for (let key in filters) { | ||
const attributeDefinition = description.Table.AttributeDefinitions.find((definition) => { | ||
return definition.AttributeName === key | ||
}) | ||
if (attributeDefinition && attributeDefinition.AttributeType === 'N') { | ||
req.query[key] = Number(req.query[key]) | ||
} | ||
ExpressionAttributeNames[`#${key}`] = key | ||
ExpressionAttributeValues[`:${key}`] = req.query[key] | ||
FilterExpressions.push(`#${key} = :${key}`) | ||
} | ||
const params = pickBy({ | ||
TableName, | ||
FilterExpression: FilterExpressions.length ? FilterExpressions.join(' AND ') : undefined, | ||
ExpressionAttributeNames: FilterExpressions.length ? ExpressionAttributeNames : undefined, | ||
ExpressionAttributeValues: FilterExpressions.length ? ExpressionAttributeValues : undefined, | ||
ExclusiveStartKey: Object.keys(ExclusiveStartKey).length ? ExclusiveStartKey : undefined, | ||
Limit: 25 | ||
}) | ||
]).then(([description, result]) => { | ||
const data = Object.assign({}, | ||
description, | ||
{ | ||
return Promise.all([ | ||
docClient.scan(params).promise() | ||
]).then(([result]) => { | ||
const data = Object.assign({}, description, { | ||
query: req.query, | ||
yaml, | ||
omit, | ||
filters, | ||
Items: result.Items.map((item) => { | ||
@@ -111,5 +141,5 @@ return Object.assign({}, item, { | ||
}) | ||
} | ||
) | ||
res.render('scan', data) | ||
}) | ||
res.render('scan', data) | ||
}) | ||
}).catch(next) | ||
@@ -122,3 +152,3 @@ }) | ||
describeTable({TableName}), | ||
scan({TableName}) | ||
docClient.scan({TableName}).promise() | ||
]).then(([description, items]) => { | ||
@@ -125,0 +155,0 @@ const data = Object.assign({}, |
{ | ||
"name": "dynamodb-admin", | ||
"version": "1.8.1", | ||
"version": "1.9.1", | ||
"description": "GUI for DynamoDB. Useful for local development.", | ||
@@ -35,3 +35,5 @@ "main": "index.js", | ||
"es7-object-polyfill": "0.0.1", | ||
"express": "^4.14.0" | ||
"express": "^4.14.0", | ||
"js-yaml": "^3.6.1", | ||
"lodash": "^4.16.4" | ||
}, | ||
@@ -38,0 +40,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
205331
74.43%18
5.88%648
4.35%9
28.57%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added