Executing ECSQL with the iModel.js Backend
ECSQL by itself is described in detail here: ECSQL
Executing an ECSQL statement typically consists of these steps:
- Prepare the ECSQL
- Bind values to the ECSQL parameters (if parameters are used)
- Execute the ECSQL and iterate the query results (for ECSQL SELECT statements).
- Reset the statement and clear its parameter bindings, if the statement should be executed again.
For iModels only ECSQL SELECT statements can be executed. Data modification must be done through the API. For ECDb ECSQL INSERT, UPDATE and DELETE statements can be executed as well.
There are two ways to execute an ECSQL statement:
- IModelDb.executeQuery is the high-level API which does all the above steps in a single call.
- ECSqlStatement is the lower-level API in case you need more flexibility, e.g. when iterating over the query results. Use IModelDb.withPreparedStatement or ECDb.withPreparedStatement in that case.
See Code Examples for examples of how the API is used.
See frequently used ECSQL queries for the specific ECSQL queries that app backends and services often run.
Last Updated: 20 September, 2019