@itwin/core-backend 3.5.0-dev.18 → 3.5.0-dev.20

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 (246) hide show
  1. package/CHANGELOG.md +8 -1
  2. package/lib/cjs/AliCloudStorageService.d.ts +23 -23
  3. package/lib/cjs/AliCloudStorageService.js +71 -71
  4. package/lib/cjs/AliCloudStorageService.js.map +1 -1
  5. package/lib/cjs/BackendHubAccess.d.ts +224 -224
  6. package/lib/cjs/BackendHubAccess.js +41 -41
  7. package/lib/cjs/BackendHubAccess.js.map +1 -1
  8. package/lib/cjs/BackendLoggerCategory.d.ts +91 -91
  9. package/lib/cjs/BackendLoggerCategory.js +99 -99
  10. package/lib/cjs/BackendLoggerCategory.js.map +1 -1
  11. package/lib/cjs/BisCoreSchema.d.ts +21 -21
  12. package/lib/cjs/BisCoreSchema.js +60 -60
  13. package/lib/cjs/BisCoreSchema.js.map +1 -1
  14. package/lib/cjs/BriefcaseManager.d.ts +165 -165
  15. package/lib/cjs/BriefcaseManager.js +405 -405
  16. package/lib/cjs/BriefcaseManager.js.map +1 -1
  17. package/lib/cjs/Category.d.ts +153 -153
  18. package/lib/cjs/Category.js +243 -243
  19. package/lib/cjs/Category.js.map +1 -1
  20. package/lib/cjs/ChangeSummaryManager.d.ts +187 -187
  21. package/lib/cjs/ChangeSummaryManager.js +445 -445
  22. package/lib/cjs/ChangeSummaryManager.js.map +1 -1
  23. package/lib/cjs/ChangedElementsDb.d.ts +99 -99
  24. package/lib/cjs/ChangedElementsDb.js +165 -165
  25. package/lib/cjs/ChangedElementsDb.js.map +1 -1
  26. package/lib/cjs/ChangedElementsManager.d.ts +39 -39
  27. package/lib/cjs/ChangedElementsManager.js +88 -88
  28. package/lib/cjs/ChangedElementsManager.js.map +1 -1
  29. package/lib/cjs/CheckpointManager.d.ts +120 -120
  30. package/lib/cjs/CheckpointManager.js +343 -343
  31. package/lib/cjs/CheckpointManager.js.map +1 -1
  32. package/lib/cjs/ClassRegistry.d.ts +72 -71
  33. package/lib/cjs/ClassRegistry.d.ts.map +1 -1
  34. package/lib/cjs/ClassRegistry.js +243 -215
  35. package/lib/cjs/ClassRegistry.js.map +1 -1
  36. package/lib/cjs/CloudSqlite.d.ts +350 -349
  37. package/lib/cjs/CloudSqlite.d.ts.map +1 -1
  38. package/lib/cjs/CloudSqlite.js +152 -151
  39. package/lib/cjs/CloudSqlite.js.map +1 -1
  40. package/lib/cjs/CloudStorageBackend.d.ts +58 -58
  41. package/lib/cjs/CloudStorageBackend.js +173 -173
  42. package/lib/cjs/CloudStorageBackend.js.map +1 -1
  43. package/lib/cjs/CodeService.d.ts +396 -396
  44. package/lib/cjs/CodeService.js +63 -63
  45. package/lib/cjs/CodeService.js.map +1 -1
  46. package/lib/cjs/CodeSpecs.d.ts +50 -50
  47. package/lib/cjs/CodeSpecs.js +112 -112
  48. package/lib/cjs/CodeSpecs.js.map +1 -1
  49. package/lib/cjs/ConcurrentQuery.d.ts +11 -11
  50. package/lib/cjs/ConcurrentQuery.js +30 -30
  51. package/lib/cjs/ConcurrentQuery.js.map +1 -1
  52. package/lib/cjs/CustomViewState3dCreator.d.ts +32 -32
  53. package/lib/cjs/CustomViewState3dCreator.js +113 -113
  54. package/lib/cjs/CustomViewState3dCreator.js.map +1 -1
  55. package/lib/cjs/DevTools.d.ts +71 -71
  56. package/lib/cjs/DevTools.js +154 -154
  57. package/lib/cjs/DevTools.js.map +1 -1
  58. package/lib/cjs/DisplayStyle.d.ts +106 -106
  59. package/lib/cjs/DisplayStyle.d.ts.map +1 -1
  60. package/lib/cjs/DisplayStyle.js +256 -256
  61. package/lib/cjs/DisplayStyle.js.map +1 -1
  62. package/lib/cjs/ECDb.d.ts +191 -191
  63. package/lib/cjs/ECDb.js +350 -350
  64. package/lib/cjs/ECDb.js.map +1 -1
  65. package/lib/cjs/ECSchemaXmlContext.d.ts +18 -18
  66. package/lib/cjs/ECSchemaXmlContext.js +41 -41
  67. package/lib/cjs/ECSchemaXmlContext.js.map +1 -1
  68. package/lib/cjs/ECSqlStatement.d.ts +466 -466
  69. package/lib/cjs/ECSqlStatement.js +791 -791
  70. package/lib/cjs/ECSqlStatement.js.map +1 -1
  71. package/lib/cjs/Element.d.ts +1102 -1109
  72. package/lib/cjs/Element.d.ts.map +1 -1
  73. package/lib/cjs/Element.js +1416 -1420
  74. package/lib/cjs/Element.js.map +1 -1
  75. package/lib/cjs/ElementAspect.d.ts +158 -156
  76. package/lib/cjs/ElementAspect.d.ts.map +1 -1
  77. package/lib/cjs/ElementAspect.js +186 -178
  78. package/lib/cjs/ElementAspect.js.map +1 -1
  79. package/lib/cjs/ElementGraphics.d.ts +9 -9
  80. package/lib/cjs/ElementGraphics.js +41 -41
  81. package/lib/cjs/ElementGraphics.js.map +1 -1
  82. package/lib/cjs/ElementTreeWalker.d.ts +162 -162
  83. package/lib/cjs/ElementTreeWalker.js +409 -409
  84. package/lib/cjs/ElementTreeWalker.js.map +1 -1
  85. package/lib/cjs/Entity.d.ts +106 -76
  86. package/lib/cjs/Entity.d.ts.map +1 -1
  87. package/lib/cjs/Entity.js +134 -82
  88. package/lib/cjs/Entity.js.map +1 -1
  89. package/lib/cjs/EntityReferences.d.ts +50 -0
  90. package/lib/cjs/EntityReferences.d.ts.map +1 -0
  91. package/lib/cjs/EntityReferences.js +96 -0
  92. package/lib/cjs/EntityReferences.js.map +1 -0
  93. package/lib/cjs/ExportGraphics.d.ts +317 -317
  94. package/lib/cjs/ExportGraphics.js +208 -208
  95. package/lib/cjs/ExportGraphics.js.map +1 -1
  96. package/lib/cjs/ExternalSource.d.ts +96 -94
  97. package/lib/cjs/ExternalSource.d.ts.map +1 -1
  98. package/lib/cjs/ExternalSource.js +131 -125
  99. package/lib/cjs/ExternalSource.js.map +1 -1
  100. package/lib/cjs/GeoCoordConfig.d.ts +19 -19
  101. package/lib/cjs/GeoCoordConfig.js +82 -82
  102. package/lib/cjs/GeoCoordConfig.js.map +1 -1
  103. package/lib/cjs/GeometrySummary.d.ts +4 -4
  104. package/lib/cjs/GeometrySummary.js +380 -380
  105. package/lib/cjs/GeometrySummary.js.map +1 -1
  106. package/lib/cjs/HubMock.d.ts +93 -93
  107. package/lib/cjs/HubMock.js +190 -190
  108. package/lib/cjs/HubMock.js.map +1 -1
  109. package/lib/cjs/IModelCloneContext.d.ts +8 -85
  110. package/lib/cjs/IModelCloneContext.d.ts.map +1 -1
  111. package/lib/cjs/IModelCloneContext.js +15 -150
  112. package/lib/cjs/IModelCloneContext.js.map +1 -1
  113. package/lib/cjs/IModelDb.d.ts +1167 -1164
  114. package/lib/cjs/IModelDb.d.ts.map +1 -1
  115. package/lib/cjs/IModelDb.js +2332 -2324
  116. package/lib/cjs/IModelDb.js.map +1 -1
  117. package/lib/cjs/IModelElementCloneContext.d.ts +90 -0
  118. package/lib/cjs/IModelElementCloneContext.d.ts.map +1 -0
  119. package/lib/cjs/IModelElementCloneContext.js +160 -0
  120. package/lib/cjs/IModelElementCloneContext.js.map +1 -0
  121. package/lib/cjs/IModelHost.d.ts +369 -361
  122. package/lib/cjs/IModelHost.d.ts.map +1 -1
  123. package/lib/cjs/IModelHost.js +492 -489
  124. package/lib/cjs/IModelHost.js.map +1 -1
  125. package/lib/cjs/IModelJsFs.d.ts +62 -62
  126. package/lib/cjs/IModelJsFs.js +140 -140
  127. package/lib/cjs/IModelJsFs.js.map +1 -1
  128. package/lib/cjs/IpcHost.d.ts +98 -98
  129. package/lib/cjs/IpcHost.js +234 -234
  130. package/lib/cjs/IpcHost.js.map +1 -1
  131. package/lib/cjs/LineStyle.d.ts +311 -311
  132. package/lib/cjs/LineStyle.js +295 -295
  133. package/lib/cjs/LineStyle.js.map +1 -1
  134. package/lib/cjs/LocalHub.d.ts +162 -162
  135. package/lib/cjs/LocalHub.js +587 -587
  136. package/lib/cjs/LocalHub.js.map +1 -1
  137. package/lib/cjs/LocalhostIpcHost.d.ts +20 -20
  138. package/lib/cjs/LocalhostIpcHost.js +81 -81
  139. package/lib/cjs/LocalhostIpcHost.js.map +1 -1
  140. package/lib/cjs/Material.d.ts +103 -103
  141. package/lib/cjs/Material.js +147 -147
  142. package/lib/cjs/Material.js.map +1 -1
  143. package/lib/cjs/Model.d.ts +388 -386
  144. package/lib/cjs/Model.d.ts.map +1 -1
  145. package/lib/cjs/Model.js +479 -471
  146. package/lib/cjs/Model.js.map +1 -1
  147. package/lib/cjs/NativeAppStorage.d.ts +51 -51
  148. package/lib/cjs/NativeAppStorage.js +202 -202
  149. package/lib/cjs/NativeAppStorage.js.map +1 -1
  150. package/lib/cjs/NativeHost.d.ts +52 -52
  151. package/lib/cjs/NativeHost.js +168 -168
  152. package/lib/cjs/NativeHost.js.map +1 -1
  153. package/lib/cjs/NavigationRelationship.d.ts +156 -156
  154. package/lib/cjs/NavigationRelationship.js +225 -225
  155. package/lib/cjs/NavigationRelationship.js.map +1 -1
  156. package/lib/cjs/PromiseMemoizer.d.ts +51 -51
  157. package/lib/cjs/PromiseMemoizer.js +101 -101
  158. package/lib/cjs/PromiseMemoizer.js.map +1 -1
  159. package/lib/cjs/PropertyStore.d.ts +132 -132
  160. package/lib/cjs/PropertyStore.js +11 -11
  161. package/lib/cjs/PropertyStore.js.map +1 -1
  162. package/lib/cjs/Relationship.d.ts +416 -400
  163. package/lib/cjs/Relationship.d.ts.map +1 -1
  164. package/lib/cjs/Relationship.js +494 -465
  165. package/lib/cjs/Relationship.js.map +1 -1
  166. package/lib/cjs/RpcBackend.d.ts +28 -28
  167. package/lib/cjs/RpcBackend.js +126 -126
  168. package/lib/cjs/RpcBackend.js.map +1 -1
  169. package/lib/cjs/SQLiteDb.d.ts +219 -219
  170. package/lib/cjs/SQLiteDb.js +214 -214
  171. package/lib/cjs/SQLiteDb.js.map +1 -1
  172. package/lib/cjs/Schema.d.ts +55 -55
  173. package/lib/cjs/Schema.js +83 -83
  174. package/lib/cjs/Schema.js.map +1 -1
  175. package/lib/cjs/ServerBasedLocks.d.ts +57 -57
  176. package/lib/cjs/ServerBasedLocks.js +168 -168
  177. package/lib/cjs/ServerBasedLocks.js.map +1 -1
  178. package/lib/cjs/SqliteStatement.d.ts +360 -283
  179. package/lib/cjs/SqliteStatement.d.ts.map +1 -1
  180. package/lib/cjs/SqliteStatement.js +586 -448
  181. package/lib/cjs/SqliteStatement.js.map +1 -1
  182. package/lib/cjs/Texture.d.ts +58 -58
  183. package/lib/cjs/Texture.js +82 -82
  184. package/lib/cjs/Texture.js.map +1 -1
  185. package/lib/cjs/TileStorage.d.ts +18 -18
  186. package/lib/cjs/TileStorage.js +90 -90
  187. package/lib/cjs/TileStorage.js.map +1 -1
  188. package/lib/cjs/TxnManager.d.ts +202 -202
  189. package/lib/cjs/TxnManager.js +356 -356
  190. package/lib/cjs/TxnManager.js.map +1 -1
  191. package/lib/cjs/ViewDefinition.d.ts +439 -435
  192. package/lib/cjs/ViewDefinition.d.ts.map +1 -1
  193. package/lib/cjs/ViewDefinition.js +646 -635
  194. package/lib/cjs/ViewDefinition.js.map +1 -1
  195. package/lib/cjs/ViewStateHydrator.d.ts +13 -13
  196. package/lib/cjs/ViewStateHydrator.js +103 -103
  197. package/lib/cjs/ViewStateHydrator.js.map +1 -1
  198. package/lib/cjs/assets/IModelChange.02.00.00.ecschema.xml +90 -90
  199. package/lib/cjs/assets/Settings/Schemas/Cloud.Schema.json +67 -67
  200. package/lib/cjs/assets/Settings/Schemas/Gcs.schema.json +31 -31
  201. package/lib/cjs/assets/Settings/Schemas/Workspace.Schema.json +52 -52
  202. package/lib/cjs/assets/Settings/backend.setting.json5 +138 -138
  203. package/lib/cjs/core-backend.d.ts +184 -182
  204. package/lib/cjs/core-backend.d.ts.map +1 -1
  205. package/lib/cjs/core-backend.js +204 -202
  206. package/lib/cjs/core-backend.js.map +1 -1
  207. package/lib/cjs/domains/FunctionalElements.d.ts +101 -101
  208. package/lib/cjs/domains/FunctionalElements.js +145 -145
  209. package/lib/cjs/domains/FunctionalElements.js.map +1 -1
  210. package/lib/cjs/domains/FunctionalSchema.d.ts +13 -13
  211. package/lib/cjs/domains/FunctionalSchema.js +40 -40
  212. package/lib/cjs/domains/FunctionalSchema.js.map +1 -1
  213. package/lib/cjs/domains/GenericElements.d.ts +177 -177
  214. package/lib/cjs/domains/GenericElements.js +263 -263
  215. package/lib/cjs/domains/GenericElements.js.map +1 -1
  216. package/lib/cjs/domains/GenericSchema.d.ts +10 -10
  217. package/lib/cjs/domains/GenericSchema.js +28 -28
  218. package/lib/cjs/domains/GenericSchema.js.map +1 -1
  219. package/lib/cjs/rpc-impl/DevToolsRpcImpl.d.ts +15 -15
  220. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js +32 -32
  221. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js.map +1 -1
  222. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts +45 -45
  223. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +262 -262
  224. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -1
  225. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts +22 -22
  226. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js +204 -204
  227. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js.map +1 -1
  228. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts +36 -36
  229. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js +168 -168
  230. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -1
  231. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.d.ts +16 -16
  232. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js +43 -43
  233. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js.map +1 -1
  234. package/lib/cjs/rpc-impl/WipRpcImpl.d.ts +15 -15
  235. package/lib/cjs/rpc-impl/WipRpcImpl.js +37 -37
  236. package/lib/cjs/rpc-impl/WipRpcImpl.js.map +1 -1
  237. package/lib/cjs/workspace/Settings.d.ts +186 -186
  238. package/lib/cjs/workspace/Settings.js +155 -155
  239. package/lib/cjs/workspace/Settings.js.map +1 -1
  240. package/lib/cjs/workspace/SettingsSchemas.d.ts +75 -75
  241. package/lib/cjs/workspace/SettingsSchemas.js +191 -191
  242. package/lib/cjs/workspace/SettingsSchemas.js.map +1 -1
  243. package/lib/cjs/workspace/Workspace.d.ts +414 -414
  244. package/lib/cjs/workspace/Workspace.js +543 -543
  245. package/lib/cjs/workspace/Workspace.js.map +1 -1
  246. package/package.json +14 -13
