@itwin/core-backend 5.14.0-dev.20 → 5.14.0-dev.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/lib/cjs/ChangesetReader.d.ts +1 -1
  2. package/lib/cjs/ChangesetReader.js +2 -2
  3. package/lib/cjs/ChangesetReader.js.map +1 -1
  4. package/lib/cjs/ChangesetReaderTypes.d.ts +4 -1
  5. package/lib/cjs/ChangesetReaderTypes.d.ts.map +1 -1
  6. package/lib/cjs/ChangesetReaderTypes.js +3 -0
  7. package/lib/cjs/ChangesetReaderTypes.js.map +1 -1
  8. package/lib/cjs/ECDb.d.ts +11 -6
  9. package/lib/cjs/ECDb.d.ts.map +1 -1
  10. package/lib/cjs/ECDb.js +11 -6
  11. package/lib/cjs/ECDb.js.map +1 -1
  12. package/lib/cjs/ECSqlStatement.d.ts +2 -2
  13. package/lib/cjs/ECSqlStatement.js +2 -2
  14. package/lib/cjs/ECSqlStatement.js.map +1 -1
  15. package/lib/cjs/Element.d.ts.map +1 -1
  16. package/lib/cjs/Element.js +6 -3
  17. package/lib/cjs/Element.js.map +1 -1
  18. package/lib/cjs/IModelDb.d.ts +12 -10
  19. package/lib/cjs/IModelDb.d.ts.map +1 -1
  20. package/lib/cjs/IModelDb.js +19 -12
  21. package/lib/cjs/IModelDb.js.map +1 -1
  22. package/lib/esm/ChangesetReader.d.ts +1 -1
  23. package/lib/esm/ChangesetReader.js +2 -2
  24. package/lib/esm/ChangesetReader.js.map +1 -1
  25. package/lib/esm/ChangesetReaderTypes.d.ts +4 -1
  26. package/lib/esm/ChangesetReaderTypes.d.ts.map +1 -1
  27. package/lib/esm/ChangesetReaderTypes.js +3 -0
  28. package/lib/esm/ChangesetReaderTypes.js.map +1 -1
  29. package/lib/esm/ECDb.d.ts +11 -6
  30. package/lib/esm/ECDb.d.ts.map +1 -1
  31. package/lib/esm/ECDb.js +11 -6
  32. package/lib/esm/ECDb.js.map +1 -1
  33. package/lib/esm/ECSqlStatement.d.ts +2 -2
  34. package/lib/esm/ECSqlStatement.js +2 -2
  35. package/lib/esm/ECSqlStatement.js.map +1 -1
  36. package/lib/esm/Element.d.ts.map +1 -1
  37. package/lib/esm/Element.js +6 -3
  38. package/lib/esm/Element.js.map +1 -1
  39. package/lib/esm/IModelDb.d.ts +12 -10
  40. package/lib/esm/IModelDb.d.ts.map +1 -1
  41. package/lib/esm/IModelDb.js +19 -12
  42. package/lib/esm/IModelDb.js.map +1 -1
  43. package/lib/esm/test/ecdb/ConcurrentQuery.test.js +19 -2
  44. package/lib/esm/test/ecdb/ConcurrentQuery.test.js.map +1 -1
  45. package/lib/esm/test/ecdb/QueryReaders.test.js +105 -30
  46. package/lib/esm/test/ecdb/QueryReaders.test.js.map +1 -1
  47. package/lib/esm/test/imodel/IModelElements.test.js +5 -0
  48. package/lib/esm/test/imodel/IModelElements.test.js.map +1 -1
  49. package/lib/esm/test/standalone/ChangesetReader.test.js +111 -2
  50. package/lib/esm/test/standalone/ChangesetReader.test.js.map +1 -1
  51. package/package.json +14 -14
