Created
December 11, 2012 09:37
-
-
Save glennblock/4257337 to your computer and use it in GitHub Desktop.
Azure Ubuntu demo
This file contains 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
{ | |
"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" | |
} | |
} |
This file contains 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
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