Skip to content

Instantly share code, notes, and snippets.

@glennblock
Created December 11, 2012 09:37
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 glennblock/4257337 to your computer and use it in GitHub Desktop.
Save glennblock/4257337 to your computer and use it in GitHub Desktop.
Azure Ubuntu demo
{
"name": "ubuntuazure",
"version": "0.0.0",
"description": "sample app using the azure sdk",
"main": "server.js",
"dependencies": {
"azure": "~0.6.8",
"node-uuid": "~1.4.0"
}
}
var fs = require('fs');
var azure = require('azure');
var http = require('http');
var port = process.env.PORT || 19200;
var uuid = require('node-uuid');
//update credentials with your storage account info
var account = "[put your account here]";
var accountKey = "[put your account key here]";
var tableService = azure.createTableService(account, accountKey );
//tableService.logger = new azure.Logger(azure.Logger.LogLevels.DEBUG);
tableService.createTableIfNotExists('sampletables', function(error, exists){
if(!error){
insert();
}
})
function insert() {
var task = {
PartitionKey : "dummy"
, RowKey : "dummykey" + uuid.v1()
, data : "dummydata"
};
tableService.insertEntity('sampletables', task, function(error){
if(!error){
console.log("Insert successful");
query();
}
});
}
function query() {
var query = azure.TableQuery
.select()
.from('sampletables');
tableService.queryEntities(query, function(error, entities){
if(!error){
//entities contains an array of entities
console.log('Entity count:' + entities.length);
console.log('ParitionKey\tRowKey\t\tData');
for (var i=0; i<entities.length; i++)
{
var entity = entities[i];
console.log(entity.PartitionKey + '\t\t' + entity.RowKey + '\t' + entity.data);
};
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment