Skip to content

Instantly share code, notes, and snippets.

@mlafleur
Last active August 29, 2015 14:02
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 mlafleur/060394f0562beb87c430 to your computer and use it in GitHub Desktop.
Save mlafleur/060394f0562beb87c430 to your computer and use it in GitHub Desktop.
var azure = require('azure'); // Azure SDK
var uuid = require('node-uuid'); // Unique ID Library
var async = require('async'); // Aync code helper
// These values need to be replaced with
// actual values from your Azure storage account.
// I love you and all but you can't have mine. ;-)
var storageAccount = "";
var storageAccessKey = "";
// TableService interfaces with Azure Table Storage for us
var tableService = azure.createTableService(storageAccount, storageAccessKey);
async.waterfall(
[
// Create our table (if it doesn't exist)
function(callback)
{
tableService.createTableIfNotExists("TestTable1", function(error)
{
if (!error)
{
callback(null)
}
});
},
// Insert the first record
function(callback)
{
var item = {
PartitionKey: 'TestItems',
RowKey: '1',
TextLabel: 'Hello'
};
tableService.insertOrReplaceEntity("TestTable1", item, function(error)
{
if (!error)
{
return callback(null);
}
});
},
// Insert the second record
function(callback)
{
var item = {
PartitionKey: 'TestItems',
RowKey: '2',
TextLabel: 'World'
};
tableService.insertOrReplaceEntity("TestTable1", item, function(error)
{
if (!error)
{
return callback(null);
}
});
},
// Read the value back out of Azure
function(callback)
{
var query = azure.TableQuery
.select()
.from('TestTable1')
.where('PartitionKey eq ?', 'TestItems');
tableService.queryEntities(query, function(error, entities)
{
if(!error)
{
var a = entities[0].TextLabel;
var b = entities[1].TextLabel;
console.log(a + " " + b);
}
});
}
],
function(err)
{
console.log("Table and records were created");
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment