UNPKG

@itwin/core-backend

Version:
65 lines 2.69 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module iModels */ import { ECSqlSchemaLocater } from "@itwin/ecschema-metadata"; import { QueryBinder, QueryRowFormat } from "@itwin/core-common"; /** * A [[ECSqlSchemaLocater]]($ecschema-metadata) implementation that uses the [[IModelDb]] to load schemas incrementally. * @beta */ export class IModelIncrementalSchemaLocater extends ECSqlSchemaLocater { _iModel; /** * Constructs a new IModelIncrementalSchemaLocater instance. * @param iModel The [[IModelDb]] to query. * @param options Optional [[ECSqlSchemaLocaterOptions]]($ecschema-metadata). */ constructor(iModel, options) { super(options ?? { useMultipleQueries: true }); this._iModel = iModel; } /** * Gets the [[IModelDb]] targeted by this schema loader. */ get iModelDb() { return this._iModel; } /** * Gets [[SchemaProps]]($ecschema-metadata) for the given [[SchemaKey]]($ecschema-metadata). * This is the full schema json with all elements that are defined in the schema. * @param schemaKey The key of the schema to be resolved. */ async getSchemaProps(schemaKey) { // To keep the main thread from being blocked in sync loading cases the resolving // is triggered through a timeout. Even if there is no delay, it improves loading // time by ~3x. return new Promise((resolve, reject) => setTimeout(() => { try { resolve(this._iModel.getSchemaProps(schemaKey.name)); } catch (error) { reject(error); } }, 0)); } /** * Executes an ECSql query against the IModelDb. * @param query The query to execute * @param options The [[ECSqlQueryOptions]]($ecschema-metadata) to use. * @returns A promise that resolves to read-only array of type TRow. */ async executeQuery(query, options) { const queryParameters = options && options.parameters ? QueryBinder.from(options.parameters) : undefined; return this._iModel .createQueryReader(query, queryParameters, { rowFormat: QueryRowFormat.UseECSqlPropertyNames, limit: { count: options?.limit }, }) .toArray(); } } //# sourceMappingURL=IModelIncrementalSchemaLocater.js.map