Created
October 3, 2018 11:07
-
-
Save ThomasPe/232923f1e22870c7629643dafdd7bd8c to your computer and use it in GitHub Desktop.
Delete | Azure Functions + NodeJs + Table Storage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const azure = require('azure-storage'); | |
const tableService = azure.createTableService(); | |
const tableName = "mytable"; | |
module.exports = function (context, req) { | |
context.log('Start ItemDelete'); | |
const id = req.query.id; | |
if (id) { | |
// create a temporary object with PartitionKey & RowKey of the item which should be deleted | |
var item = { PartitionKey: 'Partition', RowKey: id }; | |
tableService.deleteEntity(tableName, item, function (error, result, response) { | |
if (!error) { | |
context.res.status(204).send(); | |
} | |
else { | |
context.res.status(500).json({error : error}); | |
} | |
}); | |
} | |
else { | |
// item to delete can't be found since no ID was passed | |
context.res.status(404).send(); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment