Last active
October 2, 2018 12:24
-
-
Save ThomasPe/b95c6139597fe31d50f0cd24d041f5de to your computer and use it in GitHub Desktop.
Read | 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 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