dynamodb-admin
Advanced tools
Comparing version 1.7.0 to 1.8.0
50
index.js
@@ -6,3 +6,3 @@ const express = require('express') | ||
const errorhandler = require('errorhandler') | ||
const { serializeKey, parseKey } = require('./util') | ||
const { extractKey, parseKey } = require('./util') | ||
const bodyParser = require('body-parser') | ||
@@ -106,3 +106,3 @@ | ||
return Object.assign({}, item, { | ||
__key: serializeKey(item, description.Table.KeySchema) | ||
__key: extractKey(item, description.Table.KeySchema) | ||
}) | ||
@@ -146,2 +146,21 @@ }) | ||
app.get('/tables/:TableName/add-item', (req, res, next) => { | ||
const TableName = req.params.TableName | ||
describeTable({TableName}).then((result) => { | ||
const table = result.Table | ||
const Item = {} | ||
table.KeySchema.forEach((key) => { | ||
const definition = table.AttributeDefinitions.find((attribute) => { | ||
return attribute.AttributeName === key.AttributeName | ||
}) | ||
Item[key.AttributeName] = definition.AttributeType === 'S' ? '' : 0 | ||
}) | ||
res.render('item', { | ||
TableName: req.params.TableName, | ||
Item: Item, | ||
isNew: true | ||
}) | ||
}).catch(next) | ||
}) | ||
app.get('/tables/:TableName/items/:key', (req, res, next) => { | ||
@@ -161,3 +180,4 @@ const TableName = req.params.TableName | ||
TableName: req.params.TableName, | ||
Item: response.Item | ||
Item: response.Item, | ||
isNew: false | ||
}) | ||
@@ -168,2 +188,26 @@ }) | ||
app.put('/tables/:TableName/add-item', bodyParser.json(), (req, res, next) => { | ||
const TableName = req.params.TableName | ||
describeTable({TableName}).then((description) => { | ||
const params = { | ||
TableName, | ||
Item: req.body | ||
} | ||
return putItem(params).then((response) => { | ||
const Key = extractKey(req.body, description.Table.KeySchema) | ||
const params = { | ||
TableName, | ||
Key | ||
} | ||
return getItem(params).then((response) => { | ||
if (!response.Item) { | ||
return res.status(404).send('Not found') | ||
} | ||
return res.json(Key) | ||
}) | ||
}) | ||
}).catch(next) | ||
}) | ||
app.put('/tables/:TableName/items/:key', bodyParser.json(), (req, res, next) => { | ||
@@ -170,0 +214,0 @@ const TableName = req.params.TableName |
{ | ||
"name": "dynamodb-admin", | ||
"version": "1.7.0", | ||
"version": "1.8.0", | ||
"description": "GUI for DynamoDB. Useful for local development.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,2 +0,2 @@ | ||
exports.serializeKey = function (item, KeySchema) { | ||
exports.extractKey = function (item, KeySchema) { | ||
return KeySchema.reduce((prev, current) => { | ||
@@ -3,0 +3,0 @@ return Object.assign({}, prev, { |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
117715
17
621