Doug
Doug

Reputation: 7077

Azure Table Storage: How do you group AND and OR Queries Utilizing NodeJS Library?

Utilizing the manual editor in Azure Storage Explorer I can create the following query that returns the results I want from the Azure Table Storage:

TYPE eq 'MYTYPE' and (PartitionKey eq '1' or PartitionKey eq '2')

However, I'm not sure how to do this with the NodeJS library.

The following code:

const azure = require('azure-storage');
const svc = new azure.TableService();
var azureQuery = new azure.TableQuery().where("TYPE eq 'MYTYPE'").or("PartitionKey eq '1'").or("PartitionKey eq '2'")

Is equivalent to the query:

TYPE eq 'MYTYPE' or PartitionKey eq '1' or PartitionKey eq '2'

Likewise I can do the following:

const azure = require('azure-storage');
const svc = new azure.TableService();
var azureQuery = new azure.TableQuery().where("TYPE eq 'MYTYPE'").and("PartitionKey eq '1'").or("PartitionKey eq '2'")

But that results in the query:

 TYPE eq 'MYTYPE' and PartitionKey eq '1' or PartitionKey eq '2'

How do I do the equivalent of parenthesis from the NodeJS library?

Upvotes: 0

Views: 841

Answers (1)

Peter Pan
Peter Pan

Reputation: 24138

As I known, the simple way is like the code below based on my understanding for the TableQuery object.

enter image description here

var filter = "TYPE eq 'MYTYPE' and ( PartitionKey eq '1' or PartitionKey eq '2' )"
var azureQuery = new azure.TableQuery().where(filter)

It works fine.

Upvotes: 2

Related Questions