Link to home
Start Free TrialLog in
Avatar of Jayesh Acharya
Jayesh AcharyaFlag for United States of America

asked on

azure table how to create the table and add json data using javascript

I am trying to write a javascript function that will do two things
1st create a table in azure if it doesnt already exist

and 2nd add a row to the table I just created


I dont know how to do the following:
  1 - pass the name of the table to the azure function that creates the table I put the value in a variable TName and passed that to the function , but I could not get this to work and I had to hard code the name as a temp fix

  2 - how to create the azure table with the data that is in the json

I have tried to look for examples and I just need a very simple example that I can then make the appropriate changes ...

below i where I have got to and any help is really appreciated

example of the json data I am passing to the function:
{"PARTITION_KEY":"100","ROW_KEY":"1234","DISTRIBUTION_KEY":"44k2","ACCOUNT_NUMBER":"ABC1","ACCOUNT_DATE":"11/30/2017","ACCOUNT_TIME":"12:00:00","ACCOUNT_COUNT":"100","ACCOUNT_SIZE":"22.60"}

Open in new window


// here is the function I am trying to build
function (context, iJsonData) {
...
    var azureStorage = require('azure-storage');    
    var AzureEnv = process.env.test_storage;

	var tableService = azureStorage.createTableService(process.env.test_storage);

// get the season ticket data to be loaded  
    var ClientData = iJsonData; 

	var TName = "MyTestTable";

// how to pass TName to the function createTableIfNotExists ???
tableService.createTableIfNotExists('TEST1', function(error, result, response) {
  if(!error) { 
        if(result.created=true)
        {
            context.log("Table "+TName+ " created since it did not exist");
        }
        else
        {
            context.log("Table "+TName+ " already exists");
        }


          context.log("result ");
          context.log(result);
          context.log("response ");
          context.log(response);
          
  }
  else
  {
          context.log("Table "+TName+ " had an error while creating the table");
          context.log("error");
          context.log(error);
          context.log("result ");
          context.log(result);
          context.log("response ");
          context.log(response);
          
  }
});

//How to define the structure of the azure table????

// How to insert the data that is in the json to the table ???

    context.done();
};

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial