Skip to content

Instantly share code, notes, and snippets.

@ThomasPe
Last active October 2, 2018 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThomasPe/b95c6139597fe31d50f0cd24d041f5de to your computer and use it in GitHub Desktop.
Save ThomasPe/b95c6139597fe31d50f0cd24d041f5de to your computer and use it in GitHub Desktop.
Read | Azure Functions + NodeJs + Table Storage
const azure = require('azure-storage');
const tableService = azure.createTableService();
const tableName = "mytable";
module.exports = function (context, req) {
context.log('Start ItemRead');
const id = req.query.id;
if (id) {
// return item with RowKey 'id'
tableService.retrieveEntity(tableName, 'Partition', id, function (error, result, response) {
if (!error) {
context.res.status(200).json(response.body);
}
else {
context.res.status(500).json({error : error});
}
});
}
else {
// return the top 100 items
var query = new azure.TableQuery().top(100);
tableService.queryEntities(tableName, query, null, function (error, result, response) {
if(!error){
context.res.status(200).json(response.body.value);
} else {
context.res.status(500).json({error : error});
}
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment