Question

Okay, so I'm trying to use Windows Azure Table Service and node to pull data.

The data is there and fine like I want it, my only problem is with multiple where clauses, I do not know or can not find documentation on hot to do them in JavaScript. I am not using C# so most of their documentation I can find is useless.

I have guessed several things but nothing works...

function setCountryResultsWithAge(country, minAge, maxAge) {
  var query = azure.TableQuery
  .select()
  .from('dwadatastorage')
  .where('PartitionKey eq ? ' + country + ' and Age ge ? ' + minAge + ' and Age le ? ' + maxAge);
  //I've also tried this
  //and
  // .where('Age ge ?', minAge)
  //.and
  // .where('Age le ?', maxAge);
  //I've tried this as well
  // .where('Age ge ?', minAge)
  // .where('Age le ?', maxAge);
  tableService.queryEntities(query, function(error, entities){
    if(!error){
      var countryMusicians = [];
      for(var i in entities){
        //console.log(entities[i]);
        countryMusicians.push([entities[i].Artist, entities[i].TotalPlays,     entities[i].Age]);
      }
      console.log(countryMusicians);
      distributeCountryArtists(country, countryMusicians);
    }
  });
  console.log("Finished with age query maybe");
}

If anyone knows more please help

JavaScript only really.

Should just be a little syntax change, but it isnt something I know at all

Was it helpful?

Solution

If Age is stored as a number, make sure you are querying with numbers like so:

var query = azure.TableQuery
  .select()
  .from('dwadatastorage')
  .where('PartitionKey eq ? ', country)
  .and('Age ge ? ', parseInt(minAge))
  .and('Age le ? ', parseInt(maxAge));

OTHER TIPS

Try this:

var query = azure.TableQuery
  .select()
  .from('dwadatastorage')
  .where('PartitionKey eq ?', country)
  .and('Age ge ?', minAge)
  .and('Age le ?', maxAge);

Your question marks should be used as query placeholders. In your original code, they'd have been interpreted literally since you're not providing a second argument to the function call.

.where('PartitionKey eq ' + country + ' and Age ge ' + minAge + ' and Age le ' + maxAge);

I believe would also work, but not recommended.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top