@@ -1,792 +1,792 @@
1
- "use strict";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
- * See LICENSE.md in the project root for license terms and full copyright notice.
5
- *--------------------------------------------------------------------------------------------*/
6
- /** @packageDocumentation
7
- * @module ECSQL
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.ECSqlValueIterator = exports.ECSqlValue = exports.ECSqlBinder = exports.ECSqlStatement = exports.ECSqlInsertResult = void 0;
11
- const core_bentley_1 = require("@itwin/core-bentley");
12
- const core_geometry_1 = require("@itwin/core-geometry");
13
- const core_common_1 = require("@itwin/core-common");
14
- const IModelHost_1 = require("./IModelHost");
15
- /** The result of an **ECSQL INSERT** statement as returned from [ECSqlStatement.stepForInsert]($backend).
16
- *
17
- * If the step was successful, the ECSqlInsertResult contains
18
- * [DbResult.BE_SQLITE_DONE]($core-bentley)
19
- * and the ECInstanceId of the newly created instance.
20
- * In case of failure it contains the [DbResult]($core-bentley) error code.
21
- *
22
- * > Insert statements can be used with ECDb only, not with IModelDb.
23
- * @public
24
- */
25
- class ECSqlInsertResult {
26
- constructor(status, id) {
27
- this.status = status;
28
- this.id = id;
29
- }
30
- }
31
- exports.ECSqlInsertResult = ECSqlInsertResult;
32
- /** Executes ECSQL statements.
33
- *
34
- * A statement must be prepared before it can be executed, and it must be released when no longer needed.
35
- * See [IModelDb.withPreparedStatement]($backend) or
36
- * [ECDb.withPreparedStatement]($backend) for a convenient and
37
- * reliable way to prepare, execute, and then release a statement.
38
- *
39
- * A statement may contain parameters that must be filled in before use by the **bind** methods.
40
- *
41
- * Once prepared (and parameters are bound, if any), the statement is executed by calling [ECSqlStatement.step]($backend).
42
- * In case of an **ECSQL SELECT** statement, the current row can be retrieved with [ECSqlStatement.getRow]($backend) as
43
- * a whole, or with [ECSqlStatement.getValue]($backend) when individual values are needed.
44
- * Alternatively, query results of an **ECSQL SELECT** statement can be stepped through by using
45
- * standard iteration syntax, such as `for of`.
46
- *
47
- * > Preparing a statement can be time-consuming. The best way to reduce the effect of this overhead is to cache and reuse prepared
48
- * > statements. A cached prepared statement may be used in different places in an app, as long as the statement is general enough.
49
- * > The key to making this strategy work is to phrase a statement in a general way and use placeholders to represent parameters that will vary on each use.
50
- *
51
- * See also
52
- * - [Executing ECSQL]($docs/learning/backend/ExecutingECSQL) provides more background on ECSQL and an introduction on how to execute ECSQL with the iTwin.js API.
53
- * - [Code Examples]($docs/learning/backend/ECSQLCodeExamples) illustrate the use of the iTwin.js API for executing and working with ECSQL
54
- * @public
55
- */
56
- class ECSqlStatement {
57
- get sql() { return this._sql; } // eslint-disable-line @typescript-eslint/no-non-null-assertion
58
- /** Check if this statement has been prepared successfully or not */
59
- get isPrepared() { return !!this._stmt; }
60
- /** Prepare this statement prior to first use.
61
- * @param db The DgnDb or ECDb to prepare the statement against
62
- * @param ecsql The ECSQL statement string to prepare
63
- * @param logErrors Determine if errors are logged or not
64
- * @throws [IModelError]($common) if the ECSQL statement cannot be prepared. Normally, prepare fails due to ECSQL syntax errors or references to tables or properties that do not exist.
65
- * The error.message property will provide details.
66
- * @internal
67
- */
68
- prepare(db, ecsql, logErrors = true) {
69
- const stat = this.tryPrepare(db, ecsql, logErrors);
70
- if (stat.status !== core_bentley_1.DbResult.BE_SQLITE_OK) {
71
- throw new core_common_1.IModelError(stat.status, stat.message);
72
- }
73
- }
74
- /** Prepare this statement prior to first use.
75
- * @param db The DgnDb or ECDb to prepare the statement against
76
- * @param ecsql The ECSQL statement string to prepare
77
- * @param logErrors Determine if errors are logged or not, its set to false by default for tryPrepare()
78
- * @returns A [StatusCodeWithMessage]($bentley) object with a `status` member equal to [DbResult.BE_SQLITE_OK]($bentley) on success. Upon error, the `message` member will provide details.
79
- * @internal
80
- */
81
- tryPrepare(db, ecsql, logErrors = false) {
82
- if (this.isPrepared)
83
- throw new Error("ECSqlStatement is already prepared");
84
- this._sql = ecsql;
85
- this._stmt = new IModelHost_1.IModelHost.platform.ECSqlStatement();
86
- return this._stmt.prepare(db, ecsql, logErrors);
87
- }
88
- /** Reset this statement so that the next call to step will return the first row, if any. */
89
- reset() {
90
- (0, core_bentley_1.assert)(undefined !== this._stmt);
91
- this._stmt.reset();
92
- }
93
- /** Get the Native SQL statement
94
- * @internal
95
- */
96
- getNativeSql() {
97
- (0, core_bentley_1.assert)(undefined !== this._stmt);
98
- return this._stmt.getNativeSql();
99
- }
100
- /** Call this function when finished with this statement. This releases the native resources held by the statement.
101
- *
102
- * > Do not call this method directly on a statement that is being managed by a statement cache.
103
- */
104
- dispose() {
105
- if (this._stmt) {
106
- this._stmt.dispose(); // free native statement
107
- this._stmt = undefined;
108
- }
109
- }
110
- /** Binds the specified value to the specified ECSQL parameter.
111
- * The section "[iTwin.js Types used in ECSQL Parameter Bindings]($docs/learning/ECSQLParameterTypes)" describes the
112
- * iTwin.js types to be used for the different ECSQL parameter types.
113
- * @param parameter Index (1-based) or name of the parameter
114
- */
115
- bindValue(parameter, val) { this.getBinder(parameter).bind(val); }
116
- /** Binds null to the specified ECSQL parameter.
117
- * @param parameter Index (1-based) or name of the parameter
118
- */
119
- bindNull(parameter) { this.getBinder(parameter).bindNull(); }
120
- /** Binds a BLOB value to the specified ECSQL parameter.
121
- * @param parameter Index (1-based) or name of the parameter
122
- * @param BLOB value as either a Uint8Array, ArrayBuffer or a Base64 string
123
- */
124
- bindBlob(parameter, blob) { this.getBinder(parameter).bindBlob(blob); }
125
- /** Binds a boolean value to the specified ECSQL parameter.
126
- * @param parameter Index (1-based) or name of the parameter
127
- * @param val Boolean value
128
- */
129
- bindBoolean(parameter, val) { this.getBinder(parameter).bindBoolean(val); }
130
- /** Binds a DateTime value to the specified ECSQL parameter.
131
- * @param parameter Index (1-based) or name of the parameter
132
- * @param isoDateTimeString DateTime value as ISO8601 string
133
- */
134
- bindDateTime(parameter, isoDateTimeString) { this.getBinder(parameter).bindDateTime(isoDateTimeString); }
135
- /** Binds a double value to the specified ECSQL parameter.
136
- * @param parameter Index (1-based) or name of the parameter
137
- * @param val Double value
138
- */
139
- bindDouble(parameter, val) { this.getBinder(parameter).bindDouble(val); }
140
- /** Binds an GUID value to the specified ECSQL parameter.
141
- * @param parameter Index (1-based) or name of the parameter
142
- * @param val GUID value
143
- */
144
- bindGuid(parameter, val) { this.getBinder(parameter).bindGuid(val); }
145
- /** Binds an Id value to the specified ECSQL parameter.
146
- * @param parameter Index (1-based) or name of the parameter
147
- * @param val Id value
148
- */
149
- bindId(parameter, val) { this.getBinder(parameter).bindId(val); }
150
- /** Binds an integer value to the specified ECSQL parameter.
151
- * @param parameter Index (1-based) or name of the parameter
152
- * @param val Integer value as number, decimal string or hexadecimal string.
153
- */
154
- bindInteger(parameter, val) { this.getBinder(parameter).bindInteger(val); }
155
- /** Binds an Point2d value to the specified ECSQL parameter.
156
- * @param parameter Index (1-based) or name of the parameter
157
- * @param val Point2d value
158
- */
159
- bindPoint2d(parameter, val) { this.getBinder(parameter).bindPoint2d(val); }
160
- /** Binds an Point3d value to the specified ECSQL parameter.
161
- * @param parameter Index (1-based) or name of the parameter
162
- * @param val Point3d value
163
- */
164
- bindPoint3d(parameter, val) { this.getBinder(parameter).bindPoint3d(val); }
165
- /** Binds a Range3d as a blob to the specified ECSQL parameter
166
- * @param parameter Index(1-based) or name of the parameter
167
- * @param val Range3d value
168
- */
169
- bindRange3d(parameter, val) { this.getBinder(parameter).bindRange3d(val); }
170
- /** Binds an string to the specified ECSQL parameter.
171
- * @param parameter Index (1-based) or name of the parameter
172
- * @param val String value
173
- */
174
- bindString(parameter, val) { this.getBinder(parameter).bindString(val); }
175
- /** Binds a navigation property value to the specified ECSQL parameter.
176
- * @param parameter Index (1-based) or name of the parameter
177
- * @param val Navigation property value
178
- */
179
- bindNavigation(parameter, val) { this.getBinder(parameter).bindNavigation(val); }
180
- /** Binds a struct property value to the specified ECSQL parameter.
181
- * @param parameter Index (1-based) or name of the parameter
182
- * @param val Struct value. The struct value is an object composed of pairs of a struct member property name and its value
183
- * (of one of the supported types)
184
- */
185
- bindStruct(parameter, val) { this.getBinder(parameter).bindStruct(val); }
186
- /** Binds an array value to the specified ECSQL parameter.
187
- * @param parameter Index (1-based) or name of the parameter
188
- * @param val Array value. The array value is an array of values of the supported types
189
- */
190
- bindArray(parameter, val) { this.getBinder(parameter).bindArray(val); }
191
- bindIdSet(parameter, val) { this.getBinder(parameter).bindIdSet(val); }
192
- /**
193
- * Gets a binder to bind a value for an ECSQL parameter
194
- * > This is the most low-level API to bind a value to a specific parameter. Alternatively you can use the ECSqlStatement.bindXX methods
195
- * > or [ECSqlStatement.bindValues]($backend).
196
- * @param parameter Index (1-based) or name of the parameter
197
- */
198
- getBinder(parameter) {
199
- (0, core_bentley_1.assert)(undefined !== this._stmt);
200
- return new ECSqlBinder(this._stmt.getBinder(parameter));
201
- }
202
- /** Bind values to all parameters in the statement.
203
- * @param values The values to bind to the parameters.
204
- * Pass an *array* of values if the parameters are *positional*.
205
- * Pass an *object of the values keyed on the parameter name* for *named parameters*.
206
- * The values in either the array or object must match the respective types of the parameter.
207
- *
208
- * The section "[iTwin.js Types used in ECSQL Parameter Bindings]($docs/learning/ECSQLParameterTypes)" describes the
209
- * iTwin.js types to be used for the different ECSQL parameter types.
210
- *
211
- * See also these [Code Samples]($docs/learning/backend/ECSQLCodeExamples#binding-to-all-parameters-at-once)
212
- */
213
- bindValues(values) {
214
- if (Array.isArray(values)) {
215
- for (let i = 0; i < values.length; i++) {
216
- const paramIndex = i + 1;
217
- const paramValue = values[i];
218
- if (paramValue === undefined || paramValue === null)
219
- continue;
220
- this.bindValue(paramIndex, paramValue);
221
- }
222
- return;
223
- }
224
- for (const entry of Object.entries(values)) {
225
- const paramName = entry[0];
226
- const paramValue = entry[1];
227
- if (paramValue === undefined || paramValue === null)
228
- continue;
229
- this.bindValue(paramName, paramValue);
230
- }
231
- }
232
- /** Clear any bindings that were previously set on this statement.
233
- * @throws [IModelError]($common) in case of errors
234
- */
235
- clearBindings() {
236
- if (this._stmt) {
237
- const stat = this._stmt.clearBindings();
238
- if (stat !== core_bentley_1.DbResult.BE_SQLITE_OK)
239
- throw new core_common_1.IModelError(stat, "Error clearing bindings");
240
- }
241
- }
242
- /** Step this statement to the next row.
243
- *
244
- * For **ECSQL SELECT** statements the method returns
245
- * - [DbResult.BE_SQLITE_ROW]($core-bentley) if the statement now points successfully to the next row.
246
- * - [DbResult.BE_SQLITE_DONE]($core-bentley) if the statement has no more rows.
247
- * - Error status in case of errors.
248
- *
249
- * For **ECSQL INSERT, UPDATE, DELETE** statements the method returns
250
- * - [DbResult.BE_SQLITE_DONE]($core-bentley) if the statement has been executed successfully.
251
- * - Error status in case of errors.
252
- *
253
- * > Insert statements can be used with ECDb only, not with IModelDb.
254
- *
255
- * See also: [Code Samples]($docs/learning/backend/ECSQLCodeExamples)
256
- */
257
- step() { return this._stmt.step(); } // eslint-disable-line @typescript-eslint/no-non-null-assertion
258
- /** @internal added this back in for testing purposes */
259
- async stepAsync() {
260
- return new Promise((resolve, _reject) => {
261
- this._stmt.stepAsync(resolve); // eslint-disable-line @typescript-eslint/no-non-null-assertion
262
- });
263
- }
264
- /** Step this INSERT statement and returns status and the ECInstanceId of the newly
265
- * created instance.
266
- *
267
- * > Insert statements can be used with ECDb only, not with IModelDb.
268
- *
269
- * @returns Returns the generated ECInstanceId in case of success and the status of the step
270
- * call. In case of error, the respective error code is returned.
271
- */
272
- stepForInsert() {
273
- (0, core_bentley_1.assert)(undefined !== this._stmt);
274
- const r = this._stmt.stepForInsert();
275
- if (r.status === core_bentley_1.DbResult.BE_SQLITE_DONE)
276
- return new ECSqlInsertResult(r.status, r.id);
277
- return new ECSqlInsertResult(r.status);
278
- }
279
- /** Get the query result's column count (only for ECSQL SELECT statements). */
280
- getColumnCount() { return this._stmt.getColumnCount(); } // eslint-disable-line @typescript-eslint/no-non-null-assertion
281
- /** Get the current row.
282
- * The returned row is formatted as JavaScript object where every SELECT clause item becomes a property in the JavaScript object.
283
- *
284
- * See also:
285
- * - [ECSQL row format]($docs/learning/ECSQLRowFormat) for details about the format of the returned row.
286
- * - [Code Samples]($docs/learning/backend/ECSQLCodeExamples#working-with-the-query-result)
287
- */
288
- getRow() {
289
- const colCount = this.getColumnCount();
290
- const row = {};
291
- const duplicatePropNames = new Map();
292
- for (let i = 0; i < colCount; i++) {
293
- const ecsqlValue = this.getValue(i);
294
- if (!ecsqlValue.isNull) {
295
- const propName = ECSqlStatement.determineResultRowPropertyName(duplicatePropNames, ecsqlValue);
296
- const val = ecsqlValue.value;
297
- Object.defineProperty(row, propName, { enumerable: true, configurable: true, writable: true, value: val });
298
- }
299
- }
300
- return row;
301
- }
302
- static determineResultRowPropertyName(duplicatePropNames, ecsqlValue) {
303
- const colInfo = ecsqlValue.columnInfo;
304
- let jsName = core_common_1.ECJsNames.toJsName(colInfo.getAccessString(), colInfo.isSystemProperty());
305
- // now check duplicates. If there are, append a numeric suffix to the duplicates
306
- let suffix = duplicatePropNames.get(jsName);
307
- if (suffix === undefined)
308
- duplicatePropNames.set(jsName, 0);
309
- else {
310
- suffix++;
311
- duplicatePropNames.set(jsName, suffix);
312
- jsName += `_${suffix}`;
313
- }
314
- return jsName;
315
- }
316
- /** Calls step when called as an iterator.
317
- *
318
- * Each iteration returns an [ECSQL row format]($docs/learning/ECSQLRowFormat) as returned
319
- * from [ECSqlStatement.getRow]($backend).
320
- */
321
- next() {
322
- if (core_bentley_1.DbResult.BE_SQLITE_ROW === this.step()) {
323
- return {
324
- done: false,
325
- value: this.getRow(),
326
- };
327
- }
328
- else {
329
- return {
330
- done: true,
331
- value: undefined,
332
- };
333
- }
334
- }
335
- /** The iterator that will step through the results of this statement. */
336
- [Symbol.iterator]() { return this; }
337
- /** Get the value for the column at the given index in the query result.
338
- * @param columnIx Index of ECSQL column in query result (0-based)
339
- *
340
- * See also: [Code Samples]($docs/learning/backend/ECSQLCodeExamples#working-with-the-query-result)
341
- */
342
- getValue(columnIx) {
343
- (0, core_bentley_1.assert)(undefined !== this._stmt);
344
- return new ECSqlValue(this._stmt.getValue(columnIx));
345
- }
346
- }
347
- exports.ECSqlStatement = ECSqlStatement;
348
- /** Binds a value to an ECSQL parameter.
349
- *
350
- * See also:
351
- *
352
- * - [ECSqlStatement]($backend)
353
- * - [ECSqlStatement.getBinder]($backend)
354
- * - [Executing ECSQL]($docs/learning/backend/ExecutingECSQL)
355
- * @public
356
- */
357
- class ECSqlBinder {
358
- /** @internal */
359
- constructor(binder) { this._binder = binder; }
360
- /** Binds the specified value to the ECSQL parameter.
361
- * The section "[iTwin.js Types used in ECSQL Parameter Bindings]($docs/learning/ECSQLParameterTypes)" describes the
362
- * iTwin.js types to be used for the different ECSQL parameter types.
363
- * @param val Value to bind
364
- */
365
- bind(val) {
366
- ECSqlBindingHelper.bindValue(this, val);
367
- }
368
- /** Binds null to the ECSQL parameter. */
369
- bindNull() {
370
- const stat = this._binder.bindNull();
371
- if (stat !== core_bentley_1.DbResult.BE_SQLITE_OK)
372
- throw new core_common_1.IModelError(stat, "Error binding null");
373
- }
374
- /** Binds a BLOB value to the ECSQL parameter.
375
- * @param BLOB value as either a UInt8Array, ArrayBuffer or a Base64 string
376
- */
377
- bindBlob(blob) {
378
- const stat = this._binder.bindBlob(blob);
379
- if (stat !== core_bentley_1.DbResult.BE_SQLITE_OK)
380
- throw new core_common_1.IModelError(stat, "Error binding blob");
381
- }
382
- /** Binds a boolean value to the ECSQL parameter.
383
- * @param val Boolean value
384
- */
385
- bindBoolean(val) {
386
- const stat = this._binder.bindBoolean(val);
387
- if (stat !== core_bentley_1.DbResult.BE_SQLITE_OK)
388
- throw new core_common_1.IModelError(stat, "Error binding boolean");
389
- }
390
- /** Binds a DateTime value to the ECSQL parameter.
391
- * @param isoDateTimeString DateTime value as ISO8601 string
392
- */
393
- bindDateTime(isoDateTimeString) {
394
- const stat = this._binder.bindDateTime(isoDateTimeString);
395
- if (stat !== core_bentley_1.DbResult.BE_SQLITE_OK)
396
- throw new core_common_1.IModelError(stat, "Error binding DateTime");
397
- }
398
- /** Binds a double value to the ECSQL parameter.
399
- * @param val Double value
400
- */
401
- bindDouble(val) {
402
- const stat = this._binder.bindDouble(val);
403
- if (stat !== core_bentley_1.DbResult.BE_SQLITE_OK)
404
- throw new core_common_1.IModelError(stat, "Error binding double");
405
- }
406
- /** Binds an GUID value to the ECSQL parameter.
407
- * @param val GUID value. If passed as string, it must be formatted as described in [GuidString]($core-bentley).
408
- */
409
- bindGuid(val) {
410
- const stat = this._binder.bindGuid(val);
411
- if (stat !== core_bentley_1.DbResult.BE_SQLITE_OK)
412
- throw new core_common_1.IModelError(stat, "Error binding GUID");
413
- }
414
- /** Binds an Id value to the ECSQL parameter.
415
- * @param val Id value. If passed as string it must be the hexadecimal representation of the Id.
416
- */
417
- bindId(val) {
418
- const stat = this._binder.bindId(val);
419
- if (stat !== core_bentley_1.DbResult.BE_SQLITE_OK)
420
- throw new core_common_1.IModelError(stat, "Error binding Id");
421
- }
422
- /** Binds an integer value to the ECSQL parameter.
423
- * @param val Integer value as number, decimal string or hexadecimal string.
424
- */
425
- bindInteger(val) {
426
- const stat = this._binder.bindInteger(val);
427
- if (stat !== core_bentley_1.DbResult.BE_SQLITE_OK)
428
- throw new core_common_1.IModelError(stat, "Error binding integer");
429
- }
430
- /** Binds an Point2d value to the ECSQL parameter.
431
- * @param val Point2d value
432
- */
433
- bindPoint2d(val) {
434
- const stat = this._binder.bindPoint2d(val.x, val.y);
435
- if (stat !== core_bentley_1.DbResult.BE_SQLITE_OK)
436
- throw new core_common_1.IModelError(stat, "Error binding Point2d");
437
- }
438
- /** Binds an Point3d value to the ECSQL parameter.
439
- * @param val Point3d value
440
- */
441
- bindPoint3d(val) {
442
- const stat = this._binder.bindPoint3d(val.x, val.y, val.z);
443
- if (stat !== core_bentley_1.DbResult.BE_SQLITE_OK)
444
- throw new core_common_1.IModelError(stat, "Error binding Point3d");
445
- }
446
- /** Binds a Range3d as a blob to the ECSQL parameter.
447
- * @param val Range3d value
448
- */
449
- bindRange3d(val) {
450
- const stat = this._binder.bindBlob(core_geometry_1.Range3d.toFloat64Array(val).buffer);
451
- if (stat !== core_bentley_1.DbResult.BE_SQLITE_OK)
452
- throw new core_common_1.IModelError(stat, "Error binding Range3d");
453
- }
454
- /** Binds an string to the ECSQL parameter.
455
- * @param val String value
456
- */
457
- bindString(val) {
458
- const stat = this._binder.bindString(val);
459
- if (stat !== core_bentley_1.DbResult.BE_SQLITE_OK)
460
- throw new core_common_1.IModelError(stat, "Error binding string");
461
- }
462
- /** Binds a navigation property value to the ECSQL parameter.
463
- * @param val Navigation property value
464
- */
465
- bindNavigation(val) {
466
- const stat = this._binder.bindNavigation(val.id, val.relClassName, val.relClassTableSpace);
467
- if (stat !== core_bentley_1.DbResult.BE_SQLITE_OK)
468
- throw new core_common_1.IModelError(stat, "Error binding navigation property");
469
- }
470
- /** Binds a struct property value to the ECSQL parameter.
471
- * @param val Struct value. The struct value is an object composed of pairs of a struct member property name and its value
472
- * (of one of the supported types)
473
- */
474
- bindStruct(val) { ECSqlBindingHelper.bindStruct(this, val); }
475
- /** Gets the binder for the specified member of a struct parameter
476
- *
477
- * > This is the most low-level way to bind struct parameters with most flexibility. A simpler alternative is
478
- * > to just call [ECSqlBinder.bindStruct]($backend).
479
- */
480
- bindMember(memberName) { return new ECSqlBinder(this._binder.bindMember(memberName)); }
481
- /** Binds a set of Id strings to the ECSQL parameter.
482
- * @param val array of Id values. If passed as string they must be the hexadecimal representation of the Ids.
483
- */
484
- bindIdSet(vector) {
485
- const stat = this._binder.bindIdSet(vector);
486
- if (stat !== core_bentley_1.DbResult.BE_SQLITE_OK)
487
- throw new core_common_1.IModelError(stat, "Error binding id set");
488
- }
489
- /** Binds an array value to the ECSQL parameter.
490
- * @param val Array value. The array value is an array of values of the supported types
491
- */
492
- bindArray(val) { ECSqlBindingHelper.bindArray(this, val); }
493
- /** Adds a new array element to the array parameter and returns the binder for the new array element
494
- *
495
- * > This is the most low-level way to bind array parameters with most flexibility. A simpler alternative is
496
- * > to just call [ECSqlBinder.bindArray]($backend).
497
- */
498
- addArrayElement() { return new ECSqlBinder(this._binder.addArrayElement()); }
499
- }
500
- exports.ECSqlBinder = ECSqlBinder;
501
- /** Value of a column in a row of an ECSQL query result.
502
- *
503
- * See also:
504
- * - [ECSqlStatement]($backend)
505
- * - [ECSqlStatement.getValue]($backend)
506
- * - [Code Samples]($docs/learning/backend/ECSQLCodeExamples#working-with-the-query-result)
507
- * @public
508
- */
509
- class ECSqlValue {
510
- /** @internal */
511
- constructor(val) { this._val = val; }
512
- /** Get information about the query result's column this value refers to. */
513
- get columnInfo() { return this._val.getColumnInfo(); }
514
- /** Get the value of this ECSQL value */
515
- get value() { return ECSqlValueHelper.getValue(this); }
516
- /** Indicates whether the value is NULL or not. */
517
- get isNull() { return this._val.isNull(); }
518
- /** Get the value as BLOB */
519
- getBlob() { return this._val.getBlob(); }
520
- /** Get the value as a boolean value */
521
- getBoolean() { return this._val.getBoolean(); }
522
- /** Get the value as a DateTime value (formatted as ISO8601 string) */
523
- getDateTime() { return this._val.getDateTime(); }
524
- /** Get the value as a double value */
525
- getDouble() { return this._val.getDouble(); }
526
- /** Get the value as a IGeometry value (as ECJSON IGeometry) */
527
- getGeometry() { return JSON.parse(this._val.getGeometry()); }
528
- /** Get the value as a GUID (formatted as GUID string).
529
- * See [GuidString]($core-bentley)
530
- */
531
- getGuid() { return this._val.getGuid(); }
532
- /** Get the value as a Id (formatted as hexadecimal string). */
533
- getId() { return this._val.getId(); }
534
- /** Get the ClassId value formatted as fully qualified class name. */
535
- getClassNameForClassId() { return this._val.getClassNameForClassId(); }
536
- /** Get the value as a integer value */
537
- getInteger() { return this._val.getInt64(); }
538
- /** Get the value as a string value */
539
- getString() { return this._val.getString(); }
540
- /** Get the value as [XAndY]($core-geometry) */
541
- getXAndY() { return this._val.getPoint2d(); }
542
- /** Get the value as [XYAndZ]($core-geometry) */
543
- getXYAndZ() { return this._val.getPoint3d(); }
544
- /** Get the value as ECEnumeration value
545
- * Note: This method is optional. Using [[ECSqlValue.getInteger]] for integral enums and
546
- * [[ECSqlValue.getString]] for string enums respectively are the usual way to get
547
- * enum values. This method can be used if the context of the underlying ECEnumeration
548
- * is required.
549
- * The value is broken down into the ECEnumerators that make it up, if the value
550
- * is a combination of ECEnumerators. If the value is not a strict match of an ECEnumerator
551
- * or a combination of them, undefined is returned.
552
- * > Note: You can call [[ECSqlValue.columnInfo.isEnum]] to find out whether
553
- * > this method can be called or not.
554
- * @return ECEnumeration value(s) or undefined if the ECSqlValue does not represent an ECEnumeration.
555
- * or is not a strict match of an ECEnumerator or a combination of them.
556
- */
557
- getEnum() { return this._val.getEnum(); }
558
- /** Get the value as [NavigationValue]($common) */
559
- getNavigation() { return this._val.getNavigation(); }
560
- /** Get an iterator for iterating the struct members of this struct value. */
561
- getStructIterator() { return new ECSqlValueIterator(this._val.getStructIterator()); }
562
- /** Get this struct value's content as object literal */
563
- getStruct() { return ECSqlValueHelper.getStruct(this); }
564
- /** Get an iterator for iterating the array elements of this array value. */
565
- getArrayIterator() { return new ECSqlValueIterator(this._val.getArrayIterator()); }
566
- /** Get this array value as JavaScript array */
567
- getArray() { return ECSqlValueHelper.getArray(this); }
568
- }
569
- exports.ECSqlValue = ECSqlValue;
570
- /** Iterator over members of a struct [ECSqlValue]($backend) or the elements of an array [ECSqlValue]($backend).
571
- * See [ECSqlValue.getStructIterator]($backend) or [ECSqlValue.getArrayIterator]($backend).
572
- * @public
573
- */
574
- class ECSqlValueIterator {
575
- /** @internal */
576
- constructor(it) { this._it = it; }
577
- next() {
578
- if (this._it.moveNext())
579
- return { done: false, value: new ECSqlValue(this._it.getCurrent()) };
580
- return { done: true, value: undefined };
581
- }
582
- [Symbol.iterator]() { return this; }
583
- }
584
- exports.ECSqlValueIterator = ECSqlValueIterator;
585
- class ECSqlBindingHelper {
586
- /** Binds the specified value to the specified binder
587
- * @param binder Parameter Binder to bind to
588
- * @param val Value to be bound. (See [iTwin.js Types used in ECSQL Parameter Bindings]($docs/learning/ECSQLParameterTypes))
589
- * @throws IModelError in case of errors
590
- */
591
- static bindValue(binder, val) {
592
- // returns false if val is no primitive and returns true if it is primitive and a binding call was done
593
- if (ECSqlBindingHelper.tryBindPrimitiveTypes(binder, val))
594
- return;
595
- if (Array.isArray(val)) {
596
- ECSqlBindingHelper.bindArray(binder, val);
597
- return;
598
- }
599
- if (typeof (val) === "object") {
600
- ECSqlBindingHelper.bindStruct(binder, val);
601
- return;
602
- }
603
- throw new Error(`Bound value is of an unsupported type: ${val}`);
604
- }
605
- /** Binds the specified primitive value to the specified binder
606
- * @param binder Parameter Binder to bind to
607
- * @param val Primitive value to be bound. Must be of one of these types described here:
608
- * [ECSQL Binding types]($docs/learning/ECSQLParameterTypes)
609
- * @throws IModelError in case of errors
610
- */
611
- static bindPrimitive(binder, val) {
612
- if (!ECSqlBindingHelper.tryBindPrimitiveTypes(binder, val))
613
- throw new core_common_1.IModelError(core_bentley_1.DbResult.BE_SQLITE_ERROR, `Binding value is of an unsupported primitive type: ${val}`);
614
- }
615
- /** Binds the specified object to the specified struct binder
616
- * @param binder Struct parameter binder to bind to
617
- * @param val Value to be bound. Must be an Object with members of the supported types
618
- * @throws IModelError in case of errors
619
- */
620
- static bindStruct(binder, val) {
621
- if (val === null || val === undefined) {
622
- binder.bindNull();
623
- return;
624
- }
625
- for (const member of Object.entries(val)) {
626
- const memberName = member[0];
627
- const memberVal = member[1];
628
- ECSqlBindingHelper.bindValue(binder.bindMember(memberName), memberVal);
629
- }
630
- }
631
- /** Binds the specified array to the specified array binder
632
- * @param binder Array parameter binder to bind to
633
- * @param val Value to be bound. Must be an Array with elements of the supported types
634
- * @throws IModelError in case of errors
635
- */
636
- static bindArray(binder, val) {
637
- if (val === null || val === undefined) {
638
- binder.bindNull();
639
- return;
640
- }
641
- for (const element of val) {
642
- ECSqlBindingHelper.bindValue(binder.addArrayElement(), element);
643
- }
644
- }
645
- /** tries to interpret the passed value as known leaf types (primitives and navigation values).
646
- * @returns Returns undefined if the value wasn't a primitive. DbResult if it was a primitive and was bound to the binder
647
- */
648
- static tryBindPrimitiveTypes(binder, val) {
649
- if (val === undefined || val === null) {
650
- binder.bindNull();
651
- return true;
652
- }
653
- if (typeof (val) === "number") {
654
- if (Number.isInteger(val))
655
- binder.bindInteger(val);
656
- else
657
- binder.bindDouble(val);
658
- return true;
659
- }
660
- if (typeof (val) === "boolean") {
661
- binder.bindBoolean(val);
662
- return true;
663
- }
664
- if (typeof (val) === "string") {
665
- binder.bindString(val);
666
- return true;
667
- }
668
- if (ECSqlTypeHelper.isBlob(val)) {
669
- binder.bindBlob(val);
670
- return true;
671
- }
672
- if (ECSqlTypeHelper.isXYAndZ(val)) {
673
- binder.bindPoint3d(val);
674
- return true;
675
- }
676
- if (ECSqlTypeHelper.isXAndY(val)) {
677
- binder.bindPoint2d(val);
678
- return true;
679
- }
680
- if (ECSqlTypeHelper.isLowAndHighXYZ(val)) {
681
- binder.bindRange3d(val);
682
- return true;
683
- }
684
- if (ECSqlTypeHelper.isNavigationBindingValue(val)) {
685
- binder.bindNavigation(val);
686
- return true;
687
- }
688
- return false;
689
- }
690
- }
691
- class ECSqlValueHelper {
692
- static getValue(ecsqlValue) {
693
- if (ecsqlValue.isNull)
694
- return undefined;
695
- const dataType = ecsqlValue.columnInfo.getType();
696
- switch (dataType) {
697
- case core_common_1.ECSqlValueType.Struct:
698
- return ECSqlValueHelper.getStruct(ecsqlValue);
699
- case core_common_1.ECSqlValueType.Navigation:
700
- return ecsqlValue.getNavigation();
701
- case core_common_1.ECSqlValueType.PrimitiveArray:
702
- case core_common_1.ECSqlValueType.StructArray:
703
- return ECSqlValueHelper.getArray(ecsqlValue);
704
- default:
705
- return ECSqlValueHelper.getPrimitiveValue(ecsqlValue);
706
- }
707
- }
708
- static getStruct(ecsqlValue) {
709
- if (ecsqlValue.isNull)
710
- return undefined;
711
- const structVal = {};
712
- const it = ecsqlValue.getStructIterator();
713
- try {
714
- for (const memberECSqlVal of it) {
715
- if (memberECSqlVal.isNull)
716
- continue;
717
- const memberName = core_common_1.ECJsNames.toJsName(memberECSqlVal.columnInfo.getPropertyName());
718
- const memberVal = ECSqlValueHelper.getValue(memberECSqlVal);
719
- Object.defineProperty(structVal, memberName, { enumerable: true, configurable: true, writable: true, value: memberVal });
720
- }
721
- }
722
- finally {
723
- }
724
- return structVal;
725
- }
726
- static getArray(ecsqlValue) {
727
- const arrayVal = [];
728
- const it = ecsqlValue.getArrayIterator();
729
- try {
730
- for (const elementECSqlVal of it) {
731
- const memberVal = ECSqlValueHelper.getValue(elementECSqlVal);
732
- arrayVal.push(memberVal);
733
- }
734
- }
735
- finally {
736
- }
737
- return arrayVal;
738
- }
739
- static getPrimitiveValue(ecsqlValue) {
740
- if (ecsqlValue.isNull)
741
- return undefined;
742
- const colInfo = ecsqlValue.columnInfo;
743
- switch (colInfo.getType()) {
744
- case core_common_1.ECSqlValueType.Blob:
745
- return ecsqlValue.getBlob();
746
- case core_common_1.ECSqlValueType.Boolean:
747
- return ecsqlValue.getBoolean();
748
- case core_common_1.ECSqlValueType.DateTime:
749
- return ecsqlValue.getDateTime();
750
- case core_common_1.ECSqlValueType.Double:
751
- return ecsqlValue.getDouble();
752
- case core_common_1.ECSqlValueType.Geometry:
753
- return ecsqlValue.getGeometry();
754
- case core_common_1.ECSqlValueType.Guid:
755
- return ecsqlValue.getGuid();
756
- case core_common_1.ECSqlValueType.Id: {
757
- if (colInfo.isSystemProperty() && colInfo.getPropertyName().endsWith("ECClassId"))
758
- return ecsqlValue.getClassNameForClassId();
759
- return ecsqlValue.getId();
760
- }
761
- case core_common_1.ECSqlValueType.Int:
762
- case core_common_1.ECSqlValueType.Int64:
763
- return ecsqlValue.getInteger();
764
- case core_common_1.ECSqlValueType.Point2d:
765
- return ecsqlValue.getXAndY();
766
- case core_common_1.ECSqlValueType.Point3d:
767
- return ecsqlValue.getXYAndZ();
768
- case core_common_1.ECSqlValueType.String:
769
- return ecsqlValue.getString();
770
- default:
771
- throw new core_common_1.IModelError(core_bentley_1.DbResult.BE_SQLITE_ERROR, `Unsupported type ${ecsqlValue.columnInfo.getType()} of the ECSQL Value`);
772
- }
773
- }
774
- static queryClassName(ecdb, classId, tableSpace) {
775
- if (!tableSpace)
776
- tableSpace = "main";
777
- return ecdb.withPreparedStatement(`SELECT s.Name, c.Name FROM [${tableSpace}].meta.ECSchemaDef s, JOIN [${tableSpace}].meta.ECClassDef c ON s.ECInstanceId=c.SchemaId WHERE c.ECInstanceId=?`, (stmt) => {
778
- stmt.bindId(1, classId);
779
- if (stmt.step() !== core_bentley_1.DbResult.BE_SQLITE_ROW)
780
- throw new core_common_1.IModelError(core_bentley_1.DbResult.BE_SQLITE_ERROR, `No class found with ECClassId ${classId} in table space ${tableSpace}.`);
781
- return `${stmt.getValue(0).getString()}.${stmt.getValue(1).getString()}`;
782
- });
783
- }
784
- }
785
- class ECSqlTypeHelper {
786
- static isBlob(val) { return val instanceof Uint8Array; }
787
- static isXAndY(val) { return core_geometry_1.XYZ.isXAndY(val); }
788
- static isXYAndZ(val) { return core_geometry_1.XYZ.isXYAndZ(val); }
789
- static isLowAndHighXYZ(arg) { return arg.low !== undefined && ECSqlTypeHelper.isXYAndZ(arg.low) && arg.high !== undefined && ECSqlTypeHelper.isXYAndZ(arg.high); }
790
- static isNavigationBindingValue(val) { return val.id !== undefined && typeof (val.id) === "string"; }
791
- }
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ /** @packageDocumentation
7
+ * @module ECSQL
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.ECSqlValueIterator = exports.ECSqlValue = exports.ECSqlBinder = exports.ECSqlStatement = exports.ECSqlInsertResult = void 0;
11
+ const core_bentley_1 = require("@itwin/core-bentley");
12
+ const core_geometry_1 = require("@itwin/core-geometry");
13
+ const core_common_1 = require("@itwin/core-common");
14
+ const IModelHost_1 = require("./IModelHost");
15
+ /** The result of an **ECSQL INSERT** statement as returned from [ECSqlStatement.stepForInsert]($backend).
16
+ *
17
+ * If the step was successful, the ECSqlInsertResult contains
18
+ * [DbResult.BE_SQLITE_DONE]($core-bentley)
19
+ * and the ECInstanceId of the newly created instance.
20
+ * In case of failure it contains the [DbResult]($core-bentley) error code.
21
+ *
22
+ * > Insert statements can be used with ECDb only, not with IModelDb.
23
+ * @public
24
+ */
25
+ class ECSqlInsertResult {
26
+ constructor(status, id) {
27
+ this.status = status;
28
+ this.id = id;
29
+ }
30
+ }
31
+ exports.ECSqlInsertResult = ECSqlInsertResult;
32
+ /** Executes ECSQL statements.
33
+ *
34
+ * A statement must be prepared before it can be executed, and it must be released when no longer needed.
35
+ * See [IModelDb.withPreparedStatement]($backend) or
36
+ * [ECDb.withPreparedStatement]($backend) for a convenient and
37
+ * reliable way to prepare, execute, and then release a statement.
38
+ *
39
+ * A statement may contain parameters that must be filled in before use by the **bind** methods.
40
+ *
41
+ * Once prepared (and parameters are bound, if any), the statement is executed by calling [ECSqlStatement.step]($backend).
42
+ * In case of an **ECSQL SELECT** statement, the current row can be retrieved with [ECSqlStatement.getRow]($backend) as
43
+ * a whole, or with [ECSqlStatement.getValue]($backend) when individual values are needed.
44
+ * Alternatively, query results of an **ECSQL SELECT** statement can be stepped through by using
45
+ * standard iteration syntax, such as `for of`.
46
+ *
47
+ * > Preparing a statement can be time-consuming. The best way to reduce the effect of this overhead is to cache and reuse prepared
48
+ * > statements. A cached prepared statement may be used in different places in an app, as long as the statement is general enough.
49
+ * > The key to making this strategy work is to phrase a statement in a general way and use placeholders to represent parameters that will vary on each use.
50
+ *
51
+ * See also
52
+ * - [Executing ECSQL]($docs/learning/backend/ExecutingECSQL) provides more background on ECSQL and an introduction on how to execute ECSQL with the iTwin.js API.
53
+ * - [Code Examples]($docs/learning/backend/ECSQLCodeExamples) illustrate the use of the iTwin.js API for executing and working with ECSQL
54
+ * @public
55
+ */
56
+ class ECSqlStatement {
57
+ get sql() { return this._sql; } // eslint-disable-line @typescript-eslint/no-non-null-assertion
58
+ /** Check if this statement has been prepared successfully or not */
59
+ get isPrepared() { return !!this._stmt; }
60
+ /** Prepare this statement prior to first use.
61
+ * @param db The DgnDb or ECDb to prepare the statement against
62
+ * @param ecsql The ECSQL statement string to prepare
63
+ * @param logErrors Determine if errors are logged or not
64
+ * @throws [IModelError]($common) if the ECSQL statement cannot be prepared. Normally, prepare fails due to ECSQL syntax errors or references to tables or properties that do not exist.
65
+ * The error.message property will provide details.
66
+ * @internal
67
+ */
68
+ prepare(db, ecsql, logErrors = true) {
69
+ const stat = this.tryPrepare(db, ecsql, logErrors);
70
+ if (stat.status !== core_bentley_1.DbResult.BE_SQLITE_OK) {
71
+ throw new core_common_1.IModelError(stat.status, stat.message);
72
+ }
73
+ }
74
+ /** Prepare this statement prior to first use.
75
+ * @param db The DgnDb or ECDb to prepare the statement against
76
+ * @param ecsql The ECSQL statement string to prepare
77
+ * @param logErrors Determine if errors are logged or not, its set to false by default for tryPrepare()
78
+ * @returns A [StatusCodeWithMessage]($bentley) object with a `status` member equal to [DbResult.BE_SQLITE_OK]($bentley) on success. Upon error, the `message` member will provide details.
79
+ * @internal
80
+ */
81
+ tryPrepare(db, ecsql, logErrors = false) {
82
+ if (this.isPrepared)
83
+ throw new Error("ECSqlStatement is already prepared");
84
+ this._sql = ecsql;
85
+ this._stmt = new IModelHost_1.IModelHost.platform.ECSqlStatement();
86
+ return this._stmt.prepare(db, ecsql, logErrors);
87
+ }
88
+ /** Reset this statement so that the next call to step will return the first row, if any. */
89
+ reset() {
90
+ (0, core_bentley_1.assert)(undefined !== this._stmt);
91
+ this._stmt.reset();
92
+ }
93
+ /** Get the Native SQL statement
94
+ * @internal
95
+ */
96
+ getNativeSql() {
97
+ (0, core_bentley_1.assert)(undefined !== this._stmt);
98
+ return this._stmt.getNativeSql();
99
+ }
100
+ /** Call this function when finished with this statement. This releases the native resources held by the statement.
101
+ *
102
+ * > Do not call this method directly on a statement that is being managed by a statement cache.
103
+ */
104
+ dispose() {
105
+ if (this._stmt) {
106
+ this._stmt.dispose(); // free native statement
107
+ this._stmt = undefined;
108
+ }
109
+ }
110
+ /** Binds the specified value to the specified ECSQL parameter.
111
+ * The section "[iTwin.js Types used in ECSQL Parameter Bindings]($docs/learning/ECSQLParameterTypes)" describes the
112
+ * iTwin.js types to be used for the different ECSQL parameter types.
113
+ * @param parameter Index (1-based) or name of the parameter
114
+ */
115
+ bindValue(parameter, val) { this.getBinder(parameter).bind(val); }
116
+ /** Binds null to the specified ECSQL parameter.
117
+ * @param parameter Index (1-based) or name of the parameter
118
+ */
119
+ bindNull(parameter) { this.getBinder(parameter).bindNull(); }
120
+ /** Binds a BLOB value to the specified ECSQL parameter.
121
+ * @param parameter Index (1-based) or name of the parameter
122
+ * @param BLOB value as either a Uint8Array, ArrayBuffer or a Base64 string
123
+ */
124
+ bindBlob(parameter, blob) { this.getBinder(parameter).bindBlob(blob); }
125
+ /** Binds a boolean value to the specified ECSQL parameter.
126
+ * @param parameter Index (1-based) or name of the parameter
127
+ * @param val Boolean value
128
+ */
129
+ bindBoolean(parameter, val) { this.getBinder(parameter).bindBoolean(val); }
130
+ /** Binds a DateTime value to the specified ECSQL parameter.
131
+ * @param parameter Index (1-based) or name of the parameter
132
+ * @param isoDateTimeString DateTime value as ISO8601 string
133
+ */
134
+ bindDateTime(parameter, isoDateTimeString) { this.getBinder(parameter).bindDateTime(isoDateTimeString); }
135
+ /** Binds a double value to the specified ECSQL parameter.
136
+ * @param parameter Index (1-based) or name of the parameter
137
+ * @param val Double value
138
+ */
139
+ bindDouble(parameter, val) { this.getBinder(parameter).bindDouble(val); }
140
+ /** Binds an GUID value to the specified ECSQL parameter.
141
+ * @param parameter Index (1-based) or name of the parameter
142
+ * @param val GUID value
143
+ */
144
+ bindGuid(parameter, val) { this.getBinder(parameter).bindGuid(val); }
145
+ /** Binds an Id value to the specified ECSQL parameter.
146
+ * @param parameter Index (1-based) or name of the parameter
147
+ * @param val Id value
148
+ */
149
+ bindId(parameter, val) { this.getBinder(parameter).bindId(val); }
150
+ /** Binds an integer value to the specified ECSQL parameter.
151
+ * @param parameter Index (1-based) or name of the parameter
152
+ * @param val Integer value as number, decimal string or hexadecimal string.
153
+ */
154
+ bindInteger(parameter, val) { this.getBinder(parameter).bindInteger(val); }
155
+ /** Binds an Point2d value to the specified ECSQL parameter.
156
+ * @param parameter Index (1-based) or name of the parameter
157
+ * @param val Point2d value
158
+ */
159
+ bindPoint2d(parameter, val) { this.getBinder(parameter).bindPoint2d(val); }
160
+ /** Binds an Point3d value to the specified ECSQL parameter.
161
+ * @param parameter Index (1-based) or name of the parameter
162
+ * @param val Point3d value
163
+ */
164
+ bindPoint3d(parameter, val) { this.getBinder(parameter).bindPoint3d(val); }
165
+ /** Binds a Range3d as a blob to the specified ECSQL parameter
166
+ * @param parameter Index(1-based) or name of the parameter
167
+ * @param val Range3d value
168
+ */
169
+ bindRange3d(parameter, val) { this.getBinder(parameter).bindRange3d(val); }
170
+ /** Binds an string to the specified ECSQL parameter.
171
+ * @param parameter Index (1-based) or name of the parameter
172
+ * @param val String value
173
+ */
174
+ bindString(parameter, val) { this.getBinder(parameter).bindString(val); }
175
+ /** Binds a navigation property value to the specified ECSQL parameter.
176
+ * @param parameter Index (1-based) or name of the parameter
177
+ * @param val Navigation property value
178
+ */
179
+ bindNavigation(parameter, val) { this.getBinder(parameter).bindNavigation(val); }
180
+ /** Binds a struct property value to the specified ECSQL parameter.
181
+ * @param parameter Index (1-based) or name of the parameter
182
+ * @param val Struct value. The struct value is an object composed of pairs of a struct member property name and its value
183
+ * (of one of the supported types)
184
+ */
185
+ bindStruct(parameter, val) { this.getBinder(parameter).bindStruct(val); }
186
+ /** Binds an array value to the specified ECSQL parameter.
187
+ * @param parameter Index (1-based) or name of the parameter
188
+ * @param val Array value. The array value is an array of values of the supported types
189
+ */
190
+ bindArray(parameter, val) { this.getBinder(parameter).bindArray(val); }
191
+ bindIdSet(parameter, val) { this.getBinder(parameter).bindIdSet(val); }
192
+ /**
193
+ * Gets a binder to bind a value for an ECSQL parameter
194
+ * > This is the most low-level API to bind a value to a specific parameter. Alternatively you can use the ECSqlStatement.bindXX methods
195
+ * > or [ECSqlStatement.bindValues]($backend).
196
+ * @param parameter Index (1-based) or name of the parameter
197
+ */
198
+ getBinder(parameter) {
199
+ (0, core_bentley_1.assert)(undefined !== this._stmt);
200
+ return new ECSqlBinder(this._stmt.getBinder(parameter));
201
+ }
202
+ /** Bind values to all parameters in the statement.
203
+ * @param values The values to bind to the parameters.
204
+ * Pass an *array* of values if the parameters are *positional*.
205
+ * Pass an *object of the values keyed on the parameter name* for *named parameters*.
206
+ * The values in either the array or object must match the respective types of the parameter.
207
+ *
208
+ * The section "[iTwin.js Types used in ECSQL Parameter Bindings]($docs/learning/ECSQLParameterTypes)" describes the
209
+ * iTwin.js types to be used for the different ECSQL parameter types.
210
+ *
211
+ * See also these [Code Samples]($docs/learning/backend/ECSQLCodeExamples#binding-to-all-parameters-at-once)
212
+ */
213
+ bindValues(values) {
214
+ if (Array.isArray(values)) {
215
+ for (let i = 0; i < values.length; i++) {
216
+ const paramIndex = i + 1;
217
+ const paramValue = values[i];
218
+ if (paramValue === undefined || paramValue === null)
219
+ continue;
220
+ this.bindValue(paramIndex, paramValue);
221
+ }
222
+ return;
223
+ }
224
+ for (const entry of Object.entries(values)) {
225
+ const paramName = entry[0];
226
+ const paramValue = entry[1];
227
+ if (paramValue === undefined || paramValue === null)
228
+ continue;
229
+ this.bindValue(paramName, paramValue);
230
+ }
231
+ }
232
+ /** Clear any bindings that were previously set on this statement.
233
+ * @throws [IModelError]($common) in case of errors
234
+ */
235
+ clearBindings() {
236
+ if (this._stmt) {
237
+ const stat = this._stmt.clearBindings();
238
+ if (stat !== core_bentley_1.DbResult.BE_SQLITE_OK)
239
+ throw new core_common_1.IModelError(stat, "Error clearing bindings");
240
+ }
241
+ }
242
+ /** Step this statement to the next row.
243
+ *
244
+ * For **ECSQL SELECT** statements the method returns
245
+ * - [DbResult.BE_SQLITE_ROW]($core-bentley) if the statement now points successfully to the next row.
246
+ * - [DbResult.BE_SQLITE_DONE]($core-bentley) if the statement has no more rows.
247
+ * - Error status in case of errors.
248
+ *
249
+ * For **ECSQL INSERT, UPDATE, DELETE** statements the method returns
250
+ * - [DbResult.BE_SQLITE_DONE]($core-bentley) if the statement has been executed successfully.
251
+ * - Error status in case of errors.
252
+ *
253
+ * > Insert statements can be used with ECDb only, not with IModelDb.
254
+ *
255
+ * See also: [Code Samples]($docs/learning/backend/ECSQLCodeExamples)
256
+ */
257
+ step() { return this._stmt.step(); } // eslint-disable-line @typescript-eslint/no-non-null-assertion
258
+ /** @internal added this back in for testing purposes */
259
+ async stepAsync() {
260
+ return new Promise((resolve, _reject) => {
261
+ this._stmt.stepAsync(resolve); // eslint-disable-line @typescript-eslint/no-non-null-assertion
262
+ });
263
+ }
264
+ /** Step this INSERT statement and returns status and the ECInstanceId of the newly
265
+ * created instance.
266
+ *
267
+ * > Insert statements can be used with ECDb only, not with IModelDb.
268
+ *
269
+ * @returns Returns the generated ECInstanceId in case of success and the status of the step
270
+ * call. In case of error, the respective error code is returned.
271
+ */
272
+ stepForInsert() {
273
+ (0, core_bentley_1.assert)(undefined !== this._stmt);
274
+ const r = this._stmt.stepForInsert();
275
+ if (r.status === core_bentley_1.DbResult.BE_SQLITE_DONE)
276
+ return new ECSqlInsertResult(r.status, r.id);
277
+ return new ECSqlInsertResult(r.status);
278
+ }
279
+ /** Get the query result's column count (only for ECSQL SELECT statements). */
280
+ getColumnCount() { return this._stmt.getColumnCount(); } // eslint-disable-line @typescript-eslint/no-non-null-assertion
281
+ /** Get the current row.
282
+ * The returned row is formatted as JavaScript object where every SELECT clause item becomes a property in the JavaScript object.
283
+ *
284
+ * See also:
285
+ * - [ECSQL row format]($docs/learning/ECSQLRowFormat) for details about the format of the returned row.
286
+ * - [Code Samples]($docs/learning/backend/ECSQLCodeExamples#working-with-the-query-result)
287
+ */
288
+ getRow() {
289
+ const colCount = this.getColumnCount();
290
+ const row = {};
291
+ const duplicatePropNames = new Map();
292
+ for (let i = 0; i < colCount; i++) {
293
+ const ecsqlValue = this.getValue(i);
294
+ if (!ecsqlValue.isNull) {
295
+ const propName = ECSqlStatement.determineResultRowPropertyName(duplicatePropNames, ecsqlValue);
296
+ const val = ecsqlValue.value;
297
+ Object.defineProperty(row, propName, { enumerable: true, configurable: true, writable: true, value: val });
298
+ }
299
+ }
300
+ return row;
301
+ }
302
+ static determineResultRowPropertyName(duplicatePropNames, ecsqlValue) {
303
+ const colInfo = ecsqlValue.columnInfo;
304
+ let jsName = core_common_1.ECJsNames.toJsName(colInfo.getAccessString(), colInfo.isSystemProperty());
305
+ // now check duplicates. If there are, append a numeric suffix to the duplicates
306
+ let suffix = duplicatePropNames.get(jsName);
307
+ if (suffix === undefined)
308
+ duplicatePropNames.set(jsName, 0);
309
+ else {
310
+ suffix++;
311
+ duplicatePropNames.set(jsName, suffix);
312
+ jsName += `_${suffix}`;
313
+ }
314
+ return jsName;
315
+ }
316
+ /** Calls step when called as an iterator.
317
+ *
318
+ * Each iteration returns an [ECSQL row format]($docs/learning/ECSQLRowFormat) as returned
319
+ * from [ECSqlStatement.getRow]($backend).
320
+ */
321
+ next() {
322
+ if (core_bentley_1.DbResult.BE_SQLITE_ROW === this.step()) {
323
+ return {
324
+ done: false,
325
+ value: this.getRow(),
326
+ };
327
+ }
328
+ else {
329
+ return {
330
+ done: true,
331
+ value: undefined,
332
+ };
333
+ }
334
+ }
335
+ /** The iterator that will step through the results of this statement. */
336
+ [Symbol.iterator]() { return this; }
337
+ /** Get the value for the column at the given index in the query result.
338
+ * @param columnIx Index of ECSQL column in query result (0-based)
339
+ *
340
+ * See also: [Code Samples]($docs/learning/backend/ECSQLCodeExamples#working-with-the-query-result)
341
+ */
342
+ getValue(columnIx) {
343
+ (0, core_bentley_1.assert)(undefined !== this._stmt);
344
+ return new ECSqlValue(this._stmt.getValue(columnIx));
345
+ }
346
+ }
347
+ exports.ECSqlStatement = ECSqlStatement;
348
+ /** Binds a value to an ECSQL parameter.
349
+ *
350
+ * See also:
351
+ *
352
+ * - [ECSqlStatement]($backend)
353
+ * - [ECSqlStatement.getBinder]($backend)
354
+ * - [Executing ECSQL]($docs/learning/backend/ExecutingECSQL)
355
+ * @public
356
+ */
357
+ class ECSqlBinder {
358
+ /** @internal */
359
+ constructor(binder) { this._binder = binder; }
360
+ /** Binds the specified value to the ECSQL parameter.
361
+ * The section "[iTwin.js Types used in ECSQL Parameter Bindings]($docs/learning/ECSQLParameterTypes)" describes the
362
+ * iTwin.js types to be used for the different ECSQL parameter types.
363
+ * @param val Value to bind
364
+ */
365
+ bind(val) {
366
+ ECSqlBindingHelper.bindValue(this, val);
367
+ }
368
+ /** Binds null to the ECSQL parameter. */
369
+ bindNull() {
370
+ const stat = this._binder.bindNull();
371
+ if (stat !== core_bentley_1.DbResult.BE_SQLITE_OK)
372
+ throw new core_common_1.IModelError(stat, "Error binding null");
373
+ }
374
+ /** Binds a BLOB value to the ECSQL parameter.
375
+ * @param BLOB value as either a UInt8Array, ArrayBuffer or a Base64 string
376
+ */
377
+ bindBlob(blob) {
378
+ const stat = this._binder.bindBlob(blob);
379
+ if (stat !== core_bentley_1.DbResult.BE_SQLITE_OK)
380
+ throw new core_common_1.IModelError(stat, "Error binding blob");
381
+ }
382
+ /** Binds a boolean value to the ECSQL parameter.
383
+ * @param val Boolean value
384
+ */
385
+ bindBoolean(val) {
386
+ const stat = this._binder.bindBoolean(val);
387
+ if (stat !== core_bentley_1.DbResult.BE_SQLITE_OK)
388
+ throw new core_common_1.IModelError(stat, "Error binding boolean");
389
+ }
390
+ /** Binds a DateTime value to the ECSQL parameter.
391
+ * @param isoDateTimeString DateTime value as ISO8601 string
392
+ */
393
+ bindDateTime(isoDateTimeString) {
394
+ const stat = this._binder.bindDateTime(isoDateTimeString);
395
+ if (stat !== core_bentley_1.DbResult.BE_SQLITE_OK)
396
+ throw new core_common_1.IModelError(stat, "Error binding DateTime");
397
+ }
398
+ /** Binds a double value to the ECSQL parameter.
399
+ * @param val Double value
400
+ */
401
+ bindDouble(val) {
402
+ const stat = this._binder.bindDouble(val);
403
+ if (stat !== core_bentley_1.DbResult.BE_SQLITE_OK)
404
+ throw new core_common_1.IModelError(stat, "Error binding double");
405
+ }
406
+ /** Binds an GUID value to the ECSQL parameter.
407
+ * @param val GUID value. If passed as string, it must be formatted as described in [GuidString]($core-bentley).
408
+ */
409
+ bindGuid(val) {
410
+ const stat = this._binder.bindGuid(val);
411
+ if (stat !== core_bentley_1.DbResult.BE_SQLITE_OK)
412
+ throw new core_common_1.IModelError(stat, "Error binding GUID");
413
+ }
414
+ /** Binds an Id value to the ECSQL parameter.
415
+ * @param val Id value. If passed as string it must be the hexadecimal representation of the Id.
416
+ */
417
+ bindId(val) {
418
+ const stat = this._binder.bindId(val);
419
+ if (stat !== core_bentley_1.DbResult.BE_SQLITE_OK)
420
+ throw new core_common_1.IModelError(stat, "Error binding Id");
421
+ }
422
+ /** Binds an integer value to the ECSQL parameter.
423
+ * @param val Integer value as number, decimal string or hexadecimal string.
424
+ */
425
+ bindInteger(val) {
426
+ const stat = this._binder.bindInteger(val);
427
+ if (stat !== core_bentley_1.DbResult.BE_SQLITE_OK)
428
+ throw new core_common_1.IModelError(stat, "Error binding integer");
429
+ }
430
+ /** Binds an Point2d value to the ECSQL parameter.
431
+ * @param val Point2d value
432
+ */
433
+ bindPoint2d(val) {
434
+ const stat = this._binder.bindPoint2d(val.x, val.y);
435
+ if (stat !== core_bentley_1.DbResult.BE_SQLITE_OK)
436
+ throw new core_common_1.IModelError(stat, "Error binding Point2d");
437
+ }
438
+ /** Binds an Point3d value to the ECSQL parameter.
439
+ * @param val Point3d value
440
+ */
441
+ bindPoint3d(val) {
442
+ const stat = this._binder.bindPoint3d(val.x, val.y, val.z);
443
+ if (stat !== core_bentley_1.DbResult.BE_SQLITE_OK)
444
+ throw new core_common_1.IModelError(stat, "Error binding Point3d");
445
+ }
446
+ /** Binds a Range3d as a blob to the ECSQL parameter.
447
+ * @param val Range3d value
448
+ */
449
+ bindRange3d(val) {
450
+ const stat = this._binder.bindBlob(core_geometry_1.Range3d.toFloat64Array(val).buffer);
451
+ if (stat !== core_bentley_1.DbResult.BE_SQLITE_OK)
452
+ throw new core_common_1.IModelError(stat, "Error binding Range3d");
453
+ }
454
+ /** Binds an string to the ECSQL parameter.
455
+ * @param val String value
456
+ */
457
+ bindString(val) {
458
+ const stat = this._binder.bindString(val);
459
+ if (stat !== core_bentley_1.DbResult.BE_SQLITE_OK)
460
+ throw new core_common_1.IModelError(stat, "Error binding string");
461
+ }
462
+ /** Binds a navigation property value to the ECSQL parameter.
463
+ * @param val Navigation property value
464
+ */
465
+ bindNavigation(val) {
466
+ const stat = this._binder.bindNavigation(val.id, val.relClassName, val.relClassTableSpace);
467
+ if (stat !== core_bentley_1.DbResult.BE_SQLITE_OK)
468
+ throw new core_common_1.IModelError(stat, "Error binding navigation property");
469
+ }
470
+ /** Binds a struct property value to the ECSQL parameter.
471
+ * @param val Struct value. The struct value is an object composed of pairs of a struct member property name and its value
472
+ * (of one of the supported types)
473
+ */
474
+ bindStruct(val) { ECSqlBindingHelper.bindStruct(this, val); }
475
+ /** Gets the binder for the specified member of a struct parameter
476
+ *
477
+ * > This is the most low-level way to bind struct parameters with most flexibility. A simpler alternative is
478
+ * > to just call [ECSqlBinder.bindStruct]($backend).
479
+ */
480
+ bindMember(memberName) { return new ECSqlBinder(this._binder.bindMember(memberName)); }
481
+ /** Binds a set of Id strings to the ECSQL parameter.
482
+ * @param val array of Id values. If passed as string they must be the hexadecimal representation of the Ids.
483
+ */
484
+ bindIdSet(vector) {
485
+ const stat = this._binder.bindIdSet(vector);
486
+ if (stat !== core_bentley_1.DbResult.BE_SQLITE_OK)
487
+ throw new core_common_1.IModelError(stat, "Error binding id set");
488
+ }
489
+ /** Binds an array value to the ECSQL parameter.
490
+ * @param val Array value. The array value is an array of values of the supported types
491
+ */
492
+ bindArray(val) { ECSqlBindingHelper.bindArray(this, val); }
493
+ /** Adds a new array element to the array parameter and returns the binder for the new array element
494
+ *
495
+ * > This is the most low-level way to bind array parameters with most flexibility. A simpler alternative is
496
+ * > to just call [ECSqlBinder.bindArray]($backend).
497
+ */
498
+ addArrayElement() { return new ECSqlBinder(this._binder.addArrayElement()); }
499
+ }
500
+ exports.ECSqlBinder = ECSqlBinder;
501
+ /** Value of a column in a row of an ECSQL query result.
502
+ *
503
+ * See also:
504
+ * - [ECSqlStatement]($backend)
505
+ * - [ECSqlStatement.getValue]($backend)
506
+ * - [Code Samples]($docs/learning/backend/ECSQLCodeExamples#working-with-the-query-result)
507
+ * @public
508
+ */
509
+ class ECSqlValue {
510
+ /** @internal */
511
+ constructor(val) { this._val = val; }
512
+ /** Get information about the query result's column this value refers to. */
513
+ get columnInfo() { return this._val.getColumnInfo(); }
514
+ /** Get the value of this ECSQL value */
515
+ get value() { return ECSqlValueHelper.getValue(this); }
516
+ /** Indicates whether the value is NULL or not. */
517
+ get isNull() { return this._val.isNull(); }
518
+ /** Get the value as BLOB */
519
+ getBlob() { return this._val.getBlob(); }
520
+ /** Get the value as a boolean value */
521
+ getBoolean() { return this._val.getBoolean(); }
522
+ /** Get the value as a DateTime value (formatted as ISO8601 string) */
523
+ getDateTime() { return this._val.getDateTime(); }
524
+ /** Get the value as a double value */
525
+ getDouble() { return this._val.getDouble(); }
526
+ /** Get the value as a IGeometry value (as ECJSON IGeometry) */
527
+ getGeometry() { return JSON.parse(this._val.getGeometry()); }
528
+ /** Get the value as a GUID (formatted as GUID string).
529
+ * See [GuidString]($core-bentley)
530
+ */
531
+ getGuid() { return this._val.getGuid(); }
532
+ /** Get the value as a Id (formatted as hexadecimal string). */
533
+ getId() { return this._val.getId(); }
534
+ /** Get the ClassId value formatted as fully qualified class name. */
535
+ getClassNameForClassId() { return this._val.getClassNameForClassId(); }
536
+ /** Get the value as a integer value */
537
+ getInteger() { return this._val.getInt64(); }
538
+ /** Get the value as a string value */
539
+ getString() { return this._val.getString(); }
540
+ /** Get the value as [XAndY]($core-geometry) */
541
+ getXAndY() { return this._val.getPoint2d(); }
542
+ /** Get the value as [XYAndZ]($core-geometry) */
543
+ getXYAndZ() { return this._val.getPoint3d(); }
544
+ /** Get the value as ECEnumeration value
545
+ * Note: This method is optional. Using [[ECSqlValue.getInteger]] for integral enums and
546
+ * [[ECSqlValue.getString]] for string enums respectively are the usual way to get
547
+ * enum values. This method can be used if the context of the underlying ECEnumeration
548
+ * is required.
549
+ * The value is broken down into the ECEnumerators that make it up, if the value
550
+ * is a combination of ECEnumerators. If the value is not a strict match of an ECEnumerator
551
+ * or a combination of them, undefined is returned.
552
+ * > Note: You can call [[ECSqlValue.columnInfo.isEnum]] to find out whether
553
+ * > this method can be called or not.
554
+ * @return ECEnumeration value(s) or undefined if the ECSqlValue does not represent an ECEnumeration.
555
+ * or is not a strict match of an ECEnumerator or a combination of them.
556
+ */
557
+ getEnum() { return this._val.getEnum(); }
558
+ /** Get the value as [NavigationValue]($common) */
559
+ getNavigation() { return this._val.getNavigation(); }
560
+ /** Get an iterator for iterating the struct members of this struct value. */
561
+ getStructIterator() { return new ECSqlValueIterator(this._val.getStructIterator()); }
562
+ /** Get this struct value's content as object literal */
563
+ getStruct() { return ECSqlValueHelper.getStruct(this); }
564
+ /** Get an iterator for iterating the array elements of this array value. */
565
+ getArrayIterator() { return new ECSqlValueIterator(this._val.getArrayIterator()); }
566
+ /** Get this array value as JavaScript array */
567
+ getArray() { return ECSqlValueHelper.getArray(this); }
568
+ }
569
+ exports.ECSqlValue = ECSqlValue;
570
+ /** Iterator over members of a struct [ECSqlValue]($backend) or the elements of an array [ECSqlValue]($backend).
571
+ * See [ECSqlValue.getStructIterator]($backend) or [ECSqlValue.getArrayIterator]($backend).
572
+ * @public
573
+ */
574
+ class ECSqlValueIterator {
575
+ /** @internal */
576
+ constructor(it) { this._it = it; }
577
+ next() {
578
+ if (this._it.moveNext())
579
+ return { done: false, value: new ECSqlValue(this._it.getCurrent()) };
580
+ return { done: true, value: undefined };
581
+ }
582
+ [Symbol.iterator]() { return this; }
583
+ }
584
+ exports.ECSqlValueIterator = ECSqlValueIterator;
585
+ class ECSqlBindingHelper {
586
+ /** Binds the specified value to the specified binder
587
+ * @param binder Parameter Binder to bind to
588
+ * @param val Value to be bound. (See [iTwin.js Types used in ECSQL Parameter Bindings]($docs/learning/ECSQLParameterTypes))
589
+ * @throws IModelError in case of errors
590
+ */
591
+ static bindValue(binder, val) {
592
+ // returns false if val is no primitive and returns true if it is primitive and a binding call was done
593
+ if (ECSqlBindingHelper.tryBindPrimitiveTypes(binder, val))
594
+ return;
595
+ if (Array.isArray(val)) {
596
+ ECSqlBindingHelper.bindArray(binder, val);
597
+ return;
598
+ }
599
+ if (typeof (val) === "object") {
600
+ ECSqlBindingHelper.bindStruct(binder, val);
601
+ return;
602
+ }
603
+ throw new Error(`Bound value is of an unsupported type: ${val}`);
604
+ }
605
+ /** Binds the specified primitive value to the specified binder
606
+ * @param binder Parameter Binder to bind to
607
+ * @param val Primitive value to be bound. Must be of one of these types described here:
608
+ * [ECSQL Binding types]($docs/learning/ECSQLParameterTypes)
609
+ * @throws IModelError in case of errors
610
+ */
611
+ static bindPrimitive(binder, val) {
612
+ if (!ECSqlBindingHelper.tryBindPrimitiveTypes(binder, val))
613
+ throw new core_common_1.IModelError(core_bentley_1.DbResult.BE_SQLITE_ERROR, `Binding value is of an unsupported primitive type: ${val}`);
614
+ }
615
+ /** Binds the specified object to the specified struct binder
616
+ * @param binder Struct parameter binder to bind to
617
+ * @param val Value to be bound. Must be an Object with members of the supported types
618
+ * @throws IModelError in case of errors
619
+ */
620
+ static bindStruct(binder, val) {
621
+ if (val === null || val === undefined) {
622
+ binder.bindNull();
623
+ return;
624
+ }
625
+ for (const member of Object.entries(val)) {
626
+ const memberName = member[0];
627
+ const memberVal = member[1];
628
+ ECSqlBindingHelper.bindValue(binder.bindMember(memberName), memberVal);
629
+ }
630
+ }
631
+ /** Binds the specified array to the specified array binder
632
+ * @param binder Array parameter binder to bind to
633
+ * @param val Value to be bound. Must be an Array with elements of the supported types
634
+ * @throws IModelError in case of errors
635
+ */
636
+ static bindArray(binder, val) {
637
+ if (val === null || val === undefined) {
638
+ binder.bindNull();
639
+ return;
640
+ }
641
+ for (const element of val) {
642
+ ECSqlBindingHelper.bindValue(binder.addArrayElement(), element);
643
+ }
644
+ }
645
+ /** tries to interpret the passed value as known leaf types (primitives and navigation values).
646
+ * @returns Returns undefined if the value wasn't a primitive. DbResult if it was a primitive and was bound to the binder
647
+ */
648
+ static tryBindPrimitiveTypes(binder, val) {
649
+ if (val === undefined || val === null) {
650
+ binder.bindNull();
651
+ return true;
652
+ }
653
+ if (typeof (val) === "number") {
654
+ if (Number.isInteger(val))
655
+ binder.bindInteger(val);
656
+ else
657
+ binder.bindDouble(val);
658
+ return true;
659
+ }
660
+ if (typeof (val) === "boolean") {
661
+ binder.bindBoolean(val);
662
+ return true;
663
+ }
664
+ if (typeof (val) === "string") {
665
+ binder.bindString(val);
666
+ return true;
667
+ }
668
+ if (ECSqlTypeHelper.isBlob(val)) {
669
+ binder.bindBlob(val);
670
+ return true;
671
+ }
672
+ if (ECSqlTypeHelper.isXYAndZ(val)) {
673
+ binder.bindPoint3d(val);
674
+ return true;
675
+ }
676
+ if (ECSqlTypeHelper.isXAndY(val)) {
677
+ binder.bindPoint2d(val);
678
+ return true;
679
+ }
680
+ if (ECSqlTypeHelper.isLowAndHighXYZ(val)) {
681
+ binder.bindRange3d(val);
682
+ return true;
683
+ }
684
+ if (ECSqlTypeHelper.isNavigationBindingValue(val)) {
685
+ binder.bindNavigation(val);
686
+ return true;
687
+ }
688
+ return false;
689
+ }
690
+ }
691
+ class ECSqlValueHelper {
692
+ static getValue(ecsqlValue) {
693
+ if (ecsqlValue.isNull)
694
+ return undefined;
695
+ const dataType = ecsqlValue.columnInfo.getType();
696
+ switch (dataType) {
697
+ case core_common_1.ECSqlValueType.Struct:
698
+ return ECSqlValueHelper.getStruct(ecsqlValue);
699
+ case core_common_1.ECSqlValueType.Navigation:
700
+ return ecsqlValue.getNavigation();
701
+ case core_common_1.ECSqlValueType.PrimitiveArray:
702
+ case core_common_1.ECSqlValueType.StructArray:
703
+ return ECSqlValueHelper.getArray(ecsqlValue);
704
+ default:
705
+ return ECSqlValueHelper.getPrimitiveValue(ecsqlValue);
706
+ }
707
+ }
708
+ static getStruct(ecsqlValue) {
709
+ if (ecsqlValue.isNull)
710
+ return undefined;
711
+ const structVal = {};
712
+ const it = ecsqlValue.getStructIterator();
713
+ try {
714
+ for (const memberECSqlVal of it) {
715
+ if (memberECSqlVal.isNull)
716
+ continue;
717
+ const memberName = core_common_1.ECJsNames.toJsName(memberECSqlVal.columnInfo.getPropertyName());
718
+ const memberVal = ECSqlValueHelper.getValue(memberECSqlVal);
719
+ Object.defineProperty(structVal, memberName, { enumerable: true, configurable: true, writable: true, value: memberVal });
720
+ }
721
+ }
722
+ finally {
723
+ }
724
+ return structVal;
725
+ }
726
+ static getArray(ecsqlValue) {
727
+ const arrayVal = [];
728
+ const it = ecsqlValue.getArrayIterator();
729
+ try {
730
+ for (const elementECSqlVal of it) {
731
+ const memberVal = ECSqlValueHelper.getValue(elementECSqlVal);
732
+ arrayVal.push(memberVal);
733
+ }
734
+ }
735
+ finally {
736
+ }
737
+ return arrayVal;
738
+ }
739
+ static getPrimitiveValue(ecsqlValue) {
740
+ if (ecsqlValue.isNull)
741
+ return undefined;
742
+ const colInfo = ecsqlValue.columnInfo;
743
+ switch (colInfo.getType()) {
744
+ case core_common_1.ECSqlValueType.Blob:
745
+ return ecsqlValue.getBlob();
746
+ case core_common_1.ECSqlValueType.Boolean:
747
+ return ecsqlValue.getBoolean();
748
+ case core_common_1.ECSqlValueType.DateTime:
749
+ return ecsqlValue.getDateTime();
750
+ case core_common_1.ECSqlValueType.Double:
751
+ return ecsqlValue.getDouble();
752
+ case core_common_1.ECSqlValueType.Geometry:
753
+ return ecsqlValue.getGeometry();
754
+ case core_common_1.ECSqlValueType.Guid:
755
+ return ecsqlValue.getGuid();
756
+ case core_common_1.ECSqlValueType.Id: {
757
+ if (colInfo.isSystemProperty() && colInfo.getPropertyName().endsWith("ECClassId"))
758
+ return ecsqlValue.getClassNameForClassId();
759
+ return ecsqlValue.getId();
760
+ }
761
+ case core_common_1.ECSqlValueType.Int:
762
+ case core_common_1.ECSqlValueType.Int64:
763
+ return ecsqlValue.getInteger();
764
+ case core_common_1.ECSqlValueType.Point2d:
765
+ return ecsqlValue.getXAndY();
766
+ case core_common_1.ECSqlValueType.Point3d:
767
+ return ecsqlValue.getXYAndZ();
768
+ case core_common_1.ECSqlValueType.String:
769
+ return ecsqlValue.getString();
770
+ default:
771
+ throw new core_common_1.IModelError(core_bentley_1.DbResult.BE_SQLITE_ERROR, `Unsupported type ${ecsqlValue.columnInfo.getType()} of the ECSQL Value`);
772
+ }
773
+ }
774
+ static queryClassName(ecdb, classId, tableSpace) {
775
+ if (!tableSpace)
776
+ tableSpace = "main";
777
+ return ecdb.withPreparedStatement(`SELECT s.Name, c.Name FROM [${tableSpace}].meta.ECSchemaDef s, JOIN [${tableSpace}].meta.ECClassDef c ON s.ECInstanceId=c.SchemaId WHERE c.ECInstanceId=?`, (stmt) => {
778
+ stmt.bindId(1, classId);
779
+ if (stmt.step() !== core_bentley_1.DbResult.BE_SQLITE_ROW)
780
+ throw new core_common_1.IModelError(core_bentley_1.DbResult.BE_SQLITE_ERROR, `No class found with ECClassId ${classId} in table space ${tableSpace}.`);
781
+ return `${stmt.getValue(0).getString()}.${stmt.getValue(1).getString()}`;
782
+ });
783
+ }
784
+ }
785
+ class ECSqlTypeHelper {
786
+ static isBlob(val) { return val instanceof Uint8Array; }
787
+ static isXAndY(val) { return core_geometry_1.XYZ.isXAndY(val); }
788
+ static isXYAndZ(val) { return core_geometry_1.XYZ.isXYAndZ(val); }
789
+ static isLowAndHighXYZ(arg) { return arg.low !== undefined && ECSqlTypeHelper.isXYAndZ(arg.low) && arg.high !== undefined && ECSqlTypeHelper.isXYAndZ(arg.high); }
790
+ static isNavigationBindingValue(val) { return val.id !== undefined && typeof (val.id) === "string"; }
791
+ }
792
792
  //# sourceMappingURL=ECSqlStatement.js.map