import WhereClause from "@arcgis/core/core/sql/WhereClause.js";
Since
ArcGIS Maps SDK for JavaScript 4.14

The WhereClause is used to extract the features that meet a specified condition by parsing the provided results in to a value. The parseWhereClause() method returns a Promise that resolves to an instance of this module.

See also

Properties

PropertyTypeClass
readonly
string[]
readonly
readonly

fieldNames

readonly Property
Type
string[]

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

readonly Property
Type
boolean

Returns true if the parsed where clause meets the requirements of standardized sql.

parseTree

readonly Property
Type
SQLNode
Since
ArcGIS Maps SDK for JavaScript 4.24

A parse tree is a data structure for representing a parsed sql statement. Parsing a statement requires the grammar of the language that the statement was written.

See also

Methods

MethodSignatureClass
calculateValue(feature: SimpleAttributes): any
testFeature(feature: SimpleAttributes): boolean

calculateValue

Method
Signature
calculateValue (feature: SimpleAttributes): any

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.

Parameters

ParameterTypeDescriptionRequired
feature

The feature to check against the where clause.

Returns
any

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

Method
Signature
testFeature (feature: SimpleAttributes): boolean

Tests the attributes of a feature against the whereClause, and returns true if the test passes, false otherwise.

Parameters

ParameterTypeDescriptionRequired
feature

The feature to test against the whereClause.

Returns
boolean

Returns true if the test passes, false otherwise.

Example
sql.parseWhereClause("POPULATION > 100000", layer.fieldsIndex)
.then(function(clause){
let testResult = clause.testFeature(new Graphic({
attributes: {
POPULATION: 300000
}
});
console.log(testResult); // prints true
});