WhereClause
require(["esri/core/sql/WhereClause"], function(WhereClause) { /* code goes here */ });
esri/core/sql/WhereClause
The WhereClause is used to extract the features that meet a specified condition by parsing the provided results in to a value. The sql.parseWhereClause() method returns a Promise that resolves to an instance of this module.
Property Overview
Name | Type | Summary | Object | |
---|---|---|---|---|
String[] | An array of the field names used in the where clause. more details | more details | WhereClause | |
Boolean | Returns | more details | WhereClause |
Property Details
An array of the field names used in the where clause. It can be used to get the appropriate fields when querying layers.
Example:// parse layer's definition expression into where clause object sql.parseWhereClause(layer.definitionExpression, layer.fieldsIndex) .then(function(clause){ layer.queryFeatures({ where: "1=1", // where clause object returns layer fields // use these fields to query features from the layer outFields: clause.fieldsNames }).then(function(results) { // process query results }); });
- isStandardized Booleanreadonly
Returns
true
if the parsed where clause meets the requirements of standardized sql.
Method Overview
Name | Return Type | Summary | Object | |
---|---|---|---|---|
Object | Executes the where clause against a feature to generate a value. more details | more details | WhereClause | |
Boolean | Tests the attributes of a feature against the | more details | WhereClause |
Method Details
- calculateValue(feature){Object}
Executes the where clause against a feature to generate a value. It is used when the
WhereClause
is being used as a simple expression. For example, you can use the expression to gather values for statistics.Parameter:feature ObjectThe feature to check against the where clause.
Returns:Type Description Object Returns a value after check feature against the provided where clause. Returns null
if the provided value is unknown.Example:// calculate the grand total sales price of all features featureLayer.queryFeatures().then(function(results){ let total; const expression = "totalSales * totalPrice"; sql.parseWhereClause(expression, layer.fieldsIndex) .then(function(whereClause){ // check if the where clause meets requirements of standardized sql if (whereClause.isStandardized){ features.forEach(function(feature){ total += whereClause.calculateValue(feature) }); console.log(total); // prints the total sales price of all features } }); });
- testFeature(feature){Boolean}
Tests the attributes of a feature against the
whereClause
, and returnstrue
if the test passes,false
otherwise.Parameter:feature ObjectThe feature to test against the
whereClause
.Returns:Type Description Boolean Returns true
if the test passes,false
otherwise.Example:sql.parseWhereClause("POPULATION > 100000", layer.fieldsIndex) .then(function(clause){ var testResult = clause.testFeature(new Graphic({ attributes: { POPULATION: 300000 } }); console.log(testResult); // prints true });