@@ -188,7 +188,7 @@ export declare class ChangesetReader implements Disposable, ChangeSource {
188
188
  * Increasing the batch size improves throughput at the cost of higher peak memory; decreasing it keeps memory consumption lower.
189
189
  *
190
190
  * Default batch sizes when `setBatchSize` is not called:
191
- * - `InstanceKey` filter: **100**.
191
+ * - `InstanceKey` or `InstanceKeyAndIdentifiers` filter: **100**.
192
192
  * - `BisCoreElement` filter (any `abbreviateBlobs` setting): **20**.
193
193
  * - `All` filter, `abbreviateBlobs: false`: **5**.
194
194
  * - `All` filter (blobs abbreviated or unset): **10**.
@@ -65,7 +65,7 @@ class ChangesetReader {
65
65
  get _batchSize() {
66
66
  if (this._batchSizeOverride !== undefined)
67
67
  return this._batchSizeOverride;
68
- if (this._propFilter === ChangesetReaderTypes_1.PropertyFilter.InstanceKey)
68
+ if (this._propFilter === ChangesetReaderTypes_1.PropertyFilter.InstanceKey || this._propFilter === ChangesetReaderTypes_1.PropertyFilter.InstanceKeyAndIdentifiers)
69
69
  return 100;
70
70
  if (this._propFilter === ChangesetReaderTypes_1.PropertyFilter.BisCoreElement)
71
71
  return 20; // because BisCore Element class do not contain any GeomStream property so abbreviateBlobs is not relevant here
@@ -333,7 +333,7 @@ class ChangesetReader {
333
333
  * Increasing the batch size improves throughput at the cost of higher peak memory; decreasing it keeps memory consumption lower.
334
334
  *
335
335
  * Default batch sizes when `setBatchSize` is not called:
336
- * - `InstanceKey` filter: **100**.
336
+ * - `InstanceKey` or `InstanceKeyAndIdentifiers` filter: **100**.
337
337
  * - `BisCoreElement` filter (any `abbreviateBlobs` setting): **20**.
338
338
  * - `All` filter, `abbreviateBlobs: false`: **5**.
339
339
  * - `All` filter (blobs abbreviated or unset): **10**.
@@ -1 +1 @@
1
- {"version":3,"file":"ChangesetReader.js","sourceRoot":"","sources":["../../src/ChangesetReader.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F;;GAEG;AACH,sDAAyE;AACzE,oDAAiD;AAEjD,8DAAyD;AACzD,gDAA+C;AAE/C,iEAA6H;AAI7H,8EAA8E;AAC9E,kBAAkB;AAClB,8EAA8E;AAE9E;;;;;;;;;;;;;;GAcG;AACH,MAAa,eAAe;IAClB,MAAM,CAAU,4BAA4B,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,SAAS;IACjE,aAAa,GAAmC,IAAI,6BAAY,CAAC,QAAQ,CAAC,eAAe,EAAE,CAAC;IAC7G,+EAA+E;IACvE,WAAW,CAAoB;IAC/B,kBAAkB,CAAU;IAC5B,WAAW,GAAmB,qCAAc,CAAC,GAAG,CAAC;IACjD,YAAY,GAAG,CAAC,CAAC;IACzB,yDAAyD;IACjD,MAAM,GAAsC,EAAE,CAAC;IACvD;;;;OAIG;IACK,WAAW,GAAG,CAAC,CAAC;IACxB,uHAAuH;IAC/G,eAAe,GAA+B,SAAS,CAAC;IAChE,sHAAsH;IAC9G,cAAc,GAA+B,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;QACD,IAAI,CAAC,YAAY,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACH,IAAW,EAAE;QACX,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC;QAChD,OAAO,MAAM,KAAK,uBAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU;YAC5C,CAAC,CAAC,MAAM,KAAK,uBAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;gBACtC,CAAC,CAAC,SAAS,CAAC;IAClB,CAAC;IAED,8EAA8E;IAC9E,YAAY;IACZ,8EAA8E;IAE9E;;;;;;;OAOG;IACI,KAAK;QACV,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC;QACtB,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC;QACrB,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;QACjC,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC;QAChC,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;IAED;;;;;OAKG;IACI,CAAC,MAAM,CAAC,OAAO,CAAC;QACrB,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;;AAzgBH,0CA0gBC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module ECDb\r\n */\r\nimport { DbOpcode, Id64String, IModelStatus } from \"@itwin/core-bentley\";\r\nimport { IModelError } from \"@itwin/core-common\";\r\nimport { IModelDb } from \"./IModelDb\";\r\nimport { IModelNative } from \"./internal/NativePlatform\";\r\nimport { _nativeDb } from \"./internal/Symbols\";\r\nimport { IModelJsNative } from \"@bentley/imodeljs-native\";\r\nimport { ChangeInstance, ChangesetReaderArgs, ChangeSource, PropertyFilter, RowFormatOptions } from \"./ChangesetReaderTypes\";\r\nimport { AnyDb, SqliteChangeOp } from \"./SqliteChangesetReader\";\r\n\r\n\r\n// ---------------------------------------------------------------------------\r\n// ChangesetReader\r\n// ---------------------------------------------------------------------------\r\n\r\n/**\r\n * Reads EC-typed changeset data natively from a changeset file, changeset group,\r\n * in-memory transaction, or local un-pushed changes.\r\n *\r\n * Implements [ChangeSource]($backend) so rows can be fed directly into\r\n * [PartialChangeUnifier]($backend) to merge partial (per-table) instances into\r\n * complete EC instances.\r\n *\r\n * When the current row is a non-EC internal SQLite table, [[isECTable]] is `false`\r\n * and both [[inserted]] and [[deleted]] remain `undefined`.\r\n *\r\n * @note The native reader operates one SQLite table-row at a time. Multi-table EC\r\n * instances must be merged using [PartialChangeUnifier]($backend).\r\n * @beta\r\n */\r\nexport class ChangesetReader implements Disposable, ChangeSource {\r\n private static readonly defaultSpillThresholdInBytes = 50 * 1024 * 1024; // 50 MiB\r\n private readonly _nativeReader: IModelJsNative.ChangesetReader = new IModelNative.platform.ChangesetReader();\r\n // Internal options — keep ECClassId as raw Id so the unifier can use it as-is.\r\n private _rowOptions?: RowFormatOptions;\r\n private _batchSizeOverride?: number;\r\n private _propFilter: PropertyFilter = PropertyFilter.All;\r\n private _changeIndex = 0;\r\n /** Rows fetched in the most recent native batch call. */\r\n private _cache: IModelJsNative.ChangesetRowData[] = [];\r\n /**\r\n * Index of the current row in `_cache`.\r\n * Equals `_cache.length` (i.e. out-of-bounds) when no row is active:\r\n * initial state, after exhaustion, or after close().\r\n */\r\n private _cacheIndex = 0;\r\n /** Cached result of the `inserted` getter for the current row. `undefined` when not yet computed or not applicable. */\r\n private _cachedInserted: ChangeInstance | undefined = undefined;\r\n /** Cached result of the `deleted` getter for the current row. `undefined` when not yet computed or not applicable. */\r\n private _cachedDeleted: ChangeInstance | undefined = undefined;\r\n\r\n /** The db used for EC schema resolution. */\r\n public readonly db: AnyDb;\r\n\r\n /** Returns the active cached row, throwing if no row is current.\r\n * @internal */\r\n private get _currentRow(): IModelJsNative.ChangesetRowData {\r\n if (this._cacheIndex >= this._cache.length)\r\n throw new IModelError(IModelStatus.BadRequest, \"ChangesetReader: no current row — call step() first.\");\r\n return this._cache[this._cacheIndex];\r\n }\r\n\r\n /** Returns the batch size to use for native step() calls based on the active property filter.\r\n * @internal */\r\n private get _batchSize(): number {\r\n if (this._batchSizeOverride !== undefined) return this._batchSizeOverride;\r\n if (this._propFilter === PropertyFilter.InstanceKey) return 100;\r\n if (this._propFilter === PropertyFilter.BisCoreElement) return 20; // because BisCore Element class do not contain any GeomStream property so abbreviateBlobs is not relevant here\r\n if (this._rowOptions?.abbreviateBlobs === false) return 5;\r\n return 10; // PropertyFilter.All\r\n }\r\n\r\n /**\r\n * `true` when the current row belongs to an EC-mapped table.\r\n * Valid only after a successful call to [[step]].\r\n * @throws [[IModelError]] if called before a successful [[step]] call.\r\n * @beta\r\n */\r\n public get isECTable(): boolean { return this._currentRow.metadata.isECTable; }\r\n\r\n /**\r\n * Name of the SQLite table for the current change row.\r\n * Valid only after a successful call to [[step]].\r\n * @throws [[IModelError]] if called before a successful [[step]] call.\r\n * @beta\r\n */\r\n public get tableName(): string { return this._currentRow.metadata.tableName; }\r\n\r\n /**\r\n * `true` when the current change was applied indirectly\r\n * Valid only after a successful call to [[step]].\r\n * @throws [[IModelError]] if called before a successful [[step]] call.\r\n * @beta\r\n */\r\n public get isIndirectChange(): boolean { return this._currentRow.metadata.isIndirectChange; }\r\n\r\n /**\r\n * Post-change (inserted or updated-new) EC instance, computed lazily after each [[step]] call.\r\n * `undefined` when the current row is a Delete or a non-EC table row or [[step]] returned false.\r\n * For UPDATE,inserted instances indicate the new state of the instance after the change has been applied and\r\n * deleted instances indicate the old state of the instance before the change has been applied.\r\n * For INSERT, inserted instances indicate the new state of the instance after the change has been applied and deleted instances are undefined.\r\n * For DELETE, deleted instances indicate the old state of the instance before the change has been applied and inserted instances are undefined.\r\n * @beta\r\n */\r\n public get inserted(): ChangeInstance | undefined {\r\n if (this._cachedInserted !== undefined) return this._cachedInserted;\r\n const row = this._cacheIndex < this._cache.length ? this._cache[this._cacheIndex] : undefined;\r\n if (!row || !row.newValues)\r\n return undefined;\r\n const op = this.op;\r\n return (this._cachedInserted = {\r\n ...row.newValues.data,\r\n $meta: {\r\n op,\r\n tables: [row.metadata.tableName],\r\n changeIndexes: [this._changeIndex],\r\n stage: \"New\",\r\n instanceKey: row.newValues.key,\r\n propFilter: this._propFilter,\r\n changeFetchedPropNames: row.newValues.changeFetchedPropNames,\r\n rowOptions: this._rowOptions,\r\n isIndirectChange: row.metadata.isIndirectChange,\r\n },\r\n });\r\n }\r\n\r\n /**\r\n * Pre-change (deleted or updated-old) EC instance, computed lazily after each [[step]] call.\r\n * `undefined` when the current row is an Insert or a non-EC table row or [[step]] returned false.\r\n * @beta\r\n */\r\n public get deleted(): ChangeInstance | undefined {\r\n if (this._cachedDeleted !== undefined) return this._cachedDeleted;\r\n const row = this._cacheIndex < this._cache.length ? this._cache[this._cacheIndex] : undefined;\r\n if (!row || !row.oldValues)\r\n return undefined;\r\n const op = this.op;\r\n return (this._cachedDeleted = {\r\n ...row.oldValues.data,\r\n $meta: {\r\n op,\r\n tables: [row.metadata.tableName],\r\n changeIndexes: [this._changeIndex],\r\n stage: \"Old\",\r\n instanceKey: row.oldValues.key,\r\n propFilter: this._propFilter,\r\n changeFetchedPropNames: row.oldValues.changeFetchedPropNames,\r\n rowOptions: this._rowOptions,\r\n isIndirectChange: row.metadata.isIndirectChange,\r\n },\r\n });\r\n }\r\n\r\n // Private — callers use static factory methods.\r\n private constructor(db: AnyDb) {\r\n this.db = db;\r\n }\r\n\r\n /** Map public RowFormatOptions to the native adaptor options.\r\n * @internal */\r\n private toNativeRowOptions(opts: RowFormatOptions): IModelJsNative.ECSqlRowAdaptorOptions {\r\n return {\r\n abbreviateBlobs: opts.abbreviateBlobs,\r\n classIdsToClassNames: opts.classIdsToClassNames,\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n useJsName: opts.useJsName,\r\n };\r\n }\r\n\r\n // ---------------------------------------------------------------------------\r\n // Static factory methods\r\n // ---------------------------------------------------------------------------\r\n\r\n /**\r\n * Open a changeset file from disk.\r\n * @param args.fileName Absolute path to the changeset file.\r\n * @param args.db Database at or after the changeset's ending state, used for schema resolution.\r\n * @param args.invert When `true`, invert all operations (Insert↔Delete, New↔Old).\r\n * @param args.rowOptions Row adaptor options controlling how EC property values are formatted.\r\n * @param args.propFilter Controls which properties are included. Defaults to `All`.\r\n * @throws if the native layer fails to open the file.\r\n * @beta\r\n */\r\n public static openFile(args: { readonly fileName: string } & ChangesetReaderArgs): ChangesetReader {\r\n const reader = new ChangesetReader(args.db);\r\n reader._rowOptions = args.rowOptions;\r\n const propFilter = args.propFilter ?? PropertyFilter.All;\r\n reader._propFilter = propFilter;\r\n try {\r\n reader._nativeReader.openFile(args.db[_nativeDb], args.fileName, args.invert ?? false, reader._propFilter);\r\n }\r\n catch (e) {\r\n reader.handleCloseErrorWhileOpening(e);\r\n throw e;\r\n }\r\n return reader;\r\n }\r\n\r\n /**\r\n * Concatenate multiple changeset files and read them as a single logical stream.\r\n * @param args.changesetFiles Ordered list of changeset file paths.\r\n * @param args.db Database with schema at or ahead of the last changeset.\r\n * @param args.invert When `true`, invert all operations (Insert↔Delete, New↔Old).\r\n * @param args.rowOptions Row adaptor options controlling how EC property values are formatted.\r\n * @param args.propFilter Controls which properties are included. Defaults to `All`.\r\n * @param args.spillThresholdInBytes When the total size of the changeset data in the change group exceeds this threshold (in bytes),\r\n * the reader writes the data to a temporary file on disk and streams it from there instead of buffering everything in memory.\r\n * This keeps peak memory usage bounded, making the API suitable for processing large changeset groups under low-memory conditions.\r\n * Defaults to 50 MiB.\r\n * @throws if `changesetFiles` is empty, or if the native layer fails to open\r\n * the group.\r\n * @beta\r\n */\r\n public static openGroup(args: { readonly changesetFiles: string[], spillThresholdInBytes?: number } & ChangesetReaderArgs): ChangesetReader {\r\n if (args.changesetFiles.length === 0)\r\n throw new IModelError(IModelStatus.BadArg, \"changesetFiles must contain at least one file.\");\r\n const reader = new ChangesetReader(args.db);\r\n reader._rowOptions = args.rowOptions;\r\n const propFilter = args.propFilter ?? PropertyFilter.All;\r\n reader._propFilter = propFilter;\r\n try {\r\n reader._nativeReader.openGroup(args.db[_nativeDb], args.changesetFiles, args.invert ?? false, reader._propFilter, args.spillThresholdInBytes ?? this.defaultSpillThresholdInBytes);\r\n }\r\n catch (e) {\r\n reader.handleCloseErrorWhileOpening(e);\r\n throw e;\r\n }\r\n return reader;\r\n }\r\n\r\n /**\r\n * Read pending (not yet pushed) local changes from an open IModelDb.\r\n * @param args.db Must be an [IModelDb]($backend) (not [ECDb]($backend)).\r\n * @param args.includeInMemoryChanges Also include in-memory (not yet saved to disk) changes.\r\n * @param args.invert When `true`, invert all operations (Insert↔Delete, New↔Old).\r\n * @param args.rowOptions Row adaptor options controlling how EC property values are formatted.\r\n * @param args.propFilter Controls which properties are included. Defaults to `All`.\r\n * @param args.spillThresholdInBytes When the total size of all local un-pushed saved changes exceeds this threshold (in bytes),\r\n * the reader writes the data to a temporary file on disk and streams it from there instead of buffering everything in memory.\r\n * This keeps peak memory usage bounded, making the API suitable for iModels with large local change backlogs under low-memory conditions.\r\n * Defaults to 50 MiB.\r\n * @throws if the native layer\r\n * fails to open the local changes.\r\n * @beta\r\n */\r\n public static openLocalChanges(\r\n args: Omit<ChangesetReaderArgs, \"db\"> & { db: IModelDb; includeInMemoryChanges?: boolean, spillThresholdInBytes?: number },\r\n ): ChangesetReader {\r\n const reader = new ChangesetReader(args.db);\r\n reader._rowOptions = args.rowOptions;\r\n const propFilter = args.propFilter ?? PropertyFilter.All;\r\n reader._propFilter = propFilter;\r\n try {\r\n reader._nativeReader.openLocalChanges(args.db[_nativeDb], args.includeInMemoryChanges ?? false, args.invert ?? false, reader._propFilter, args.spillThresholdInBytes ?? this.defaultSpillThresholdInBytes);\r\n } catch (e) {\r\n reader.handleCloseErrorWhileOpening(e);\r\n throw e;\r\n }\r\n return reader;\r\n }\r\n\r\n /**\r\n * Read the in-memory (not yet saved to disk) changes of an open IModelDb.\r\n * @param args.db Must be an [IModelDb]($backend).\r\n * @param args.invert When `true`, invert all operations (Insert↔Delete, New↔Old).\r\n * @param args.rowOptions Row adaptor options controlling how EC property values are formatted.\r\n * @param args.propFilter Controls which properties are included. Defaults to `All`.\r\n * @param args.spillThresholdInBytes When the total size of the in-memory (unsaved) change data exceeds this threshold (in bytes),\r\n * the reader writes the data to a temporary file on disk and streams it from there instead of buffering everything in memory.\r\n * This keeps peak memory usage bounded, making the API suitable for large in-memory transactions under low-memory conditions.\r\n * Defaults to 50 MiB.\r\n * @throws if the native layer encounters an error while opening the in-memory changes.\r\n * @beta\r\n */\r\n public static openInMemoryChanges(\r\n args: Omit<ChangesetReaderArgs, \"db\"> & { db: IModelDb, spillThresholdInBytes?: number },\r\n ): ChangesetReader {\r\n const reader = new ChangesetReader(args.db);\r\n reader._rowOptions = args.rowOptions;\r\n const propFilter = args.propFilter ?? PropertyFilter.All;\r\n reader._propFilter = propFilter;\r\n try {\r\n reader._nativeReader.openInMemoryChanges(args.db[_nativeDb], args.invert ?? false, reader._propFilter, args.spillThresholdInBytes ?? this.defaultSpillThresholdInBytes);\r\n } catch (e) {\r\n reader.handleCloseErrorWhileOpening(e);\r\n throw e;\r\n }\r\n return reader;\r\n }\r\n\r\n /**\r\n * Read a single saved transaction by its id.\r\n * @param args.db Must be an [IModelDb]($backend) ([ECDb]($backend) does not support transactions).\r\n * @param args.txnId The id of the saved transaction to read.\r\n * @param args.invert When `true`, invert all operations (Insert↔Delete, New↔Old).\r\n * @param args.rowOptions Row adaptor options controlling how EC property values are formatted.\r\n * @param args.propFilter Controls which properties are included. Defaults to `All`.\r\n * @param args.spillThresholdInBytes When the total size of the transaction's change data exceeds this threshold (in bytes),\r\n * the reader writes the data to a temporary file on disk and streams it from there instead of buffering everything in memory.\r\n * This keeps peak memory usage bounded, making the API suitable for large transactions under low-memory conditions.\r\n * Defaults to 50 MiB.\r\n * @throws if `txnId` is not found, or\r\n * the native layer fails to open the transaction data.\r\n * @beta\r\n */\r\n public static openTxn(\r\n args: Omit<ChangesetReaderArgs, \"db\"> & { db: IModelDb; txnId: Id64String, spillThresholdInBytes?: number },\r\n ): ChangesetReader {\r\n const reader = new ChangesetReader(args.db);\r\n reader._rowOptions = args.rowOptions;\r\n const propFilter = args.propFilter ?? PropertyFilter.All;\r\n reader._propFilter = propFilter;\r\n try {\r\n reader._nativeReader.openTxn(args.db[_nativeDb], args.txnId, args.invert ?? false, reader._propFilter, args.spillThresholdInBytes ?? this.defaultSpillThresholdInBytes);\r\n } catch (e) {\r\n reader.handleCloseErrorWhileOpening(e);\r\n throw e;\r\n }\r\n return reader;\r\n }\r\n\r\n /** Throws if [[step]] has already been called, preventing filter/mode changes mid-iteration.\r\n * @internal */\r\n private throwIfAlreadyStepped(): void {\r\n if (this._changeIndex > 0)\r\n throw new IModelError(IModelStatus.BadRequest, \"ChangesetReader: filters and strict mode and batch size must be configured before the first call to step().\");\r\n }\r\n\r\n /** Handle errors that occur while auto closing the reader if there is also an error while opening the reader */\r\n private handleCloseErrorWhileOpening(e: unknown): void {\r\n try {\r\n this.close();\r\n } catch (closeError) {\r\n throw new IModelError(IModelStatus.BadArg, `Failed to open ChangesetReader with error ${e instanceof Error ? e.message : String(e)}.\r\n Additionally, that triggered an automatic closure of the reader\r\n releasing native resources which also failed with failure ${closeError instanceof Error ? closeError.message : String(closeError)}.\r\n Check native error logs for more details.`);\r\n }\r\n }\r\n\r\n /**\r\n * Set the number of rows to fetch and cache while stepping.\r\n * This is an advanced option that can be used to tune performance for large changesets.\r\n * Increasing the batch size improves throughput at the cost of higher peak memory; decreasing it keeps memory consumption lower.\r\n *\r\n * Default batch sizes when `setBatchSize` is not called:\r\n * - `InstanceKey` filter: **100**.\r\n * - `BisCoreElement` filter (any `abbreviateBlobs` setting): **20**.\r\n * - `All` filter, `abbreviateBlobs: false`: **5**.\r\n * - `All` filter (blobs abbreviated or unset): **10**.\r\n *\r\n * @param batchSize Number of rows to fetch and cache while stepping. Must be a positive integer.\r\n * @throws [[IModelError]] if [[step]] has already been called successfully, or if `batchSize` is not a positive integer.\r\n * @beta\r\n */\r\n public setBatchSize(batchSize: number): void {\r\n this.throwIfAlreadyStepped();\r\n if (!Number.isInteger(batchSize) || batchSize <= 0)\r\n throw new IModelError(IModelStatus.BadArg, \"ChangesetReader: batchSize must be a positive integer.\");\r\n this._batchSizeOverride = batchSize;\r\n }\r\n\r\n // ---------------------------------------------------------------------------\r\n // Filtering\r\n // ---------------------------------------------------------------------------\r\n\r\n /**\r\n * Restrict iteration to changes from the named SQLite tables.\r\n * That means the rows for changes from other tables will be skipped entirely and won't be visible through the reader.\r\n * @param tableNames SQLite table names to include.\r\n * Note: Table names must be provided in the correct case for proper filtering.\r\n * @throws if [[step]] has already been called and the reader successfully stepped at least once(i.e. returned true for a step() call) or if the native layer encounters an error while setting the filter.\r\n * @beta\r\n */\r\n public setTableNameFilters(tableNames: Set<string>): void {\r\n this.throwIfAlreadyStepped();\r\n this._nativeReader.setTableNameFilters(Array.from(tableNames));\r\n }\r\n\r\n /**\r\n * Restrict iteration to changes with the given operation types.\r\n * That means the rows for changes with other operation types will be skipped entirely and won't be visible through the reader.\r\n * @param ops Operations to include.\r\n * @throws if [[step]] has already been called and the reader successfully stepped at least once(i.e. returned true for a step() call) or if the native layer encounters an error while setting the filter.\r\n * @beta\r\n */\r\n public setOpCodeFilters(ops: Set<SqliteChangeOp>): void {\r\n this.throwIfAlreadyStepped();\r\n this._nativeReader.setOpCodeFilters(Array.from(ops));\r\n }\r\n\r\n /**\r\n * Restrict iteration to changes for the given EC class names.\r\n * That means the rows for changes from other EC classes will be skipped entirely and won't be visible through the reader.\r\n * @param classNames EC class names to include. The classNames should be in the full name format(i.e. \"SchemaName:ClassName\").\r\n * Note: Schema names and class names must be provided in the correct case for proper filtering. Derived classes are not automatically included, so they must be specified explicitly if needed.\r\n * @throws if [[step]] has already been called and the reader successfully stepped at least once(i.e. returned true for a step() call) or if the native layer encounters an error while setting the filter.\r\n * @beta\r\n */\r\n public setClassNameFilters(classNames: Set<string>): void {\r\n this.throwIfAlreadyStepped();\r\n this._nativeReader.setClassNameFilters(Array.from(classNames));\r\n }\r\n\r\n /**\r\n * Remove the table-name filters\r\n * @throws if [[step]] has already been called and the reader successfully stepped at least once(i.e. returned true for a step() call) or if the native layer encounters an error.\r\n * @beta\r\n */\r\n public clearTableNameFilters(): void {\r\n this.throwIfAlreadyStepped();\r\n this._nativeReader.clearTableNameFilters();\r\n }\r\n\r\n /**\r\n * Remove the op-code filters\r\n * @throws if [[step]] has already been called and the reader successfully stepped at least once(i.e. returned true for a step() call) or if the native layer encounters an error.\r\n * @beta\r\n */\r\n public clearOpCodeFilters(): void {\r\n this.throwIfAlreadyStepped();\r\n this._nativeReader.clearOpCodeFilters();\r\n }\r\n\r\n /**\r\n * Remove the class-name filters\r\n * @throws if [[step]] has already been called and the reader successfully stepped at least once(i.e. returned true for a step() call) or if the native layer encounters an error.\r\n * @beta\r\n */\r\n public clearClassNameFilters(): void {\r\n this.throwIfAlreadyStepped();\r\n this._nativeReader.clearClassNameFilters();\r\n }\r\n\r\n // ---------------------------------------------------------------------------\r\n // Strict mode\r\n // ---------------------------------------------------------------------------\r\n\r\n /**\r\n * Enable strict mode on the reader.\r\n *\r\n * Strict mode affects how the reader handles a **column-count mismatch** between a change\r\n * record and the corresponding live database table. Such a mismatch can occur when columns\r\n * have been added to a table after the changeset was created.\r\n *\r\n * When strict mode is **enabled**: if the number of columns recorded in a change row differs\r\n * from the number of columns currently present in the live table, the reader throws an error\r\n * instead of processing that row.\r\n *\r\n * Use strict mode when you need to be certain that every change row is interpreted against\r\n * exactly the schema that was in effect when the changeset was written.\r\n *\r\n * @see [[disableStrictMode]] — the default (lenient) behaviour.\r\n * @throws if [[step]] has already been called and the reader successfully stepped at least once(i.e. returned true for a step() call) or if the native layer encounters an error.\r\n * @beta\r\n */\r\n public enableStrictMode(): void {\r\n this.throwIfAlreadyStepped();\r\n this._nativeReader.enableStrictMode();\r\n }\r\n\r\n /**\r\n * Disable strict mode on the reader (this is the default).\r\n *\r\n * When strict mode is **disabled**: if the number of columns recorded in a change row differs\r\n * from the number of columns currently present in the live table, the reader takes the\r\n * **minimum** of the two column counts and proceeds normally with that subset. This is safe\r\n * because SQLite only ever appends new columns at the end of a table and never removes them —\r\n * so older change records simply lack the trailing columns that were added later, and those\r\n * missing columns are silently ignored.\r\n *\r\n * @see [[enableStrictMode]] — throw on column-count mismatches instead.\r\n * @throws if [[step]] has already been called and the reader successfully stepped at least once(i.e. returned true for a step() call) or if the native layer encounters an error.\r\n * @beta\r\n */\r\n public disableStrictMode(): void {\r\n this.throwIfAlreadyStepped();\r\n this._nativeReader.disableStrictMode();\r\n }\r\n\r\n // ---------------------------------------------------------------------------\r\n // Iteration\r\n // ---------------------------------------------------------------------------\r\n\r\n /**\r\n * Advance to the next change.\r\n * @returns `true` while positioned on a valid change; `false` when the stream is exhausted.\r\n * @throws if the native layer encounters an error while reading or decoding\r\n * the next change.\r\n * @beta\r\n */\r\n public step(): boolean {\r\n this._cachedInserted = undefined;\r\n this._cachedDeleted = undefined;\r\n if (this._cacheIndex + 1 < this._cache.length) {\r\n // Still have rows in cache — advance the pointer\r\n this._cacheIndex++;\r\n } else {\r\n // Cache empty or fully consumed — fetch next batch from native\r\n const nativeRowOpts = this._rowOptions ? this.toNativeRowOptions(this._rowOptions) : {};\r\n this._cache = this._nativeReader.step(this._batchSize, nativeRowOpts);\r\n this._cacheIndex = 0;\r\n if (this._cache.length === 0) return false;\r\n }\r\n this._changeIndex++;\r\n return true;\r\n }\r\n\r\n /**\r\n * SQLite opcode of the current change.\r\n * Valid only after a successful call to [[step]].\r\n * @throws [[IModelError]] if called before a successful [[step]] call.\r\n * @beta\r\n */\r\n public get op(): SqliteChangeOp {\r\n const opCode = this._currentRow.metadata.opCode;\r\n return opCode === DbOpcode.Insert ? \"Inserted\"\r\n : opCode === DbOpcode.Update ? \"Updated\"\r\n : \"Deleted\";\r\n }\r\n\r\n // ---------------------------------------------------------------------------\r\n // Lifecycle\r\n // ---------------------------------------------------------------------------\r\n\r\n /**\r\n * Close the reader and release all native resources.\r\n *\r\n * @throws if the native layer encounters an error during cleanup. Native resources\r\n * are not fully released when this throws — check the native error\r\n * logs for details.\r\n * @beta\r\n */\r\n public close(): void {\r\n this._changeIndex = 0;\r\n this._cache = [];\r\n this._cacheIndex = 0;\r\n this._cachedInserted = undefined;\r\n this._cachedDeleted = undefined;\r\n this._nativeReader.close();\r\n }\r\n\r\n /**\r\n * Implements the `Disposable` contract — delegates to [[close]].\r\n *\r\n * @throws if the native layer fails to release its resources (re-thrown from [[close]]).\r\n * @beta\r\n */\r\n public [Symbol.dispose](): void {\r\n this.close();\r\n }\r\n}\r\n\r\n"]}
1
+ {"version":3,"file":"ChangesetReader.js","sourceRoot":"","sources":["../../src/ChangesetReader.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F;;GAEG;AACH,sDAAyE;AACzE,oDAAiD;AAEjD,8DAAyD;AACzD,gDAA+C;AAE/C,iEAA6H;AAI7H,8EAA8E;AAC9E,kBAAkB;AAClB,8EAA8E;AAE9E;;;;;;;;;;;;;;GAcG;AACH,MAAa,eAAe;IAClB,MAAM,CAAU,4BAA4B,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,SAAS;IACjE,aAAa,GAAmC,IAAI,6BAAY,CAAC,QAAQ,CAAC,eAAe,EAAE,CAAC;IAC7G,+EAA+E;IACvE,WAAW,CAAoB;IAC/B,kBAAkB,CAAU;IAC5B,WAAW,GAAmB,qCAAc,CAAC,GAAG,CAAC;IACjD,YAAY,GAAG,CAAC,CAAC;IACzB,yDAAyD;IACjD,MAAM,GAAsC,EAAE,CAAC;IACvD;;;;OAIG;IACK,WAAW,GAAG,CAAC,CAAC;IACxB,uHAAuH;IAC/G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AW,GAAG,CAAC,CAAC;YACrB,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC;gBAAE,OAAO,KAAK,CAAC;QAC7C,CAAC;QACD,IAAI,CAAC,YAAY,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACH,IAAW,EAAE;QACX,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC;QAChD,OAAO,MAAM,KAAK,uBAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU;YAC5C,CAAC,CAAC,MAAM,KAAK,uBAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;gBACtC,CAAC,CAAC,SAAS,CAAC;IAClB,CAAC;IAED,8EAA8E;IAC9E,YAAY;IACZ,8EAA8E;IAE9E;;;;;;;OAOG;IACI,KAAK;QACV,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC;QACtB,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC;QACrB,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;QACjC,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC;QAChC,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;IAED;;;;;OAKG;IACI,CAAC,MAAM,CAAC,OAAO,CAAC;QACrB,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;;AAzgBH,0CA0gBC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module ECDb\r\n */\r\nimport { DbOpcode, Id64String, IModelStatus } from \"@itwin/core-bentley\";\r\nimport { IModelError } from \"@itwin/core-common\";\r\nimport { IModelDb } from \"./IModelDb\";\r\nimport { IModelNative } from \"./internal/NativePlatform\";\r\nimport { _nativeDb } from \"./internal/Symbols\";\r\nimport { IModelJsNative } from \"@bentley/imodeljs-native\";\r\nimport { ChangeInstance, ChangesetReaderArgs, ChangeSource, PropertyFilter, RowFormatOptions } from \"./ChangesetReaderTypes\";\r\nimport { AnyDb, SqliteChangeOp } from \"./SqliteChangesetReader\";\r\n\r\n\r\n// ---------------------------------------------------------------------------\r\n// ChangesetReader\r\n// ---------------------------------------------------------------------------\r\n\r\n/**\r\n * Reads EC-typed changeset data natively from a changeset file, changeset group,\r\n * in-memory transaction, or local un-pushed changes.\r\n *\r\n * Implements [ChangeSource]($backend) so rows can be fed directly into\r\n * [PartialChangeUnifier]($backend) to merge partial (per-table) instances into\r\n * complete EC instances.\r\n *\r\n * When the current row is a non-EC internal SQLite table, [[isECTable]] is `false`\r\n * and both [[inserted]] and [[deleted]] remain `undefined`.\r\n *\r\n * @note The native reader operates one SQLite table-row at a time. Multi-table EC\r\n * instances must be merged using [PartialChangeUnifier]($backend).\r\n * @beta\r\n */\r\nexport class ChangesetReader implements Disposable, ChangeSource {\r\n private static readonly defaultSpillThresholdInBytes = 50 * 1024 * 1024; // 50 MiB\r\n private readonly _nativeReader: IModelJsNative.ChangesetReader = new IModelNative.platform.ChangesetReader();\r\n // Internal options — keep ECClassId as raw Id so the unifier can use it as-is.\r\n private _rowOptions?: RowFormatOptions;\r\n private _batchSizeOverride?: number;\r\n private _propFilter: PropertyFilter = PropertyFilter.All;\r\n private _changeIndex = 0;\r\n /** Rows fetched in the most recent native batch call. */\r\n private _cache: IModelJsNative.ChangesetRowData[] = [];\r\n /**\r\n * Index of the current row in `_cache`.\r\n * Equals `_cache.length` (i.e. out-of-bounds) when no row is active:\r\n * initial state, after exhaustion, or after close().\r\n */\r\n private _cacheIndex = 0;\r\n /** Cached result of the `inserted` getter for the current row. `undefined` when not yet computed or not applicable. */\r\n private _cachedInserted: ChangeInstance | undefined = undefined;\r\n /** Cached result of the `deleted` getter for the current row. `undefined` when not yet computed or not applicable. */\r\n private _cachedDeleted: ChangeInstance | undefined = undefined;\r\n\r\n /** The db used for EC schema resolution. */\r\n public readonly db: AnyDb;\r\n\r\n /** Returns the active cached row, throwing if no row is current.\r\n * @internal */\r\n private get _currentRow(): IModelJsNative.ChangesetRowData {\r\n if (this._cacheIndex >= this._cache.length)\r\n throw new IModelError(IModelStatus.BadRequest, \"ChangesetReader: no current row — call step() first.\");\r\n return this._cache[this._cacheIndex];\r\n }\r\n\r\n /** Returns the batch size to use for native step() calls based on the active property filter.\r\n * @internal */\r\n private get _batchSize(): number {\r\n if (this._batchSizeOverride !== undefined) return this._batchSizeOverride;\r\n if (this._propFilter === PropertyFilter.InstanceKey || this._propFilter === PropertyFilter.InstanceKeyAndIdentifiers) return 100;\r\n if (this._propFilter === PropertyFilter.BisCoreElement) return 20; // because BisCore Element class do not contain any GeomStream property so abbreviateBlobs is not relevant here\r\n if (this._rowOptions?.abbreviateBlobs === false) return 5;\r\n return 10; // PropertyFilter.All\r\n }\r\n\r\n /**\r\n * `true` when the current row belongs to an EC-mapped table.\r\n * Valid only after a successful call to [[step]].\r\n * @throws [[IModelError]] if called before a successful [[step]] call.\r\n * @beta\r\n */\r\n public get isECTable(): boolean { return this._currentRow.metadata.isECTable; }\r\n\r\n /**\r\n * Name of the SQLite table for the current change row.\r\n * Valid only after a successful call to [[step]].\r\n * @throws [[IModelError]] if called before a successful [[step]] call.\r\n * @beta\r\n */\r\n public get tableName(): string { return this._currentRow.metadata.tableName; }\r\n\r\n /**\r\n * `true` when the current change was applied indirectly\r\n * Valid only after a successful call to [[step]].\r\n * @throws [[IModelError]] if called before a successful [[step]] call.\r\n * @beta\r\n */\r\n public get isIndirectChange(): boolean { return this._currentRow.metadata.isIndirectChange; }\r\n\r\n /**\r\n * Post-change (inserted or updated-new) EC instance, computed lazily after each [[step]] call.\r\n * `undefined` when the current row is a Delete or a non-EC table row or [[step]] returned false.\r\n * For UPDATE,inserted instances indicate the new state of the instance after the change has been applied and\r\n * deleted instances indicate the old state of the instance before the change has been applied.\r\n * For INSERT, inserted instances indicate the new state of the instance after the change has been applied and deleted instances are undefined.\r\n * For DELETE, deleted instances indicate the old state of the instance before the change has been applied and inserted instances are undefined.\r\n * @beta\r\n */\r\n public get inserted(): ChangeInstance | undefined {\r\n if (this._cachedInserted !== undefined) return this._cachedInserted;\r\n const row = this._cacheIndex < this._cache.length ? this._cache[this._cacheIndex] : undefined;\r\n if (!row || !row.newValues)\r\n return undefined;\r\n const op = this.op;\r\n return (this._cachedInserted = {\r\n ...row.newValues.data,\r\n $meta: {\r\n op,\r\n tables: [row.metadata.tableName],\r\n changeIndexes: [this._changeIndex],\r\n stage: \"New\",\r\n instanceKey: row.newValues.key,\r\n propFilter: this._propFilter,\r\n changeFetchedPropNames: row.newValues.changeFetchedPropNames,\r\n rowOptions: this._rowOptions,\r\n isIndirectChange: row.metadata.isIndirectChange,\r\n },\r\n });\r\n }\r\n\r\n /**\r\n * Pre-change (deleted or updated-old) EC instance, computed lazily after each [[step]] call.\r\n * `undefined` when the current row is an Insert or a non-EC table row or [[step]] returned false.\r\n * @beta\r\n */\r\n public get deleted(): ChangeInstance | undefined {\r\n if (this._cachedDeleted !== undefined) return this._cachedDeleted;\r\n const row = this._cacheIndex < this._cache.length ? this._cache[this._cacheIndex] : undefined;\r\n if (!row || !row.oldValues)\r\n return undefined;\r\n const op = this.op;\r\n return (this._cachedDeleted = {\r\n ...row.oldValues.data,\r\n $meta: {\r\n op,\r\n tables: [row.metadata.tableName],\r\n changeIndexes: [this._changeIndex],\r\n stage: \"Old\",\r\n instanceKey: row.oldValues.key,\r\n propFilter: this._propFilter,\r\n changeFetchedPropNames: row.oldValues.changeFetchedPropNames,\r\n rowOptions: this._rowOptions,\r\n isIndirectChange: row.metadata.isIndirectChange,\r\n },\r\n });\r\n }\r\n\r\n // Private — callers use static factory methods.\r\n private constructor(db: AnyDb) {\r\n this.db = db;\r\n }\r\n\r\n /** Map public RowFormatOptions to the native adaptor options.\r\n * @internal */\r\n private toNativeRowOptions(opts: RowFormatOptions): IModelJsNative.ECSqlRowAdaptorOptions {\r\n return {\r\n abbreviateBlobs: opts.abbreviateBlobs,\r\n classIdsToClassNames: opts.classIdsToClassNames,\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n useJsName: opts.useJsName,\r\n };\r\n }\r\n\r\n // ---------------------------------------------------------------------------\r\n // Static factory methods\r\n // ---------------------------------------------------------------------------\r\n\r\n /**\r\n * Open a changeset file from disk.\r\n * @param args.fileName Absolute path to the changeset file.\r\n * @param args.db Database at or after the changeset's ending state, used for schema resolution.\r\n * @param args.invert When `true`, invert all operations (Insert↔Delete, New↔Old).\r\n * @param args.rowOptions Row adaptor options controlling how EC property values are formatted.\r\n * @param args.propFilter Controls which properties are included. Defaults to `All`.\r\n * @throws if the native layer fails to open the file.\r\n * @beta\r\n */\r\n public static openFile(args: { readonly fileName: string } & ChangesetReaderArgs): ChangesetReader {\r\n const reader = new ChangesetReader(args.db);\r\n reader._rowOptions = args.rowOptions;\r\n const propFilter = args.propFilter ?? PropertyFilter.All;\r\n reader._propFilter = propFilter;\r\n try {\r\n reader._nativeReader.openFile(args.db[_nativeDb], args.fileName, args.invert ?? false, reader._propFilter);\r\n }\r\n catch (e) {\r\n reader.handleCloseErrorWhileOpening(e);\r\n throw e;\r\n }\r\n return reader;\r\n }\r\n\r\n /**\r\n * Concatenate multiple changeset files and read them as a single logical stream.\r\n * @param args.changesetFiles Ordered list of changeset file paths.\r\n * @param args.db Database with schema at or ahead of the last changeset.\r\n * @param args.invert When `true`, invert all operations (Insert↔Delete, New↔Old).\r\n * @param args.rowOptions Row adaptor options controlling how EC property values are formatted.\r\n * @param args.propFilter Controls which properties are included. Defaults to `All`.\r\n * @param args.spillThresholdInBytes When the total size of the changeset data in the change group exceeds this threshold (in bytes),\r\n * the reader writes the data to a temporary file on disk and streams it from there instead of buffering everything in memory.\r\n * This keeps peak memory usage bounded, making the API suitable for processing large changeset groups under low-memory conditions.\r\n * Defaults to 50 MiB.\r\n * @throws if `changesetFiles` is empty, or if the native layer fails to open\r\n * the group.\r\n * @beta\r\n */\r\n public static openGroup(args: { readonly changesetFiles: string[], spillThresholdInBytes?: number } & ChangesetReaderArgs): ChangesetReader {\r\n if (args.changesetFiles.length === 0)\r\n throw new IModelError(IModelStatus.BadArg, \"changesetFiles must contain at least one file.\");\r\n const reader = new ChangesetReader(args.db);\r\n reader._rowOptions = args.rowOptions;\r\n const propFilter = args.propFilter ?? PropertyFilter.All;\r\n reader._propFilter = propFilter;\r\n try {\r\n reader._nativeReader.openGroup(args.db[_nativeDb], args.changesetFiles, args.invert ?? false, reader._propFilter, args.spillThresholdInBytes ?? this.defaultSpillThresholdInBytes);\r\n }\r\n catch (e) {\r\n reader.handleCloseErrorWhileOpening(e);\r\n throw e;\r\n }\r\n return reader;\r\n }\r\n\r\n /**\r\n * Read pending (not yet pushed) local changes from an open IModelDb.\r\n * @param args.db Must be an [IModelDb]($backend) (not [ECDb]($backend)).\r\n * @param args.includeInMemoryChanges Also include in-memory (not yet saved to disk) changes.\r\n * @param args.invert When `true`, invert all operations (Insert↔Delete, New↔Old).\r\n * @param args.rowOptions Row adaptor options controlling how EC property values are formatted.\r\n * @param args.propFilter Controls which properties are included. Defaults to `All`.\r\n * @param args.spillThresholdInBytes When the total size of all local un-pushed saved changes exceeds this threshold (in bytes),\r\n * the reader writes the data to a temporary file on disk and streams it from there instead of buffering everything in memory.\r\n * This keeps peak memory usage bounded, making the API suitable for iModels with large local change backlogs under low-memory conditions.\r\n * Defaults to 50 MiB.\r\n * @throws if the native layer\r\n * fails to open the local changes.\r\n * @beta\r\n */\r\n public static openLocalChanges(\r\n args: Omit<ChangesetReaderArgs, \"db\"> & { db: IModelDb; includeInMemoryChanges?: boolean, spillThresholdInBytes?: number },\r\n ): ChangesetReader {\r\n const reader = new ChangesetReader(args.db);\r\n reader._rowOptions = args.rowOptions;\r\n const propFilter = args.propFilter ?? PropertyFilter.All;\r\n reader._propFilter = propFilter;\r\n try {\r\n reader._nativeReader.openLocalChanges(args.db[_nativeDb], args.includeInMemoryChanges ?? false, args.invert ?? false, reader._propFilter, args.spillThresholdInBytes ?? this.defaultSpillThresholdInBytes);\r\n } catch (e) {\r\n reader.handleCloseErrorWhileOpening(e);\r\n throw e;\r\n }\r\n return reader;\r\n }\r\n\r\n /**\r\n * Read the in-memory (not yet saved to disk) changes of an open IModelDb.\r\n * @param args.db Must be an [IModelDb]($backend).\r\n * @param args.invert When `true`, invert all operations (Insert↔Delete, New↔Old).\r\n * @param args.rowOptions Row adaptor options controlling how EC property values are formatted.\r\n * @param args.propFilter Controls which properties are included. Defaults to `All`.\r\n * @param args.spillThresholdInBytes When the total size of the in-memory (unsaved) change data exceeds this threshold (in bytes),\r\n * the reader writes the data to a temporary file on disk and streams it from there instead of buffering everything in memory.\r\n * This keeps peak memory usage bounded, making the API suitable for large in-memory transactions under low-memory conditions.\r\n * Defaults to 50 MiB.\r\n * @throws if the native layer encounters an error while opening the in-memory changes.\r\n * @beta\r\n */\r\n public static openInMemoryChanges(\r\n args: Omit<ChangesetReaderArgs, \"db\"> & { db: IModelDb, spillThresholdInBytes?: number },\r\n ): ChangesetReader {\r\n const reader = new ChangesetReader(args.db);\r\n reader._rowOptions = args.rowOptions;\r\n const propFilter = args.propFilter ?? PropertyFilter.All;\r\n reader._propFilter = propFilter;\r\n try {\r\n reader._nativeReader.openInMemoryChanges(args.db[_nativeDb], args.invert ?? false, reader._propFilter, args.spillThresholdInBytes ?? this.defaultSpillThresholdInBytes);\r\n } catch (e) {\r\n reader.handleCloseErrorWhileOpening(e);\r\n throw e;\r\n }\r\n return reader;\r\n }\r\n\r\n /**\r\n * Read a single saved transaction by its id.\r\n * @param args.db Must be an [IModelDb]($backend) ([ECDb]($backend) does not support transactions).\r\n * @param args.txnId The id of the saved transaction to read.\r\n * @param args.invert When `true`, invert all operations (Insert↔Delete, New↔Old).\r\n * @param args.rowOptions Row adaptor options controlling how EC property values are formatted.\r\n * @param args.propFilter Controls which properties are included. Defaults to `All`.\r\n * @param args.spillThresholdInBytes When the total size of the transaction's change data exceeds this threshold (in bytes),\r\n * the reader writes the data to a temporary file on disk and streams it from there instead of buffering everything in memory.\r\n * This keeps peak memory usage bounded, making the API suitable for large transactions under low-memory conditions.\r\n * Defaults to 50 MiB.\r\n * @throws if `txnId` is not found, or\r\n * the native layer fails to open the transaction data.\r\n * @beta\r\n */\r\n public static openTxn(\r\n args: Omit<ChangesetReaderArgs, \"db\"> & { db: IModelDb; txnId: Id64String, spillThresholdInBytes?: number },\r\n ): ChangesetReader {\r\n const reader = new ChangesetReader(args.db);\r\n reader._rowOptions = args.rowOptions;\r\n const propFilter = args.propFilter ?? PropertyFilter.All;\r\n reader._propFilter = propFilter;\r\n try {\r\n reader._nativeReader.openTxn(args.db[_nativeDb], args.txnId, args.invert ?? false, reader._propFilter, args.spillThresholdInBytes ?? this.defaultSpillThresholdInBytes);\r\n } catch (e) {\r\n reader.handleCloseErrorWhileOpening(e);\r\n throw e;\r\n }\r\n return reader;\r\n }\r\n\r\n /** Throws if [[step]] has already been called, preventing filter/mode changes mid-iteration.\r\n * @internal */\r\n private throwIfAlreadyStepped(): void {\r\n if (this._changeIndex > 0)\r\n throw new IModelError(IModelStatus.BadRequest, \"ChangesetReader: filters and strict mode and batch size must be configured before the first call to step().\");\r\n }\r\n\r\n /** Handle errors that occur while auto closing the reader if there is also an error while opening the reader */\r\n private handleCloseErrorWhileOpening(e: unknown): void {\r\n try {\r\n this.close();\r\n } catch (closeError) {\r\n throw new IModelError(IModelStatus.BadArg, `Failed to open ChangesetReader with error ${e instanceof Error ? e.message : String(e)}.\r\n Additionally, that triggered an automatic closure of the reader\r\n releasing native resources which also failed with failure ${closeError instanceof Error ? closeError.message : String(closeError)}.\r\n Check native error logs for more details.`);\r\n }\r\n }\r\n\r\n /**\r\n * Set the number of rows to fetch and cache while stepping.\r\n * This is an advanced option that can be used to tune performance for large changesets.\r\n * Increasing the batch size improves throughput at the cost of higher peak memory; decreasing it keeps memory consumption lower.\r\n *\r\n * Default batch sizes when `setBatchSize` is not called:\r\n * - `InstanceKey` or `InstanceKeyAndIdentifiers` filter: **100**.\r\n * - `BisCoreElement` filter (any `abbreviateBlobs` setting): **20**.\r\n * - `All` filter, `abbreviateBlobs: false`: **5**.\r\n * - `All` filter (blobs abbreviated or unset): **10**.\r\n *\r\n * @param batchSize Number of rows to fetch and cache while stepping. Must be a positive integer.\r\n * @throws [[IModelError]] if [[step]] has already been called successfully, or if `batchSize` is not a positive integer.\r\n * @beta\r\n */\r\n public setBatchSize(batchSize: number): void {\r\n this.throwIfAlreadyStepped();\r\n if (!Number.isInteger(batchSize) || batchSize <= 0)\r\n throw new IModelError(IModelStatus.BadArg, \"ChangesetReader: batchSize must be a positive integer.\");\r\n this._batchSizeOverride = batchSize;\r\n }\r\n\r\n // ---------------------------------------------------------------------------\r\n // Filtering\r\n // ---------------------------------------------------------------------------\r\n\r\n /**\r\n * Restrict iteration to changes from the named SQLite tables.\r\n * That means the rows for changes from other tables will be skipped entirely and won't be visible through the reader.\r\n * @param tableNames SQLite table names to include.\r\n * Note: Table names must be provided in the correct case for proper filtering.\r\n * @throws if [[step]] has already been called and the reader successfully stepped at least once(i.e. returned true for a step() call) or if the native layer encounters an error while setting the filter.\r\n * @beta\r\n */\r\n public setTableNameFilters(tableNames: Set<string>): void {\r\n this.throwIfAlreadyStepped();\r\n this._nativeReader.setTableNameFilters(Array.from(tableNames));\r\n }\r\n\r\n /**\r\n * Restrict iteration to changes with the given operation types.\r\n * That means the rows for changes with other operation types will be skipped entirely and won't be visible through the reader.\r\n * @param ops Operations to include.\r\n * @throws if [[step]] has already been called and the reader successfully stepped at least once(i.e. returned true for a step() call) or if the native layer encounters an error while setting the filter.\r\n * @beta\r\n */\r\n public setOpCodeFilters(ops: Set<SqliteChangeOp>): void {\r\n this.throwIfAlreadyStepped();\r\n this._nativeReader.setOpCodeFilters(Array.from(ops));\r\n }\r\n\r\n /**\r\n * Restrict iteration to changes for the given EC class names.\r\n * That means the rows for changes from other EC classes will be skipped entirely and won't be visible through the reader.\r\n * @param classNames EC class names to include. The classNames should be in the full name format(i.e. \"SchemaName:ClassName\").\r\n * Note: Schema names and class names must be provided in the correct case for proper filtering. Derived classes are not automatically included, so they must be specified explicitly if needed.\r\n * @throws if [[step]] has already been called and the reader successfully stepped at least once(i.e. returned true for a step() call) or if the native layer encounters an error while setting the filter.\r\n * @beta\r\n */\r\n public setClassNameFilters(classNames: Set<string>): void {\r\n this.throwIfAlreadyStepped();\r\n this._nativeReader.setClassNameFilters(Array.from(classNames));\r\n }\r\n\r\n /**\r\n * Remove the table-name filters\r\n * @throws if [[step]] has already been called and the reader successfully stepped at least once(i.e. returned true for a step() call) or if the native layer encounters an error.\r\n * @beta\r\n */\r\n public clearTableNameFilters(): void {\r\n this.throwIfAlreadyStepped();\r\n this._nativeReader.clearTableNameFilters();\r\n }\r\n\r\n /**\r\n * Remove the op-code filters\r\n * @throws if [[step]] has already been called and the reader successfully stepped at least once(i.e. returned true for a step() call) or if the native layer encounters an error.\r\n * @beta\r\n */\r\n public clearOpCodeFilters(): void {\r\n this.throwIfAlreadyStepped();\r\n this._nativeReader.clearOpCodeFilters();\r\n }\r\n\r\n /**\r\n * Remove the class-name filters\r\n * @throws if [[step]] has already been called and the reader successfully stepped at least once(i.e. returned true for a step() call) or if the native layer encounters an error.\r\n * @beta\r\n */\r\n public clearClassNameFilters(): void {\r\n this.throwIfAlreadyStepped();\r\n this._nativeReader.clearClassNameFilters();\r\n }\r\n\r\n // ---------------------------------------------------------------------------\r\n // Strict mode\r\n // ---------------------------------------------------------------------------\r\n\r\n /**\r\n * Enable strict mode on the reader.\r\n *\r\n * Strict mode affects how the reader handles a **column-count mismatch** between a change\r\n * record and the corresponding live database table. Such a mismatch can occur when columns\r\n * have been added to a table after the changeset was created.\r\n *\r\n * When strict mode is **enabled**: if the number of columns recorded in a change row differs\r\n * from the number of columns currently present in the live table, the reader throws an error\r\n * instead of processing that row.\r\n *\r\n * Use strict mode when you need to be certain that every change row is interpreted against\r\n * exactly the schema that was in effect when the changeset was written.\r\n *\r\n * @see [[disableStrictMode]] — the default (lenient) behaviour.\r\n * @throws if [[step]] has already been called and the reader successfully stepped at least once(i.e. returned true for a step() call) or if the native layer encounters an error.\r\n * @beta\r\n */\r\n public enableStrictMode(): void {\r\n this.throwIfAlreadyStepped();\r\n this._nativeReader.enableStrictMode();\r\n }\r\n\r\n /**\r\n * Disable strict mode on the reader (this is the default).\r\n *\r\n * When strict mode is **disabled**: if the number of columns recorded in a change row differs\r\n * from the number of columns currently present in the live table, the reader takes the\r\n * **minimum** of the two column counts and proceeds normally with that subset. This is safe\r\n * because SQLite only ever appends new columns at the end of a table and never removes them —\r\n * so older change records simply lack the trailing columns that were added later, and those\r\n * missing columns are silently ignored.\r\n *\r\n * @see [[enableStrictMode]] — throw on column-count mismatches instead.\r\n * @throws if [[step]] has already been called and the reader successfully stepped at least once(i.e. returned true for a step() call) or if the native layer encounters an error.\r\n * @beta\r\n */\r\n public disableStrictMode(): void {\r\n this.throwIfAlreadyStepped();\r\n this._nativeReader.disableStrictMode();\r\n }\r\n\r\n // ---------------------------------------------------------------------------\r\n // Iteration\r\n // ---------------------------------------------------------------------------\r\n\r\n /**\r\n * Advance to the next change.\r\n * @returns `true` while positioned on a valid change; `false` when the stream is exhausted.\r\n * @throws if the native layer encounters an error while reading or decoding\r\n * the next change.\r\n * @beta\r\n */\r\n public step(): boolean {\r\n this._cachedInserted = undefined;\r\n this._cachedDeleted = undefined;\r\n if (this._cacheIndex + 1 < this._cache.length) {\r\n // Still have rows in cache — advance the pointer\r\n this._cacheIndex++;\r\n } else {\r\n // Cache empty or fully consumed — fetch next batch from native\r\n const nativeRowOpts = this._rowOptions ? this.toNativeRowOptions(this._rowOptions) : {};\r\n this._cache = this._nativeReader.step(this._batchSize, nativeRowOpts);\r\n this._cacheIndex = 0;\r\n if (this._cache.length === 0) return false;\r\n }\r\n this._changeIndex++;\r\n return true;\r\n }\r\n\r\n /**\r\n * SQLite opcode of the current change.\r\n * Valid only after a successful call to [[step]].\r\n * @throws [[IModelError]] if called before a successful [[step]] call.\r\n * @beta\r\n */\r\n public get op(): SqliteChangeOp {\r\n const opCode = this._currentRow.metadata.opCode;\r\n return opCode === DbOpcode.Insert ? \"Inserted\"\r\n : opCode === DbOpcode.Update ? \"Updated\"\r\n : \"Deleted\";\r\n }\r\n\r\n // ---------------------------------------------------------------------------\r\n // Lifecycle\r\n // ---------------------------------------------------------------------------\r\n\r\n /**\r\n * Close the reader and release all native resources.\r\n *\r\n * @throws if the native layer encounters an error during cleanup. Native resources\r\n * are not fully released when this throws — check the native error\r\n * logs for details.\r\n * @beta\r\n */\r\n public close(): void {\r\n this._changeIndex = 0;\r\n this._cache = [];\r\n this._cacheIndex = 0;\r\n this._cachedInserted = undefined;\r\n this._cachedDeleted = undefined;\r\n this._nativeReader.close();\r\n }\r\n\r\n /**\r\n * Implements the `Disposable` contract — delegates to [[close]].\r\n *\r\n * @throws if the native layer fails to release its resources (re-thrown from [[close]]).\r\n * @beta\r\n */\r\n public [Symbol.dispose](): void {\r\n this.close();\r\n }\r\n}\r\n\r\n"]}
@@ -15,7 +15,10 @@ export declare enum PropertyFilter {
15
15
  * are returned. */
16
16
  BisCoreElement = 1,
17
17
  /** Only `ECInstanceId` and `ECClassId`. */
18
- InstanceKey = 2
18
+ InstanceKey = 2,
19
+ /** `ECInstanceId` and `ECClassId`, plus identifiers read only from the changeset, such as an aspect's owning `Element`.
20
+ * See [the full list]($docs/learning/backend/ChangesetReader.md#identifiers-returned-by-instancekeyandidentifiers). */
21
+ InstanceKeyAndIdentifiers = 3
19
22
  }
20
23
  /**
21
24
  * Row-formatting options for [ChangesetReader]($backend) factory methods.
@@ -1 +1 @@
1
- {"version":3,"file":"ChangesetReaderTypes.d.ts","sourceRoot":"","sources":["../../src/ChangesetReaderTypes.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,OAAO,EAAE,KAAK,EA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C3H,sBAAsB,EAAE,MAAM,EAAE,CAAC;IACjC,8EAA8E;IAC9E,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAC9B,oDAAoD;IACpD,gBAAgB,EAAE,OAAO,CAAC;CAC3B;AAED;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,kEAAkE;IAClE,KAAK,EAAE,UAAU,CAAC;IAClB,+EAA+E;IAC/E,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,mDAAmD;IACnD,QAAQ,CAAC,EAAE,EAAE,cAAc,CAAC;IAC5B;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,cAAc,CAAC;IACnC;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,cAAc,CAAC;CACnC;AAMD;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,yFAAyF;IACzF,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IACnB,sCAAsC;IACtC,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,4EAA4E;IAC5E,QAAQ,CAAC,UAAU,CAAC,EAAE,gBAAgB,CAAC;IACvC,mGAAmG;IACnG,QAAQ,CAAC,UAAU,CAAC,EAAE,cAAc,CAAC;CACtC"}
@@ -19,5 +19,8 @@ var PropertyFilter;
19
19
  PropertyFilter[PropertyFilter["BisCoreElement"] = 1] = "BisCoreElement";
20
20
  /** Only `ECInstanceId` and `ECClassId`. */
21
21
  PropertyFilter[PropertyFilter["InstanceKey"] = 2] = "InstanceKey";
22
+ /** `ECInstanceId` and `ECClassId`, plus identifiers read only from the changeset, such as an aspect's owning `Element`.
23
+ * See [the full list]($docs/learning/backend/ChangesetReader.md#identifiers-returned-by-instancekeyandidentifiers). */
24
+ PropertyFilter[PropertyFilter["InstanceKeyAndIdentifiers"] = 3] = "InstanceKeyAndIdentifiers";
22
25
  })(PropertyFilter || (exports.PropertyFilter = PropertyFilter = {}));
23
26
  //# sourceMappingURL=ChangesetReaderTypes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ChangesetReaderTypes.js","sourceRoot":"","sources":["../../src/ChangesetReaderTypes.ts"],"names":[],"mappings":";;;AASA,8EAA8E;AAC9E,eAAe;AACf,8EAA8E;AAE9E;;;GAGG;AACH,IAAY,cAUX;AAVD,WAAY,cAAc;IACxB,kDAAkD;IAClD,iDAAO,CAAA;IACP;;;uBAGmB;IACnB,uEAAkB,CAAA;IAClB,2CAA2C;IAC3C,iEAAe,CAAA;AACjB,CAAC,EAVW,cAAc,8BAAd,cAAc,QAUzB","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module ECDb\r\n */\r\nimport { AnyDb, SqliteChangeOp, SqliteValueStage } from \"./SqliteChangesetReader\";\r\n\r\n// ---------------------------------------------------------------------------\r\n// Type aliases\r\n// ---------------------------------------------------------------------------\r\n\r\n/**\r\n * Controls which properties are included in the output of [ChangesetReader]($backend).\r\n * @beta\r\n */\r\nexport enum PropertyFilter {\r\n /** All EC properties mapped to changed tables. */\r\n All = 0,\r\n /** For classes whose base class is `BisCore:Element`, only `BisCore:Element` properties\r\n * mapped to changed tables are returned. If no `BisCore:Element` class property changed,\r\n * only `ECInstanceId` and `ECClassId` are returned. For other classes all mapped properties\r\n * are returned. */\r\n BisCoreElement = 1,\r\n /** Only `ECInstanceId` and `ECClassId`. */\r\n InstanceKey = 2,\r\n}\r\n\r\n/**\r\n * Row-formatting options for [ChangesetReader]($backend) factory methods.\r\n * Controls how EC property values are represented in the returned instances.\r\n * @beta\r\n */\r\nexport interface RowFormatOptions {\r\n /**\r\n * When `false`, binary properties are returned as full `Uint8Array` values.\r\n * When `true` (or omitted), binary properties are summarized as `{ bytes: N }`.\r\n */\r\n abbreviateBlobs?: boolean;\r\n /**\r\n * When `true`, all classId values are converted from hex strings\r\n * to fully-qualified class names (e.g. `\"BisCore.DrawingModel\"`).\r\n */\r\n classIdsToClassNames?: boolean;\r\n /**\r\n * When `true`, all property keys and struct sub-keys are returned in camelCase\r\n * (e.g. `id`, `className`, `lastMod`). Navigation property sub-keys use\r\n * `{ id, relClassName }` instead of `{ Id, RelECClassId }`.\r\n * @deprecated We should stick to ECProperty names as is instead.\r\n */\r\n useJsName?: boolean;\r\n}\r\n\r\n// ---------------------------------------------------------------------------\r\n// Public interfaces\r\n// ---------------------------------------------------------------------------\r\n\r\n/**\r\n * Metadata attached to every [[ChangeInstance]].\r\n * @beta\r\n */\r\nexport interface ChangeMeta {\r\n /** SQLite tables that contributed columns to this change row. */\r\n tables: string[];\r\n /** Operation that produced this change. */\r\n op: SqliteChangeOp;\r\n /** Whether this is the pre-change (`\"Old\"`) or post-change (`\"New\"`) snapshot. */\r\n stage: SqliteValueStage;\r\n /** Change-stream index positions. */\r\n changeIndexes: number[];\r\n /**\r\n * ECInstanceId and class Id in format \"<ECInstanceId>-<ECClassId>\".\r\n */\r\n instanceKey: string;\r\n /** Reader property filter that was active when this change row was captured. */\r\n propFilter: PropertyFilter;\r\n /** EC property names fetched from the current row of changeset or transaction or any other change stream.\r\n For compound data properties like point2d, point3d or navigation properties,\r\n the full name of the property is returned in case all the components of the property are fetched from the change.\r\n If all of the components are not fetched from the changes(meaning they did not change),\r\n then the individual component names which changed are returned smartly by using `.` as a separator (e.g. \"MyPoint.X\", \"MyPoint.Y\" for a point3d property \"MyPoint\" if only X and Y changed).\r\n For struct properties the property names are always returned in the \"StructProp.MemberName\" format.\r\n So if only X changed for a point2d property named \"Myp2d\" inide a struct \"CustomStruct\", the returned property name will be \"CustomStruct.Myp2d.X\".\r\n Similaly if both X and Y changed for the same point2d property, the returned property name will be \"CustomStruct.Myp2d\". */\r\n changeFetchedPropNames: string[];\r\n /** Row adaptor options that were active when this change row was captured. */\r\n rowOptions?: RowFormatOptions;\r\n /** `true` when the change was applied indirectly */\r\n isIndirectChange: boolean;\r\n}\r\n\r\n/**\r\n * An EC instance produced by [ChangesetReader]($backend) after each `step()`.\r\n * Contains the EC property bag plus mandatory `$meta` metadata.\r\n * @beta\r\n */\r\nexport interface ChangeInstance {\r\n /** Metadata describing the origin and identity of this change. */\r\n $meta: ChangeMeta;\r\n /** EC property bag (ECClassId, ECInstanceId, user-defined properties, ...). */\r\n [key: string]: any;\r\n}\r\n\r\n/**\r\n * Contract for any reader that produces EC-typed changed instances compatible with\r\n * [PartialChangeUnifier]($backend).\r\n * @beta\r\n */\r\nexport interface ChangeSource {\r\n /** The SQLite opcode of the current change row. */\r\n readonly op: SqliteChangeOp;\r\n /**\r\n * The newly-inserted or post-update EC instance.\r\n * `undefined` when the current row is a Delete, or when `isECTable` is `false`.\r\n */\r\n readonly inserted?: ChangeInstance;\r\n /**\r\n * The deleted or pre-update EC instance.\r\n * `undefined` when the current row is an Insert, or when `isECTable` is `false`.\r\n */\r\n readonly deleted?: ChangeInstance;\r\n}\r\n\r\n// ---------------------------------------------------------------------------\r\n// ChangesetReader args / options\r\n// ---------------------------------------------------------------------------\r\n\r\n/**\r\n * Arguments common to all [ChangesetReader]($backend) `open*` factory methods.\r\n * @beta\r\n */\r\nexport interface ChangesetReaderArgs {\r\n /** The db used to resolve EC schema. Must be at or ahead of the changeset being read. */\r\n readonly db: AnyDb;\r\n /** invert the changeset operations */\r\n readonly invert?: boolean;\r\n /** Row adaptor options controlling how EC property values are formatted. */\r\n readonly rowOptions?: RowFormatOptions;\r\n /** Controls which properties are included in the change output. Defaults to PropertyFilter.All. */\r\n readonly propFilter?: PropertyFilter;\r\n}"]}
1
+ {"version":3,"file":"ChangesetReaderTypes.js","sourceRoot":"","sources":["../../src/ChangesetReaderTypes.ts"],"names":[],"mappings":";;;AASA,8EAA8E;AAC9E,eAAe;AACf,8EAA8E;AAE9E;;;GAGG;AACH,IAAY,cAaX;AAbD,WAAY,cAAc;IACxB,kDAAkD;IAClD,iDAAO,CAAA;IACP;;;uBAGmB;IACnB,uEAAkB,CAAA;IAClB,2CAA2C;IAC3C,iEAAe,CAAA;IACf;2HACuH;IACvH,6FAA6B,CAAA;AAC/B,CAAC,EAbW,cAAc,8BAAd,cAAc,QAazB","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module ECDb\r\n */\r\nimport { AnyDb, SqliteChangeOp, SqliteValueStage } from \"./SqliteChangesetReader\";\r\n\r\n// ---------------------------------------------------------------------------\r\n// Type aliases\r\n// ---------------------------------------------------------------------------\r\n\r\n/**\r\n * Controls which properties are included in the output of [ChangesetReader]($backend).\r\n * @beta\r\n */\r\nexport enum PropertyFilter {\r\n /** All EC properties mapped to changed tables. */\r\n All = 0,\r\n /** For classes whose base class is `BisCore:Element`, only `BisCore:Element` properties\r\n * mapped to changed tables are returned. If no `BisCore:Element` class property changed,\r\n * only `ECInstanceId` and `ECClassId` are returned. For other classes all mapped properties\r\n * are returned. */\r\n BisCoreElement = 1,\r\n /** Only `ECInstanceId` and `ECClassId`. */\r\n InstanceKey = 2,\r\n /** `ECInstanceId` and `ECClassId`, plus identifiers read only from the changeset, such as an aspect's owning `Element`.\r\n * See [the full list]($docs/learning/backend/ChangesetReader.md#identifiers-returned-by-instancekeyandidentifiers). */\r\n InstanceKeyAndIdentifiers = 3,\r\n}\r\n\r\n/**\r\n * Row-formatting options for [ChangesetReader]($backend) factory methods.\r\n * Controls how EC property values are represented in the returned instances.\r\n * @beta\r\n */\r\nexport interface RowFormatOptions {\r\n /**\r\n * When `false`, binary properties are returned as full `Uint8Array` values.\r\n * When `true` (or omitted), binary properties are summarized as `{ bytes: N }`.\r\n */\r\n abbreviateBlobs?: boolean;\r\n /**\r\n * When `true`, all classId values are converted from hex strings\r\n * to fully-qualified class names (e.g. `\"BisCore.DrawingModel\"`).\r\n */\r\n classIdsToClassNames?: boolean;\r\n /**\r\n * When `true`, all property keys and struct sub-keys are returned in camelCase\r\n * (e.g. `id`, `className`, `lastMod`). Navigation property sub-keys use\r\n * `{ id, relClassName }` instead of `{ Id, RelECClassId }`.\r\n * @deprecated We should stick to ECProperty names as is instead.\r\n */\r\n useJsName?: boolean;\r\n}\r\n\r\n// ---------------------------------------------------------------------------\r\n// Public interfaces\r\n// ---------------------------------------------------------------------------\r\n\r\n/**\r\n * Metadata attached to every [[ChangeInstance]].\r\n * @beta\r\n */\r\nexport interface ChangeMeta {\r\n /** SQLite tables that contributed columns to this change row. */\r\n tables: string[];\r\n /** Operation that produced this change. */\r\n op: SqliteChangeOp;\r\n /** Whether this is the pre-change (`\"Old\"`) or post-change (`\"New\"`) snapshot. */\r\n stage: SqliteValueStage;\r\n /** Change-stream index positions. */\r\n changeIndexes: number[];\r\n /**\r\n * ECInstanceId and class Id in format \"<ECInstanceId>-<ECClassId>\".\r\n */\r\n instanceKey: string;\r\n /** Reader property filter that was active when this change row was captured. */\r\n propFilter: PropertyFilter;\r\n /** EC property names fetched from the current row of changeset or transaction or any other change stream.\r\n For compound data properties like point2d, point3d or navigation properties,\r\n the full name of the property is returned in case all the components of the property are fetched from the change.\r\n If all of the components are not fetched from the changes(meaning they did not change),\r\n then the individual component names which changed are returned smartly by using `.` as a separator (e.g. \"MyPoint.X\", \"MyPoint.Y\" for a point3d property \"MyPoint\" if only X and Y changed).\r\n For struct properties the property names are always returned in the \"StructProp.MemberName\" format.\r\n So if only X changed for a point2d property named \"Myp2d\" inide a struct \"CustomStruct\", the returned property name will be \"CustomStruct.Myp2d.X\".\r\n Similaly if both X and Y changed for the same point2d property, the returned property name will be \"CustomStruct.Myp2d\". */\r\n changeFetchedPropNames: string[];\r\n /** Row adaptor options that were active when this change row was captured. */\r\n rowOptions?: RowFormatOptions;\r\n /** `true` when the change was applied indirectly */\r\n isIndirectChange: boolean;\r\n}\r\n\r\n/**\r\n * An EC instance produced by [ChangesetReader]($backend) after each `step()`.\r\n * Contains the EC property bag plus mandatory `$meta` metadata.\r\n * @beta\r\n */\r\nexport interface ChangeInstance {\r\n /** Metadata describing the origin and identity of this change. */\r\n $meta: ChangeMeta;\r\n /** EC property bag (ECClassId, ECInstanceId, user-defined properties, ...). */\r\n [key: string]: any;\r\n}\r\n\r\n/**\r\n * Contract for any reader that produces EC-typed changed instances compatible with\r\n * [PartialChangeUnifier]($backend).\r\n * @beta\r\n */\r\nexport interface ChangeSource {\r\n /** The SQLite opcode of the current change row. */\r\n readonly op: SqliteChangeOp;\r\n /**\r\n * The newly-inserted or post-update EC instance.\r\n * `undefined` when the current row is a Delete, or when `isECTable` is `false`.\r\n */\r\n readonly inserted?: ChangeInstance;\r\n /**\r\n * The deleted or pre-update EC instance.\r\n * `undefined` when the current row is an Insert, or when `isECTable` is `false`.\r\n */\r\n readonly deleted?: ChangeInstance;\r\n}\r\n\r\n// ---------------------------------------------------------------------------\r\n// ChangesetReader args / options\r\n// ---------------------------------------------------------------------------\r\n\r\n/**\r\n * Arguments common to all [ChangesetReader]($backend) `open*` factory methods.\r\n * @beta\r\n */\r\nexport interface ChangesetReaderArgs {\r\n /** The db used to resolve EC schema. Must be at or ahead of the changeset being read. */\r\n readonly db: AnyDb;\r\n /** invert the changeset operations */\r\n readonly invert?: boolean;\r\n /** Row adaptor options controlling how EC property values are formatted. */\r\n readonly rowOptions?: RowFormatOptions;\r\n /** Controls which properties are included in the change output. Defaults to PropertyFilter.All. */\r\n readonly propFilter?: PropertyFilter;\r\n}"]}
package/lib/cjs/ECDb.d.ts CHANGED
@@ -260,11 +260,13 @@ export declare class ECDb implements Disposable {
260
260
  prepareSqliteStatement(sql: string, logErrors?: boolean): SqliteStatement;
261
261
  /** @internal */
262
262
  get [_nativeDb](): IModelJsNative.ECDb;
263
- /** Allow to execute query and read results along with meta data. The result are streamed.
263
+ /** Creates a reader for asynchronous ECSQL query execution.
264
+ * Execution starts when the reader is consumed using asynchronous iteration or awaited calls to `step()` or `toArray()`.
265
+ * Results are fetched and buffered in batches. For synchronous, callback-scoped execution, use [[withQueryReader]].
264
266
  *
265
267
  * See also:
266
- * - [ECSQL Overview]($docs/learning/backend/ExecutingECSQL)
267
- * - [Code Examples]($docs/learning/backend/ECSQLCodeExamples)
268
+ * - [Choosing a query reader]($docs/learning/backend/ExecutingECSQL)
269
+ * - [Asynchronous query examples]($docs/learning/ECSQLCodeExamples)
268
270
  * - [ECSQL Row Format]($docs/learning/ECSQLRowFormat)
269
271
  *
270
272
  * @param params The values to bind to the parameters (if the ECSQL has any).
@@ -273,11 +275,14 @@ export declare class ECDb implements Disposable {
273
275
  * @public
274
276
  * */
275
277
  createQueryReader(ecsql: string, params?: QueryBinder, config?: QueryOptions): ECSqlReader;
276
- /** Allow to execute query and read results along with meta data. The result are stepped one by one.
278
+ /** Executes a callback with a synchronous ECSQL reader on the owning database connection.
279
+ * The reader steps one row at a time without buffering result batches. Finish using it before the callback completes.
280
+ * Return materialized rows or computed values rather than the reader. For asynchronous execution, use [[createQueryReader]].
281
+ * The prepared statement may be reused from the statement cache between completed calls.
277
282
  *
278
283
  * See also:
279
- * - [ECSQL Overview]($docs/learning/backend/ExecutingECSQL)
280
- * - [Code Examples]($docs/learning/backend/ECSQLCodeExamples)
284
+ * - [Choosing a query reader]($docs/learning/backend/ExecutingECSQL)
285
+ * - [Synchronous query examples]($docs/learning/backend/WithQueryReaderCodeExamples)
281
286
  * - [ECSQL Row Format]($docs/learning/ECSQLRowFormat)
282
287
  * @param ecsql The ECSQL query to execute.
283
288
  * @param callback the callback to invoke on the prepared ECSqlSyncReader
@@ -1 +1 @@
1
- {"version":3,"file":"ECDb.d.ts","sourceRoot":"","sources":["../../src/ECDb.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,OAAO,EAAU,OAAO,EAA8B,MAAM,qBAAqB,CAAC;AAClF,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CA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S,UAAO,GAAG,CAAC;IAiB/G;;;;;;;;;OASG;IACI,mBAAmB,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,CAAC,EAAE,SAAS,UAAO,GAAG,CAAC;IAiBvG;;;;;OAKG;IACI,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,UAAO,GAAG,eAAe;IAM7E,gBAAgB;IAChB,IAAW,CAAC,SAAS,CAAC,IAAI,cAAc,CAAC,IAAI,CAG5C;IAED;;;;;;;;;;;;;SAaK;IACE,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,EAAE,YAAY,GAAG,WAAW;IAYjG;;;;;;;;;;;;;;;;SAgBK;IACE,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,MAAM,EAAE,eAAe,KAAK,CAAC,EAAE,MAAM,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,EAAE,uBAAuB,GAAG,CAAC;CAyB9I"}
package/lib/cjs/ECDb.js CHANGED
@@ -476,11 +476,13 @@ class ECDb {
476
476
  (0, core_bentley_1.assert)(undefined !== this._nativeDb);
477
477
  return this._nativeDb;
478
478
  }
479
- /** Allow to execute query and read results along with meta data. The result are streamed.
479
+ /** Creates a reader for asynchronous ECSQL query execution.
480
+ * Execution starts when the reader is consumed using asynchronous iteration or awaited calls to `step()` or `toArray()`.
481
+ * Results are fetched and buffered in batches. For synchronous, callback-scoped execution, use [[withQueryReader]].
480
482
  *
481
483
  * See also:
482
- * - [ECSQL Overview]($docs/learning/backend/ExecutingECSQL)
483
- * - [Code Examples]($docs/learning/backend/ECSQLCodeExamples)
484
+ * - [Choosing a query reader]($docs/learning/backend/ExecutingECSQL)
485
+ * - [Asynchronous query examples]($docs/learning/ECSQLCodeExamples)
484
486
  * - [ECSQL Row Format]($docs/learning/ECSQLRowFormat)
485
487
  *
486
488
  * @param params The values to bind to the parameters (if the ECSQL has any).
@@ -499,11 +501,14 @@ class ECDb {
499
501
  };
500
502
  return new core_common_1.ECSqlReader(executor, ecsql, params, config);
501
503
  }
502
- /** Allow to execute query and read results along with meta data. The result are stepped one by one.
504
+ /** Executes a callback with a synchronous ECSQL reader on the owning database connection.
505
+ * The reader steps one row at a time without buffering result batches. Finish using it before the callback completes.
506
+ * Return materialized rows or computed values rather than the reader. For asynchronous execution, use [[createQueryReader]].
507
+ * The prepared statement may be reused from the statement cache between completed calls.
503
508
  *
504
509
  * See also:
505
- * - [ECSQL Overview]($docs/learning/backend/ExecutingECSQL)
506
- * - [Code Examples]($docs/learning/backend/ECSQLCodeExamples)
510
+ * - [Choosing a query reader]($docs/learning/backend/ExecutingECSQL)
511
+ * - [Synchronous query examples]($docs/learning/backend/WithQueryReaderCodeExamples)
507
512
  * - [ECSQL Row Format]($docs/learning/ECSQLRowFormat)
508
513
  * @param ecsql The ECSQL query to execute.
509
514
  * @param callback the callback to invoke on the prepared ECSqlSyncReader
@@ -1 +1 @@
1
- {"version":3,"file":"ECDb.js","sourceRoot":"","sources":["../../src/ECDb.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F;;GAEG;AACH,sDAAkF;AAElF,oDAAwH;AACxH,qCAAoC;AACpC,mEAAgE;AAChE,uDAAoD;AACpD,qDAAuE;AACvE,8DAAyD;AACzD,uDAAoE;AACpE,gDAA+C;AAC/C,yDAA6E;AAC7E,uDAA6E;AAE7E,MAAM,cAAc,GAAW,6CAAqB,CAAC,IAAI,CAAC;AAgC1D,SAAS,kBAAkB,CAAC,OAAoC;IAC9D,IAAI,CAAC,KAAK,OAAO,CAAC,MAAM;QACtB,MAAM,IAAI,SAAS,CAAC,2BAA2B,CAAC,CAAC;IAEnD,MAAM,aAAa,GAAG,IAAI,GAAG,EAAU,CAAC;IACxC,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,IAAI,SAA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E,QAAQ,CAAC,iBAAiB,CAAC,CAAC;QAChG,CAAC,CAAC;QACF,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAI,iCAAe,CAAC,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;YACpE,MAAM,GAAG,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;YAC7B,IAAI,GAAG,YAAY,OAAO,EAAE,CAAC;gBAC3B,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC7B,CAAC;iBAAM,CAAC;gBACN,OAAO,EAAE,CAAC;YACZ,CAAC;YACD,OAAO,GAAG,CAAC;QACb,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,OAAO,EAAE,CAAC;YACV,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAAC;CACF;AA3fD,oBA2fC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module ECDb\r\n */\r\nimport { assert, BeEvent, DbResult, Logger, OpenMode } from \"@itwin/core-bentley\";\r\nimport { IModelJsNative } from \"@bentley/imodeljs-native\";\r\nimport { DbQueryRequest, ECSchemaProps, ECSqlReader, IModelError, QueryBinder, QueryOptions } from \"@itwin/core-common\";\r\nimport { serialize } from \"node:v8\";\r\nimport { BackendLoggerCategory } from \"./BackendLoggerCategory\";\r\nimport { ConcurrentQuery } from \"./ConcurrentQuery\";\r\nimport { ECSqlStatement, ECSqlWriteStatement } from \"./ECSqlStatement\";\r\nimport { IModelNative } from \"./internal/NativePlatform\";\r\nimport { SqliteStatement, StatementCache } from \"./SqliteStatement\";\r\nimport { _nativeDb } from \"./internal/Symbols\";\r\nimport { ECSqlRowExecutor, releaseECSqlStatement } from \"./ECSqlRowExecutor\";\r\nimport { ECSqlSyncReader, SynchronousQueryOptions } from \"./ECSqlSyncReader\";\r\n\r\nconst loggerCategory: string = BackendLoggerCategory.ECDb;\r\n\r\n/** Maps a zero-based CSV column to an EC property.\r\n * @beta\r\n */\r\nexport interface CSVColumnMapping {\r\n /** Zero-based index of the source CSV column. */\r\n columnIndex: number;\r\n /** EC property access string to receive the column value. */\r\n propertyName: string;\r\n}\r\n\r\n/** Common options for importing CSV data into an ECClass.\r\n * @beta\r\n */\r\nexport interface CSVImportOptions {\r\n /** Full name or ECSQL name of the ECClass to insert. */\r\n className: string;\r\n /** Source-column to EC-property mappings. Unmapped source columns are ignored. */\r\n mapping: readonly CSVColumnMapping[];\r\n /** Exact CSV value to bind as null. By default, every field is treated as a value. */\r\n nullValue?: string;\r\n}\r\n\r\n/** Options for [[ECDb.importCSVFile]].\r\n * @beta\r\n */\r\nexport interface CSVFileImportOptions extends CSVImportOptions {\r\n /** Whether the first CSV row is a header to skip. Defaults to false. */\r\n hasHeader?: boolean;\r\n}\r\n\r\nfunction validateCSVMapping(mapping: readonly CSVColumnMapping[]): void {\r\n if (0 === mapping.length)\r\n throw new TypeError(\"mapping must not be empty\");\r\n\r\n const columnIndexes = new Set<number>();\r\n for (const entry of mapping) {\r\n if (undefined === entry || null === entry || \"object\" !== typeof entry)\r\n throw new TypeError(\"mapping must contain only objects\");\r\n if (!Number.isSafeInteger(entry.columnIndex) || entry.columnIndex < 0 || entry.columnIndex >= 0xffff_ffff)\r\n throw new TypeError(\"mapping columnIndex values must be non-negative safe integers\");\r\n if (\"string\" !== typeof entry.propertyName || 0 === entry.propertyName.length)\r\n throw new TypeError(\"mapping propertyName values must not be empty\");\r\n if (columnIndexes.has(entry.columnIndex))\r\n throw new TypeError(\"mapping must not contain duplicate columnIndex values\");\r\n columnIndexes.add(entry.columnIndex);\r\n }\r\n}\r\n\r\n/** Modes for how to open [ECDb]($backend) files.\r\n * @public\r\n */\r\nexport enum ECDbOpenMode {\r\n Readonly,\r\n ReadWrite,\r\n /** Opens the file read-write and upgrades the file if necessary to the latest file format version. */\r\n FileUpgrade,\r\n}\r\n\r\n/** An ECDb file\r\n * @public\r\n */\r\nexport class ECDb implements Disposable {\r\n private _nativeDb?: IModelJsNative.ECDb;\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n private readonly _statementCache = new StatementCache<ECSqlStatement>();\r\n private _sqliteStatementCache = new StatementCache<SqliteStatement>();\r\n\r\n /** Event called when the ECDb is about to be closed. */\r\n public readonly onBeforeClose = new BeEvent<() => void>();\r\n\r\n /** only for tests\r\n * @internal\r\n */\r\n public resetSqliteCache(size: number) {\r\n this._sqliteStatementCache.clear();\r\n this._sqliteStatementCache = new StatementCache<SqliteStatement>(size);\r\n }\r\n\r\n constructor() {\r\n this._nativeDb = new IModelNative.platform.ECDb();\r\n }\r\n /** Call this function when finished with this ECDb object. This releases the native resources held by the\r\n * ECDb object.\r\n */\r\n public [Symbol.dispose](): void {\r\n if (!this._nativeDb)\r\n return;\r\n\r\n this.closeDb();\r\n this._nativeDb.dispose();\r\n this._nativeDb = undefined;\r\n }\r\n /**\r\n * Attach an iModel file to this connection and load and register its schemas.\r\n * @note There are some reserve tablespace names that cannot be used. They are 'main', 'schema_sync_db', 'ecchange' & 'temp'\r\n * @param fileName IModel file name\r\n * @param alias identifier for the attached file. This identifer is used to access schema from the attached file. e.g. if alias is 'abc' then schema can be accessed using 'abc.MySchema.MyClass'\r\n */\r\n public attachDb(fileName: string, alias: string): void {\r\n if (alias.toLowerCase() === \"main\" || alias.toLowerCase() === \"schema_sync_db\" || alias.toLowerCase() === \"ecchange\" || alias.toLowerCase() === \"temp\") {\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Reserved tablespace name cannot be used\");\r\n }\r\n this[_nativeDb].attachDb(fileName, alias);\r\n }\r\n /**\r\n * Detach the attached file from this connection. The attached file is closed and its schemas are unregistered.\r\n * @note There are some reserve tablespace names that cannot be used. They are 'main', 'schema_sync_db', 'ecchange' & 'temp'\r\n * @param alias identifer that was used in the call to [[attachDb]]\r\n */\r\n public detachDb(alias: string): void {\r\n if (alias.toLowerCase() === \"main\" || alias.toLowerCase() === \"schema_sync_db\" || alias.toLowerCase() === \"ecchange\" || alias.toLowerCase() === \"temp\") {\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Reserved tablespace name cannot be used\");\r\n }\r\n this.clearCaches();\r\n this[_nativeDb].detachDb(alias);\r\n }\r\n\r\n /** @deprecated in 5.0 - might be removed in next major version. Use [Symbol.dispose] instead. */\r\n public dispose(): void {\r\n this[Symbol.dispose]();\r\n }\r\n\r\n /** Create an ECDb\r\n * @param pathName The path to the ECDb file to create.\r\n * @throws [IModelError]($common) if the operation failed.\r\n */\r\n public createDb(pathName: string): void {\r\n const status: DbResult = this[_nativeDb].createDb(pathName);\r\n if (status !== DbResult.BE_SQLITE_OK)\r\n throw new IModelError(status, \"Failed to created ECDb\");\r\n }\r\n\r\n /** Open the ECDb.\r\n * @param pathName The path to the ECDb file to open\r\n * @param openMode Open mode\r\n * @throws [IModelError]($common) if the operation failed.\r\n */\r\n public openDb(pathName: string, openMode: ECDbOpenMode = ECDbOpenMode.Readonly): void {\r\n const nativeOpenMode: OpenMode = openMode === ECDbOpenMode.Readonly ? OpenMode.Readonly : OpenMode.ReadWrite;\r\n const tryUpgrade: boolean = openMode === ECDbOpenMode.FileUpgrade;\r\n const status: DbResult = this[_nativeDb].openDb(pathName, nativeOpenMode, tryUpgrade);\r\n if (status !== DbResult.BE_SQLITE_OK)\r\n throw new IModelError(status, \"Failed to open ECDb\");\r\n }\r\n\r\n /** Returns true if the ECDb is open */\r\n public get isOpen(): boolean { return this[_nativeDb].isOpen(); }\r\n\r\n /** Close the Db after saving any uncommitted changes.\r\n * @throws [IModelError]($common) if the database is not open.\r\n */\r\n public closeDb(): void {\r\n this.onBeforeClose.raiseEvent();\r\n this.clearCaches();\r\n this[_nativeDb].closeDb();\r\n }\r\n\r\n /** Clear all in-memory caches held in this ECDb.\r\n * @beta\r\n */\r\n public clearCaches(): void {\r\n this._statementCache.clear();\r\n this._sqliteStatementCache.clear();\r\n this[_nativeDb].clearECDbCache();\r\n }\r\n\r\n /** @internal use to test statement caching */\r\n public clearStatementCache() {\r\n this._statementCache.clear();\r\n }\r\n\r\n /** @internal use to test statement caching */\r\n public getCachedStatementCount() {\r\n return this._statementCache.size;\r\n }\r\n\r\n /** Commit the outermost transaction, writing changes to the file. Then, restart the transaction.\r\n * @param changesetName The name of the operation that generated these changes.\r\n * @throws [IModelError]($common) if the database is not open or if the operation failed.\r\n */\r\n public saveChanges(changesetName?: string): void {\r\n const status: DbResult = this[_nativeDb].saveChanges(changesetName);\r\n if (status !== DbResult.BE_SQLITE_OK)\r\n throw new IModelError(status, \"Failed to save changes\");\r\n }\r\n\r\n /** Abandon (cancel) the outermost transaction, discarding all changes since last save. Then, restart the transaction.\r\n * @throws [IModelError]($common) if the database is not open or if the operation failed.\r\n */\r\n public abandonChanges(): void {\r\n const status: DbResult = this[_nativeDb].abandonChanges();\r\n if (status !== DbResult.BE_SQLITE_OK)\r\n throw new IModelError(status, \"Failed to abandon changes\");\r\n }\r\n\r\n /** Import a schema.\r\n *\r\n * If the import was successful, the database is automatically saved to disk.\r\n * @param pathName Path to ECSchema XML file to import.\r\n * @throws [IModelError]($common) if the database is not open or if the operation failed.\r\n */\r\n public importSchema(pathName: string): void {\r\n const status: DbResult = this[_nativeDb].importSchema(pathName);\r\n if (status !== DbResult.BE_SQLITE_OK) {\r\n Logger.logError(loggerCategory, `Failed to import schema from '${pathName}'.`);\r\n throw new IModelError(status, `Failed to import schema from '${pathName}'.`);\r\n }\r\n this.clearCaches();\r\n }\r\n\r\n /** Removes unused schemas from the database.\r\n *\r\n * If the removal was successful, the database is automatically saved to disk.\r\n * @param schemaNames Array of schema names to drop\r\n * @throws [IModelError]($common) if the database if the operation failed.\r\n * @alpha\r\n */\r\n public dropSchemas(schemaNames: string[]): void {\r\n if (schemaNames.length === 0)\r\n return;\r\n // SchemaSync.isEnabled() should be used, but ECDb is not an iModelDb so it has no container props\r\n if (this[_nativeDb].schemaSyncEnabled())\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Cannot drop schemas when schema sync is enabled\");\r\n\r\n try {\r\n this[_nativeDb].dropSchemas(schemaNames);\r\n this.saveChanges('dropped unused schemas');\r\n } catch (error: any) {\r\n Logger.logError(loggerCategory, `Failed to drop schemas: ${error}`);\r\n this.abandonChanges();\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, `Failed to drop schemas: ${error}`);\r\n } finally {\r\n this.clearCaches();\r\n }\r\n }\r\n\r\n /**\r\n * Returns the full schema for the input name.\r\n * @param name The name of the schema e.g. 'ECDbMeta'\r\n * @returns The SchemaProps for the requested schema\r\n * @throws if the schema can not be found or loaded.\r\n */\r\n public getSchemaProps(name: string): ECSchemaProps {\r\n return this[_nativeDb].getSchemaProps(name);\r\n }\r\n\r\n /** Import in-memory CSV rows into an ECClass.\r\n *\r\n * The rows are V8-serialized and processed in one native call. Values are converted from\r\n * their CSV string representation according to the mapped EC property type. One ECSQL\r\n * statement is reused for all rows. Every row must have the same number of columns.\r\n * Boolean fields accept `true`, `false`, `1`, or `0`. Integer fields must contain a\r\n * base-10 value in the signed 32-bit range. Boolean, double, integer, and string EC\r\n * properties are supported. The import is all-or-nothing and callers must call\r\n * [[saveChanges]] to commit it to disk.\r\n * @returns The number of imported rows.\r\n * @beta\r\n */\r\n public importCSVData(rows: readonly (readonly string[])[], options: CSVImportOptions): number {\r\n validateCSVMapping(options.mapping);\r\n return this[_nativeDb].importCSVData(options.className, serialize(rows), options.mapping, { nullValue: options.nullValue });\r\n }\r\n\r\n /** Stream a CSV file into an ECClass.\r\n *\r\n * The file must be UTF-8 encoded; an optional UTF-8 byte-order mark is accepted. It is read\r\n * and parsed in native code, and one ECSQL statement is reused for all rows. Every record must\r\n * have the same number of columns; blank records are not skipped. Boolean fields accept\r\n * `true`, `false`, `1`, or `0`. Integer fields must contain a base-10 value in the signed\r\n * 32-bit range. Boolean, double, integer, and string EC properties are supported. The import\r\n * is all-or-nothing and callers must call [[saveChanges]] to commit it to disk.\r\n * @returns The number of imported rows, excluding an optional header.\r\n * @beta\r\n */\r\n public importCSVFile(csvFilePath: string, options: CSVFileImportOptions): number {\r\n validateCSVMapping(options.mapping);\r\n return this[_nativeDb].importCSVFile(options.className, csvFilePath, options.mapping, {\r\n hasHeader: options.hasHeader,\r\n nullValue: options.nullValue,\r\n });\r\n }\r\n\r\n /**\r\n * Use a prepared ECSQL statement, potentially from the statement cache. If the requested statement doesn't exist\r\n * in the statement cache, a new statement is prepared. After the callback completes, the statement is reset and saved\r\n * in the statement cache so it can be reused in the future. Use this method for ECSQL statements that will be\r\n * reused often and are expensive to prepare. The statement cache holds the most recently used statements, discarding\r\n * the oldest statements as it fills. For statements you don't intend to reuse, instead use [[withStatement]].\r\n * @param sql The SQLite SQL statement to execute\r\n * @param callback the callback to invoke on the prepared statement\r\n * @param logErrors Determines if error will be logged if statement fail to prepare\r\n * @returns the value returned by `callback`.\r\n * @see [[withWriteStatement]]\r\n * @beta\r\n */\r\n public withCachedWriteStatement<T>(ecsql: string, callback: (stmt: ECSqlWriteStatement) => T, logErrors = true): T {\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n const stmt = this._statementCache.findAndRemove(ecsql) ?? this.prepareStatement(ecsql, logErrors);\r\n const release = () => this._statementCache.addOrDispose(stmt);\r\n try {\r\n const val = callback(new ECSqlWriteStatement(stmt));\r\n if (val instanceof Promise) {\r\n val.then(release, release);\r\n } else {\r\n release();\r\n }\r\n return val;\r\n } catch (err) {\r\n release();\r\n throw err;\r\n }\r\n }\r\n\r\n /**\r\n * Prepared and execute a callback on an ECSQL statement. After the callback completes the statement is disposed.\r\n * Use this method for ECSQL statements are either not expected to be reused, or are not expensive to prepare.\r\n * For statements that will be reused often, instead use [[withPreparedStatement]].\r\n * @param sql The SQLite SQL statement to execute\r\n * @param callback the callback to invoke on the prepared statement\r\n * @param logErrors Determines if error will be logged if statement fail to prepare\r\n * @returns the value returned by `callback`.\r\n * @see [[withCachedWriteStatement]]\r\n * @beta\r\n */\r\n public withWriteStatement<T>(ecsql: string, callback: (stmt: ECSqlWriteStatement) => T, logErrors = true): T {\r\n const stmt = this.prepareWriteStatement(ecsql, logErrors);\r\n const release = () => stmt[Symbol.dispose]();\r\n try {\r\n const val = callback(stmt);\r\n if (val instanceof Promise) {\r\n val.then(release, release);\r\n } else {\r\n release();\r\n }\r\n return val;\r\n } catch (err) {\r\n release();\r\n throw err;\r\n }\r\n }\r\n\r\n /** Prepare an ECSQL statement.\r\n * @param ecsql The ECSQL statement to prepare\r\n * @param logErrors Determines if error will be logged if statement fail to prepare\r\n * @throws [IModelError]($common) if there is a problem preparing the statement.\r\n * @beta\r\n */\r\n public prepareWriteStatement(ecsql: string, logErrors = true): ECSqlWriteStatement {\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n return new ECSqlWriteStatement(this.prepareStatement(ecsql, logErrors));\r\n }\r\n\r\n /**\r\n * Use a prepared ECSQL statement, potentially from the statement cache. If the requested statement doesn't exist\r\n * in the statement cache, a new statement is prepared. After the callback completes, the statement is reset and saved\r\n * in the statement cache so it can be reused in the future. Use this method for ECSQL statements that will be\r\n * reused often and are expensive to prepare. The statement cache holds the most recently used statements, discarding\r\n * the oldest statements as it fills. For statements you don't intend to reuse, instead use [[withStatement]].\r\n * @param sql The SQLite SQL statement to execute\r\n * @param callback the callback to invoke on the prepared statement\r\n * @param logErrors Determines if error will be logged if statement fail to prepare\r\n * @returns the value returned by `callback`.\r\n * @see [[withStatement]]\r\n * @public\r\n * @deprecated in 4.11 - might be removed in next major version. Use [[createQueryReader]] for SELECT statements and [[withCachedWriteStatement]] for INSERT/UPDATE/DELETE instead.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n public withPreparedStatement<T>(ecsql: string, callback: (stmt: ECSqlStatement) => T, logErrors = true): T {\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n const stmt = this._statementCache.findAndRemove(ecsql) ?? this.prepareStatement(ecsql, logErrors);\r\n const release = () => this._statementCache.addOrDispose(stmt);\r\n try {\r\n const val = callback(stmt);\r\n if (val instanceof Promise) {\r\n val.then(release, release);\r\n } else {\r\n release();\r\n }\r\n return val;\r\n } catch (err) {\r\n release();\r\n throw err;\r\n }\r\n }\r\n\r\n /**\r\n * Prepared and execute a callback on an ECSQL statement. After the callback completes the statement is disposed.\r\n * Use this method for ECSQL statements are either not expected to be reused, or are not expensive to prepare.\r\n * For statements that will be reused often, instead use [[withPreparedStatement]].\r\n * @param sql The SQLite SQL statement to execute\r\n * @param callback the callback to invoke on the prepared statement\r\n * @param logErrors Determines if error will be logged if statement fail to prepare\r\n * @returns the value returned by `callback`.\r\n * @see [[withPreparedStatement]]\r\n * @public\r\n * @deprecated in 4.11 - might be removed in next major version. Use [[createQueryReader]] for SELECT statements and [[withWriteStatement]] for INSERT/UPDATE/DELETE instead.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n public withStatement<T>(ecsql: string, callback: (stmt: ECSqlStatement) => T, logErrors = true): T {\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n const stmt = this.prepareStatement(ecsql, logErrors);\r\n const release = () => stmt[Symbol.dispose]();\r\n try {\r\n const val = callback(stmt);\r\n if (val instanceof Promise) {\r\n val.then(release, release);\r\n } else {\r\n release();\r\n }\r\n return val;\r\n } catch (err) {\r\n release();\r\n throw err;\r\n }\r\n }\r\n\r\n /** Prepare an ECSQL statement.\r\n * @param ecsql The ECSQL statement to prepare\r\n * @param logErrors Determines if error will be logged if statement fail to prepare\r\n * @throws [IModelError]($common) if there is a problem preparing the statement.\r\n * @deprecated in 4.11 - might be removed in next major version. Use [[prepareWriteStatement]] when preparing an INSERT/UPDATE/DELETE statement or [[createQueryReader]] to execute a SELECT statement.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n public prepareStatement(ecsql: string, logErrors = true): ECSqlStatement {\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n const stmt = new ECSqlStatement();\r\n stmt.prepare(this[_nativeDb], ecsql, logErrors);\r\n return stmt;\r\n }\r\n\r\n /**\r\n * Use a prepared SQL statement, potentially from the statement cache. If the requested statement doesn't exist\r\n * in the statement cache, a new statement is prepared. After the callback completes, the statement is reset and saved\r\n * in the statement cache so it can be reused in the future. Use this method for SQL statements that will be\r\n * reused often and are expensive to prepare. The statement cache holds the most recently used statements, discarding\r\n * the oldest statements as it fills. For statements you don't intend to reuse, instead use [[withSqliteStatement]].\r\n * @param sql The SQLite SQL statement to execute\r\n * @param callback the callback to invoke on the prepared statement\r\n * @param logErrors Determines if error will be logged if statement fail to prepare\r\n * @returns the value returned by `callback`.\r\n * @see [[withPreparedStatement]]\r\n * @public\r\n */\r\n public withPreparedSqliteStatement<T>(sql: string, callback: (stmt: SqliteStatement) => T, logErrors = true): T {\r\n const stmt = this._sqliteStatementCache.findAndRemove(sql) ?? this.prepareSqliteStatement(sql, logErrors);\r\n const release = () => this._sqliteStatementCache.addOrDispose(stmt);\r\n try {\r\n const val: T = callback(stmt);\r\n if (val instanceof Promise) {\r\n val.then(release, release);\r\n } else {\r\n release();\r\n }\r\n return val;\r\n } catch (err) {\r\n release();\r\n throw err;\r\n }\r\n }\r\n\r\n /**\r\n * Prepared and execute a callback on a SQL statement. After the callback completes the statement is disposed.\r\n * Use this method for SQL statements are either not expected to be reused, or are not expensive to prepare.\r\n * For statements that will be reused often, instead use [[withPreparedSqliteStatement]].\r\n * @param sql The SQLite SQL statement to execute\r\n * @param callback the callback to invoke on the prepared statement\r\n * @param logErrors Determines if error will be logged if statement fail to prepare\r\n * @returns the value returned by `callback`.\r\n * @public\r\n */\r\n public withSqliteStatement<T>(sql: string, callback: (stmt: SqliteStatement) => T, logErrors = true): T {\r\n const stmt = this.prepareSqliteStatement(sql, logErrors);\r\n const release = () => stmt[Symbol.dispose]();\r\n try {\r\n const val: T = callback(stmt);\r\n if (val instanceof Promise) {\r\n val.then(release, release);\r\n } else {\r\n release();\r\n }\r\n return val;\r\n } catch (err) {\r\n release();\r\n throw err;\r\n }\r\n }\r\n\r\n /** Prepare an SQL statement.\r\n * @param sql The SQLite SQL statement to prepare\r\n * @param logErrors Determines if error will be logged if statement fail to prepare\r\n * @throws [IModelError]($common) if there is a problem preparing the statement.\r\n * @internal\r\n */\r\n public prepareSqliteStatement(sql: string, logErrors = true): SqliteStatement {\r\n const stmt = new SqliteStatement(sql);\r\n stmt.prepare(this[_nativeDb], logErrors);\r\n return stmt;\r\n }\r\n\r\n /** @internal */\r\n public get [_nativeDb](): IModelJsNative.ECDb {\r\n assert(undefined !== this._nativeDb);\r\n return this._nativeDb;\r\n }\r\n\r\n /** Allow to execute query and read results along with meta data. The result are streamed.\r\n *\r\n * See also:\r\n * - [ECSQL Overview]($docs/learning/backend/ExecutingECSQL)\r\n * - [Code Examples]($docs/learning/backend/ECSQLCodeExamples)\r\n * - [ECSQL Row Format]($docs/learning/ECSQLRowFormat)\r\n *\r\n * @param params The values to bind to the parameters (if the ECSQL has any).\r\n * @param config Allow to specify certain flags which control how query is executed.\r\n * @returns Returns an [ECSqlReader]($common) which helps iterate over the result set and also give access to metadata.\r\n * @public\r\n * */\r\n public createQueryReader(ecsql: string, params?: QueryBinder, config?: QueryOptions): ECSqlReader {\r\n if (!this._nativeDb || !this._nativeDb.isOpen()) {\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR_NOTOPEN, \"db not open\");\r\n }\r\n const executor = {\r\n execute: async (request: DbQueryRequest) => {\r\n return ConcurrentQuery.executeQueryRequest(this[_nativeDb], request);\r\n },\r\n };\r\n return new ECSqlReader(executor, ecsql, params, config);\r\n }\r\n\r\n /** Allow to execute query and read results along with meta data. The result are stepped one by one.\r\n *\r\n * See also:\r\n * - [ECSQL Overview]($docs/learning/backend/ExecutingECSQL)\r\n * - [Code Examples]($docs/learning/backend/ECSQLCodeExamples)\r\n * - [ECSQL Row Format]($docs/learning/ECSQLRowFormat)\r\n * @param ecsql The ECSQL query to execute.\r\n * @param callback the callback to invoke on the prepared ECSqlSyncReader\r\n * @param params The values to bind to the parameters (if the ECSQL has any).\r\n * @param config Optional flags which control how query is executed.\r\n * @returns the value returned by `callback`.\r\n * @throws IModelError if db is not open or if error occurs during statement execution\r\n * @beta\r\n * */\r\n public withQueryReader<T>(ecsql: string, callback: (reader: ECSqlSyncReader) => T, params?: QueryBinder, config?: SynchronousQueryOptions): T {\r\n if (!this[_nativeDb].isOpen())\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR_NOTOPEN, \"db not open\");\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n const stmt = this._statementCache.findAndRemove(ecsql) ?? new ECSqlStatement();\r\n const executor = new ECSqlRowExecutor(this, stmt, loggerCategory);\r\n const release = () => {\r\n executor[Symbol.dispose]();\r\n releaseECSqlStatement(stmt, this._statementCache, loggerCategory, executor.canCacheStatement);\r\n };\r\n try {\r\n const reader = new ECSqlSyncReader(executor, ecsql, params, config);\r\n const val = callback(reader);\r\n if (val instanceof Promise) {\r\n val.then(release, release);\r\n } else {\r\n release();\r\n }\r\n return val;\r\n } catch (err: any) {\r\n release();\r\n throw err;\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"ECDb.js","sourceRoot":"","sources":["../../src/ECDb.ts"],"names":[],"mappings":";;;AAAA;;;+FAG+F;AAC/F;;GAEG;AACH,sDAAkF;AAElF,oDAAwH;AACxH,qCAAoC;AACpC,mEAAgE;AAChE,uDAAoD;AACpD,qDAAuE;AACvE,8DAAyD;AACzD,uDAAoE;AACpE,gDAA+C;AAC/C,yDAA6E;AAC7E,uDAA6E;AAE7E,MAAM,cAAc,GAAW,6CAAqB,CAAC,IAAI,CAAC;AAgC1D,SAAS,kBAAkB,CAAC,OAAoC;IAC9D,IAAI,CAAC,KAAK,OAAO,CAAC,MAAM;QACtB,MAAM,IAAI,SAAS,CAAC,2BAA2B,CAAC,CAAC;IAEnD,MAAM,aAAa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CAAC,OAAO,CAAC,EAAE,CAAC;YAC3B,IAAA,wCAAqB,EAAC,IAAI,EAAE,IAAI,CAAC,eAAe,EAAE,cAAc,EAAE,QAAQ,CAAC,iBAAiB,CAAC,CAAC;QAChG,CAAC,CAAC;QACF,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAI,iCAAe,CAAC,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;YACpE,MAAM,GAAG,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;YAC7B,IAAI,GAAG,YAAY,OAAO,EAAE,CAAC;gBAC3B,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC7B,CAAC;iBAAM,CAAC;gBACN,OAAO,EAAE,CAAC;YACZ,CAAC;YACD,OAAO,GAAG,CAAC;QACb,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,OAAO,EAAE,CAAC;YACV,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAAC;CACF;AAhgBD,oBAggBC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module ECDb\r\n */\r\nimport { assert, BeEvent, DbResult, Logger, OpenMode } from \"@itwin/core-bentley\";\r\nimport { IModelJsNative } from \"@bentley/imodeljs-native\";\r\nimport { DbQueryRequest, ECSchemaProps, ECSqlReader, IModelError, QueryBinder, QueryOptions } from \"@itwin/core-common\";\r\nimport { serialize } from \"node:v8\";\r\nimport { BackendLoggerCategory } from \"./BackendLoggerCategory\";\r\nimport { ConcurrentQuery } from \"./ConcurrentQuery\";\r\nimport { ECSqlStatement, ECSqlWriteStatement } from \"./ECSqlStatement\";\r\nimport { IModelNative } from \"./internal/NativePlatform\";\r\nimport { SqliteStatement, StatementCache } from \"./SqliteStatement\";\r\nimport { _nativeDb } from \"./internal/Symbols\";\r\nimport { ECSqlRowExecutor, releaseECSqlStatement } from \"./ECSqlRowExecutor\";\r\nimport { ECSqlSyncReader, SynchronousQueryOptions } from \"./ECSqlSyncReader\";\r\n\r\nconst loggerCategory: string = BackendLoggerCategory.ECDb;\r\n\r\n/** Maps a zero-based CSV column to an EC property.\r\n * @beta\r\n */\r\nexport interface CSVColumnMapping {\r\n /** Zero-based index of the source CSV column. */\r\n columnIndex: number;\r\n /** EC property access string to receive the column value. */\r\n propertyName: string;\r\n}\r\n\r\n/** Common options for importing CSV data into an ECClass.\r\n * @beta\r\n */\r\nexport interface CSVImportOptions {\r\n /** Full name or ECSQL name of the ECClass to insert. */\r\n className: string;\r\n /** Source-column to EC-property mappings. Unmapped source columns are ignored. */\r\n mapping: readonly CSVColumnMapping[];\r\n /** Exact CSV value to bind as null. By default, every field is treated as a value. */\r\n nullValue?: string;\r\n}\r\n\r\n/** Options for [[ECDb.importCSVFile]].\r\n * @beta\r\n */\r\nexport interface CSVFileImportOptions extends CSVImportOptions {\r\n /** Whether the first CSV row is a header to skip. Defaults to false. */\r\n hasHeader?: boolean;\r\n}\r\n\r\nfunction validateCSVMapping(mapping: readonly CSVColumnMapping[]): void {\r\n if (0 === mapping.length)\r\n throw new TypeError(\"mapping must not be empty\");\r\n\r\n const columnIndexes = new Set<number>();\r\n for (const entry of mapping) {\r\n if (undefined === entry || null === entry || \"object\" !== typeof entry)\r\n throw new TypeError(\"mapping must contain only objects\");\r\n if (!Number.isSafeInteger(entry.columnIndex) || entry.columnIndex < 0 || entry.columnIndex >= 0xffff_ffff)\r\n throw new TypeError(\"mapping columnIndex values must be non-negative safe integers\");\r\n if (\"string\" !== typeof entry.propertyName || 0 === entry.propertyName.length)\r\n throw new TypeError(\"mapping propertyName values must not be empty\");\r\n if (columnIndexes.has(entry.columnIndex))\r\n throw new TypeError(\"mapping must not contain duplicate columnIndex values\");\r\n columnIndexes.add(entry.columnIndex);\r\n }\r\n}\r\n\r\n/** Modes for how to open [ECDb]($backend) files.\r\n * @public\r\n */\r\nexport enum ECDbOpenMode {\r\n Readonly,\r\n ReadWrite,\r\n /** Opens the file read-write and upgrades the file if necessary to the latest file format version. */\r\n FileUpgrade,\r\n}\r\n\r\n/** An ECDb file\r\n * @public\r\n */\r\nexport class ECDb implements Disposable {\r\n private _nativeDb?: IModelJsNative.ECDb;\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n private readonly _statementCache = new StatementCache<ECSqlStatement>();\r\n private _sqliteStatementCache = new StatementCache<SqliteStatement>();\r\n\r\n /** Event called when the ECDb is about to be closed. */\r\n public readonly onBeforeClose = new BeEvent<() => void>();\r\n\r\n /** only for tests\r\n * @internal\r\n */\r\n public resetSqliteCache(size: number) {\r\n this._sqliteStatementCache.clear();\r\n this._sqliteStatementCache = new StatementCache<SqliteStatement>(size);\r\n }\r\n\r\n constructor() {\r\n this._nativeDb = new IModelNative.platform.ECDb();\r\n }\r\n /** Call this function when finished with this ECDb object. This releases the native resources held by the\r\n * ECDb object.\r\n */\r\n public [Symbol.dispose](): void {\r\n if (!this._nativeDb)\r\n return;\r\n\r\n this.closeDb();\r\n this._nativeDb.dispose();\r\n this._nativeDb = undefined;\r\n }\r\n /**\r\n * Attach an iModel file to this connection and load and register its schemas.\r\n * @note There are some reserve tablespace names that cannot be used. They are 'main', 'schema_sync_db', 'ecchange' & 'temp'\r\n * @param fileName IModel file name\r\n * @param alias identifier for the attached file. This identifer is used to access schema from the attached file. e.g. if alias is 'abc' then schema can be accessed using 'abc.MySchema.MyClass'\r\n */\r\n public attachDb(fileName: string, alias: string): void {\r\n if (alias.toLowerCase() === \"main\" || alias.toLowerCase() === \"schema_sync_db\" || alias.toLowerCase() === \"ecchange\" || alias.toLowerCase() === \"temp\") {\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Reserved tablespace name cannot be used\");\r\n }\r\n this[_nativeDb].attachDb(fileName, alias);\r\n }\r\n /**\r\n * Detach the attached file from this connection. The attached file is closed and its schemas are unregistered.\r\n * @note There are some reserve tablespace names that cannot be used. They are 'main', 'schema_sync_db', 'ecchange' & 'temp'\r\n * @param alias identifer that was used in the call to [[attachDb]]\r\n */\r\n public detachDb(alias: string): void {\r\n if (alias.toLowerCase() === \"main\" || alias.toLowerCase() === \"schema_sync_db\" || alias.toLowerCase() === \"ecchange\" || alias.toLowerCase() === \"temp\") {\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Reserved tablespace name cannot be used\");\r\n }\r\n this.clearCaches();\r\n this[_nativeDb].detachDb(alias);\r\n }\r\n\r\n /** @deprecated in 5.0 - might be removed in next major version. Use [Symbol.dispose] instead. */\r\n public dispose(): void {\r\n this[Symbol.dispose]();\r\n }\r\n\r\n /** Create an ECDb\r\n * @param pathName The path to the ECDb file to create.\r\n * @throws [IModelError]($common) if the operation failed.\r\n */\r\n public createDb(pathName: string): void {\r\n const status: DbResult = this[_nativeDb].createDb(pathName);\r\n if (status !== DbResult.BE_SQLITE_OK)\r\n throw new IModelError(status, \"Failed to created ECDb\");\r\n }\r\n\r\n /** Open the ECDb.\r\n * @param pathName The path to the ECDb file to open\r\n * @param openMode Open mode\r\n * @throws [IModelError]($common) if the operation failed.\r\n */\r\n public openDb(pathName: string, openMode: ECDbOpenMode = ECDbOpenMode.Readonly): void {\r\n const nativeOpenMode: OpenMode = openMode === ECDbOpenMode.Readonly ? OpenMode.Readonly : OpenMode.ReadWrite;\r\n const tryUpgrade: boolean = openMode === ECDbOpenMode.FileUpgrade;\r\n const status: DbResult = this[_nativeDb].openDb(pathName, nativeOpenMode, tryUpgrade);\r\n if (status !== DbResult.BE_SQLITE_OK)\r\n throw new IModelError(status, \"Failed to open ECDb\");\r\n }\r\n\r\n /** Returns true if the ECDb is open */\r\n public get isOpen(): boolean { return this[_nativeDb].isOpen(); }\r\n\r\n /** Close the Db after saving any uncommitted changes.\r\n * @throws [IModelError]($common) if the database is not open.\r\n */\r\n public closeDb(): void {\r\n this.onBeforeClose.raiseEvent();\r\n this.clearCaches();\r\n this[_nativeDb].closeDb();\r\n }\r\n\r\n /** Clear all in-memory caches held in this ECDb.\r\n * @beta\r\n */\r\n public clearCaches(): void {\r\n this._statementCache.clear();\r\n this._sqliteStatementCache.clear();\r\n this[_nativeDb].clearECDbCache();\r\n }\r\n\r\n /** @internal use to test statement caching */\r\n public clearStatementCache() {\r\n this._statementCache.clear();\r\n }\r\n\r\n /** @internal use to test statement caching */\r\n public getCachedStatementCount() {\r\n return this._statementCache.size;\r\n }\r\n\r\n /** Commit the outermost transaction, writing changes to the file. Then, restart the transaction.\r\n * @param changesetName The name of the operation that generated these changes.\r\n * @throws [IModelError]($common) if the database is not open or if the operation failed.\r\n */\r\n public saveChanges(changesetName?: string): void {\r\n const status: DbResult = this[_nativeDb].saveChanges(changesetName);\r\n if (status !== DbResult.BE_SQLITE_OK)\r\n throw new IModelError(status, \"Failed to save changes\");\r\n }\r\n\r\n /** Abandon (cancel) the outermost transaction, discarding all changes since last save. Then, restart the transaction.\r\n * @throws [IModelError]($common) if the database is not open or if the operation failed.\r\n */\r\n public abandonChanges(): void {\r\n const status: DbResult = this[_nativeDb].abandonChanges();\r\n if (status !== DbResult.BE_SQLITE_OK)\r\n throw new IModelError(status, \"Failed to abandon changes\");\r\n }\r\n\r\n /** Import a schema.\r\n *\r\n * If the import was successful, the database is automatically saved to disk.\r\n * @param pathName Path to ECSchema XML file to import.\r\n * @throws [IModelError]($common) if the database is not open or if the operation failed.\r\n */\r\n public importSchema(pathName: string): void {\r\n const status: DbResult = this[_nativeDb].importSchema(pathName);\r\n if (status !== DbResult.BE_SQLITE_OK) {\r\n Logger.logError(loggerCategory, `Failed to import schema from '${pathName}'.`);\r\n throw new IModelError(status, `Failed to import schema from '${pathName}'.`);\r\n }\r\n this.clearCaches();\r\n }\r\n\r\n /** Removes unused schemas from the database.\r\n *\r\n * If the removal was successful, the database is automatically saved to disk.\r\n * @param schemaNames Array of schema names to drop\r\n * @throws [IModelError]($common) if the database if the operation failed.\r\n * @alpha\r\n */\r\n public dropSchemas(schemaNames: string[]): void {\r\n if (schemaNames.length === 0)\r\n return;\r\n // SchemaSync.isEnabled() should be used, but ECDb is not an iModelDb so it has no container props\r\n if (this[_nativeDb].schemaSyncEnabled())\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Cannot drop schemas when schema sync is enabled\");\r\n\r\n try {\r\n this[_nativeDb].dropSchemas(schemaNames);\r\n this.saveChanges('dropped unused schemas');\r\n } catch (error: any) {\r\n Logger.logError(loggerCategory, `Failed to drop schemas: ${error}`);\r\n this.abandonChanges();\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, `Failed to drop schemas: ${error}`);\r\n } finally {\r\n this.clearCaches();\r\n }\r\n }\r\n\r\n /**\r\n * Returns the full schema for the input name.\r\n * @param name The name of the schema e.g. 'ECDbMeta'\r\n * @returns The SchemaProps for the requested schema\r\n * @throws if the schema can not be found or loaded.\r\n */\r\n public getSchemaProps(name: string): ECSchemaProps {\r\n return this[_nativeDb].getSchemaProps(name);\r\n }\r\n\r\n /** Import in-memory CSV rows into an ECClass.\r\n *\r\n * The rows are V8-serialized and processed in one native call. Values are converted from\r\n * their CSV string representation according to the mapped EC property type. One ECSQL\r\n * statement is reused for all rows. Every row must have the same number of columns.\r\n * Boolean fields accept `true`, `false`, `1`, or `0`. Integer fields must contain a\r\n * base-10 value in the signed 32-bit range. Boolean, double, integer, and string EC\r\n * properties are supported. The import is all-or-nothing and callers must call\r\n * [[saveChanges]] to commit it to disk.\r\n * @returns The number of imported rows.\r\n * @beta\r\n */\r\n public importCSVData(rows: readonly (readonly string[])[], options: CSVImportOptions): number {\r\n validateCSVMapping(options.mapping);\r\n return this[_nativeDb].importCSVData(options.className, serialize(rows), options.mapping, { nullValue: options.nullValue });\r\n }\r\n\r\n /** Stream a CSV file into an ECClass.\r\n *\r\n * The file must be UTF-8 encoded; an optional UTF-8 byte-order mark is accepted. It is read\r\n * and parsed in native code, and one ECSQL statement is reused for all rows. Every record must\r\n * have the same number of columns; blank records are not skipped. Boolean fields accept\r\n * `true`, `false`, `1`, or `0`. Integer fields must contain a base-10 value in the signed\r\n * 32-bit range. Boolean, double, integer, and string EC properties are supported. The import\r\n * is all-or-nothing and callers must call [[saveChanges]] to commit it to disk.\r\n * @returns The number of imported rows, excluding an optional header.\r\n * @beta\r\n */\r\n public importCSVFile(csvFilePath: string, options: CSVFileImportOptions): number {\r\n validateCSVMapping(options.mapping);\r\n return this[_nativeDb].importCSVFile(options.className, csvFilePath, options.mapping, {\r\n hasHeader: options.hasHeader,\r\n nullValue: options.nullValue,\r\n });\r\n }\r\n\r\n /**\r\n * Use a prepared ECSQL statement, potentially from the statement cache. If the requested statement doesn't exist\r\n * in the statement cache, a new statement is prepared. After the callback completes, the statement is reset and saved\r\n * in the statement cache so it can be reused in the future. Use this method for ECSQL statements that will be\r\n * reused often and are expensive to prepare. The statement cache holds the most recently used statements, discarding\r\n * the oldest statements as it fills. For statements you don't intend to reuse, instead use [[withStatement]].\r\n * @param sql The SQLite SQL statement to execute\r\n * @param callback the callback to invoke on the prepared statement\r\n * @param logErrors Determines if error will be logged if statement fail to prepare\r\n * @returns the value returned by `callback`.\r\n * @see [[withWriteStatement]]\r\n * @beta\r\n */\r\n public withCachedWriteStatement<T>(ecsql: string, callback: (stmt: ECSqlWriteStatement) => T, logErrors = true): T {\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n const stmt = this._statementCache.findAndRemove(ecsql) ?? this.prepareStatement(ecsql, logErrors);\r\n const release = () => this._statementCache.addOrDispose(stmt);\r\n try {\r\n const val = callback(new ECSqlWriteStatement(stmt));\r\n if (val instanceof Promise) {\r\n val.then(release, release);\r\n } else {\r\n release();\r\n }\r\n return val;\r\n } catch (err) {\r\n release();\r\n throw err;\r\n }\r\n }\r\n\r\n /**\r\n * Prepared and execute a callback on an ECSQL statement. After the callback completes the statement is disposed.\r\n * Use this method for ECSQL statements are either not expected to be reused, or are not expensive to prepare.\r\n * For statements that will be reused often, instead use [[withPreparedStatement]].\r\n * @param sql The SQLite SQL statement to execute\r\n * @param callback the callback to invoke on the prepared statement\r\n * @param logErrors Determines if error will be logged if statement fail to prepare\r\n * @returns the value returned by `callback`.\r\n * @see [[withCachedWriteStatement]]\r\n * @beta\r\n */\r\n public withWriteStatement<T>(ecsql: string, callback: (stmt: ECSqlWriteStatement) => T, logErrors = true): T {\r\n const stmt = this.prepareWriteStatement(ecsql, logErrors);\r\n const release = () => stmt[Symbol.dispose]();\r\n try {\r\n const val = callback(stmt);\r\n if (val instanceof Promise) {\r\n val.then(release, release);\r\n } else {\r\n release();\r\n }\r\n return val;\r\n } catch (err) {\r\n release();\r\n throw err;\r\n }\r\n }\r\n\r\n /** Prepare an ECSQL statement.\r\n * @param ecsql The ECSQL statement to prepare\r\n * @param logErrors Determines if error will be logged if statement fail to prepare\r\n * @throws [IModelError]($common) if there is a problem preparing the statement.\r\n * @beta\r\n */\r\n public prepareWriteStatement(ecsql: string, logErrors = true): ECSqlWriteStatement {\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n return new ECSqlWriteStatement(this.prepareStatement(ecsql, logErrors));\r\n }\r\n\r\n /**\r\n * Use a prepared ECSQL statement, potentially from the statement cache. If the requested statement doesn't exist\r\n * in the statement cache, a new statement is prepared. After the callback completes, the statement is reset and saved\r\n * in the statement cache so it can be reused in the future. Use this method for ECSQL statements that will be\r\n * reused often and are expensive to prepare. The statement cache holds the most recently used statements, discarding\r\n * the oldest statements as it fills. For statements you don't intend to reuse, instead use [[withStatement]].\r\n * @param sql The SQLite SQL statement to execute\r\n * @param callback the callback to invoke on the prepared statement\r\n * @param logErrors Determines if error will be logged if statement fail to prepare\r\n * @returns the value returned by `callback`.\r\n * @see [[withStatement]]\r\n * @public\r\n * @deprecated in 4.11 - might be removed in next major version. Use [[createQueryReader]] for SELECT statements and [[withCachedWriteStatement]] for INSERT/UPDATE/DELETE instead.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n public withPreparedStatement<T>(ecsql: string, callback: (stmt: ECSqlStatement) => T, logErrors = true): T {\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n const stmt = this._statementCache.findAndRemove(ecsql) ?? this.prepareStatement(ecsql, logErrors);\r\n const release = () => this._statementCache.addOrDispose(stmt);\r\n try {\r\n const val = callback(stmt);\r\n if (val instanceof Promise) {\r\n val.then(release, release);\r\n } else {\r\n release();\r\n }\r\n return val;\r\n } catch (err) {\r\n release();\r\n throw err;\r\n }\r\n }\r\n\r\n /**\r\n * Prepared and execute a callback on an ECSQL statement. After the callback completes the statement is disposed.\r\n * Use this method for ECSQL statements are either not expected to be reused, or are not expensive to prepare.\r\n * For statements that will be reused often, instead use [[withPreparedStatement]].\r\n * @param sql The SQLite SQL statement to execute\r\n * @param callback the callback to invoke on the prepared statement\r\n * @param logErrors Determines if error will be logged if statement fail to prepare\r\n * @returns the value returned by `callback`.\r\n * @see [[withPreparedStatement]]\r\n * @public\r\n * @deprecated in 4.11 - might be removed in next major version. Use [[createQueryReader]] for SELECT statements and [[withWriteStatement]] for INSERT/UPDATE/DELETE instead.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n public withStatement<T>(ecsql: string, callback: (stmt: ECSqlStatement) => T, logErrors = true): T {\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n const stmt = this.prepareStatement(ecsql, logErrors);\r\n const release = () => stmt[Symbol.dispose]();\r\n try {\r\n const val = callback(stmt);\r\n if (val instanceof Promise) {\r\n val.then(release, release);\r\n } else {\r\n release();\r\n }\r\n return val;\r\n } catch (err) {\r\n release();\r\n throw err;\r\n }\r\n }\r\n\r\n /** Prepare an ECSQL statement.\r\n * @param ecsql The ECSQL statement to prepare\r\n * @param logErrors Determines if error will be logged if statement fail to prepare\r\n * @throws [IModelError]($common) if there is a problem preparing the statement.\r\n * @deprecated in 4.11 - might be removed in next major version. Use [[prepareWriteStatement]] when preparing an INSERT/UPDATE/DELETE statement or [[createQueryReader]] to execute a SELECT statement.\r\n */\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n public prepareStatement(ecsql: string, logErrors = true): ECSqlStatement {\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n const stmt = new ECSqlStatement();\r\n stmt.prepare(this[_nativeDb], ecsql, logErrors);\r\n return stmt;\r\n }\r\n\r\n /**\r\n * Use a prepared SQL statement, potentially from the statement cache. If the requested statement doesn't exist\r\n * in the statement cache, a new statement is prepared. After the callback completes, the statement is reset and saved\r\n * in the statement cache so it can be reused in the future. Use this method for SQL statements that will be\r\n * reused often and are expensive to prepare. The statement cache holds the most recently used statements, discarding\r\n * the oldest statements as it fills. For statements you don't intend to reuse, instead use [[withSqliteStatement]].\r\n * @param sql The SQLite SQL statement to execute\r\n * @param callback the callback to invoke on the prepared statement\r\n * @param logErrors Determines if error will be logged if statement fail to prepare\r\n * @returns the value returned by `callback`.\r\n * @see [[withPreparedStatement]]\r\n * @public\r\n */\r\n public withPreparedSqliteStatement<T>(sql: string, callback: (stmt: SqliteStatement) => T, logErrors = true): T {\r\n const stmt = this._sqliteStatementCache.findAndRemove(sql) ?? this.prepareSqliteStatement(sql, logErrors);\r\n const release = () => this._sqliteStatementCache.addOrDispose(stmt);\r\n try {\r\n const val: T = callback(stmt);\r\n if (val instanceof Promise) {\r\n val.then(release, release);\r\n } else {\r\n release();\r\n }\r\n return val;\r\n } catch (err) {\r\n release();\r\n throw err;\r\n }\r\n }\r\n\r\n /**\r\n * Prepared and execute a callback on a SQL statement. After the callback completes the statement is disposed.\r\n * Use this method for SQL statements are either not expected to be reused, or are not expensive to prepare.\r\n * For statements that will be reused often, instead use [[withPreparedSqliteStatement]].\r\n * @param sql The SQLite SQL statement to execute\r\n * @param callback the callback to invoke on the prepared statement\r\n * @param logErrors Determines if error will be logged if statement fail to prepare\r\n * @returns the value returned by `callback`.\r\n * @public\r\n */\r\n public withSqliteStatement<T>(sql: string, callback: (stmt: SqliteStatement) => T, logErrors = true): T {\r\n const stmt = this.prepareSqliteStatement(sql, logErrors);\r\n const release = () => stmt[Symbol.dispose]();\r\n try {\r\n const val: T = callback(stmt);\r\n if (val instanceof Promise) {\r\n val.then(release, release);\r\n } else {\r\n release();\r\n }\r\n return val;\r\n } catch (err) {\r\n release();\r\n throw err;\r\n }\r\n }\r\n\r\n /** Prepare an SQL statement.\r\n * @param sql The SQLite SQL statement to prepare\r\n * @param logErrors Determines if error will be logged if statement fail to prepare\r\n * @throws [IModelError]($common) if there is a problem preparing the statement.\r\n * @internal\r\n */\r\n public prepareSqliteStatement(sql: string, logErrors = true): SqliteStatement {\r\n const stmt = new SqliteStatement(sql);\r\n stmt.prepare(this[_nativeDb], logErrors);\r\n return stmt;\r\n }\r\n\r\n /** @internal */\r\n public get [_nativeDb](): IModelJsNative.ECDb {\r\n assert(undefined !== this._nativeDb);\r\n return this._nativeDb;\r\n }\r\n\r\n /** Creates a reader for asynchronous ECSQL query execution.\r\n * Execution starts when the reader is consumed using asynchronous iteration or awaited calls to `step()` or `toArray()`.\r\n * Results are fetched and buffered in batches. For synchronous, callback-scoped execution, use [[withQueryReader]].\r\n *\r\n * See also:\r\n * - [Choosing a query reader]($docs/learning/backend/ExecutingECSQL)\r\n * - [Asynchronous query examples]($docs/learning/ECSQLCodeExamples)\r\n * - [ECSQL Row Format]($docs/learning/ECSQLRowFormat)\r\n *\r\n * @param params The values to bind to the parameters (if the ECSQL has any).\r\n * @param config Allow to specify certain flags which control how query is executed.\r\n * @returns Returns an [ECSqlReader]($common) which helps iterate over the result set and also give access to metadata.\r\n * @public\r\n * */\r\n public createQueryReader(ecsql: string, params?: QueryBinder, config?: QueryOptions): ECSqlReader {\r\n if (!this._nativeDb || !this._nativeDb.isOpen()) {\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR_NOTOPEN, \"db not open\");\r\n }\r\n const executor = {\r\n execute: async (request: DbQueryRequest) => {\r\n return ConcurrentQuery.executeQueryRequest(this[_nativeDb], request);\r\n },\r\n };\r\n return new ECSqlReader(executor, ecsql, params, config);\r\n }\r\n\r\n /** Executes a callback with a synchronous ECSQL reader on the owning database connection.\r\n * The reader steps one row at a time without buffering result batches. Finish using it before the callback completes.\r\n * Return materialized rows or computed values rather than the reader. For asynchronous execution, use [[createQueryReader]].\r\n * The prepared statement may be reused from the statement cache between completed calls.\r\n *\r\n * See also:\r\n * - [Choosing a query reader]($docs/learning/backend/ExecutingECSQL)\r\n * - [Synchronous query examples]($docs/learning/backend/WithQueryReaderCodeExamples)\r\n * - [ECSQL Row Format]($docs/learning/ECSQLRowFormat)\r\n * @param ecsql The ECSQL query to execute.\r\n * @param callback the callback to invoke on the prepared ECSqlSyncReader\r\n * @param params The values to bind to the parameters (if the ECSQL has any).\r\n * @param config Optional flags which control how query is executed.\r\n * @returns the value returned by `callback`.\r\n * @throws IModelError if db is not open or if error occurs during statement execution\r\n * @beta\r\n * */\r\n public withQueryReader<T>(ecsql: string, callback: (reader: ECSqlSyncReader) => T, params?: QueryBinder, config?: SynchronousQueryOptions): T {\r\n if (!this[_nativeDb].isOpen())\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR_NOTOPEN, \"db not open\");\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n const stmt = this._statementCache.findAndRemove(ecsql) ?? new ECSqlStatement();\r\n const executor = new ECSqlRowExecutor(this, stmt, loggerCategory);\r\n const release = () => {\r\n executor[Symbol.dispose]();\r\n releaseECSqlStatement(stmt, this._statementCache, loggerCategory, executor.canCacheStatement);\r\n };\r\n try {\r\n const reader = new ECSqlSyncReader(executor, ecsql, params, config);\r\n const val = callback(reader);\r\n if (val instanceof Promise) {\r\n val.then(release, release);\r\n } else {\r\n release();\r\n }\r\n return val;\r\n } catch (err: any) {\r\n release();\r\n throw err;\r\n }\r\n }\r\n}\r\n"]}
@@ -196,7 +196,7 @@ export declare class ECSqlStatement implements IterableIterator<any>, Disposable
196
196
  * The section "[iTwin.js Types used in ECSQL Parameter Bindings]($docs/learning/ECSQLParameterTypes)" describes the
197
197
  * iTwin.js types to be used for the different ECSQL parameter types.
198
198
  *
199
- * See also these [Code Samples]($docs/learning/backend/ECSQLCodeExamples#binding-to-all-parameters-at-once)
199
+ * See [reader parameter-binding examples]($docs/learning/ECSQLCodeExamples.md#parameter-bindings) for SELECT queries using [QueryBinder]($common).
200
200
  */
201
201
  bindValues(values: any[] | object): void;
202
202
  /** Clear any bindings that were previously set on this statement.
@@ -430,7 +430,7 @@ export declare class ECSqlWriteStatement {
430
430
  * The section "[iTwin.js Types used in ECSQL Parameter Bindings]($docs/learning/ECSQLParameterTypes)" describes the
431
431
  * iTwin.js types to be used for the different ECSQL parameter types.
432
432
  *
433
- * See also these [Code Samples]($docs/learning/backend/ECSQLCodeExamples#binding-to-all-parameters-at-once)
433
+ * See [reader parameter-binding examples]($docs/learning/ECSQLCodeExamples.md#parameter-bindings) for SELECT queries using [QueryBinder]($common).
434
434
  */
435
435
  bindValues(values: any[] | object): void;
436
436
  /** Clear any bindings that were previously set on this statement.