@itwin/core-backend 3.0.0-dev.100

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 (245) hide show
  1. package/CHANGELOG.md +1525 -0
  2. package/LICENSE.md +9 -0
  3. package/README.md +11 -0
  4. package/lib/cjs/AliCloudStorageService.d.ts +12 -0
  5. package/lib/cjs/AliCloudStorageService.d.ts.map +1 -0
  6. package/lib/cjs/AliCloudStorageService.js +70 -0
  7. package/lib/cjs/AliCloudStorageService.js.map +1 -0
  8. package/lib/cjs/BackendHubAccess.d.ts +208 -0
  9. package/lib/cjs/BackendHubAccess.d.ts.map +1 -0
  10. package/lib/cjs/BackendHubAccess.js +42 -0
  11. package/lib/cjs/BackendHubAccess.js.map +1 -0
  12. package/lib/cjs/BackendLoggerCategory.d.ts +83 -0
  13. package/lib/cjs/BackendLoggerCategory.d.ts.map +1 -0
  14. package/lib/cjs/BackendLoggerCategory.js +91 -0
  15. package/lib/cjs/BackendLoggerCategory.js.map +1 -0
  16. package/lib/cjs/BisCoreSchema.d.ts +22 -0
  17. package/lib/cjs/BisCoreSchema.d.ts.map +1 -0
  18. package/lib/cjs/BisCoreSchema.js +61 -0
  19. package/lib/cjs/BisCoreSchema.js.map +1 -0
  20. package/lib/cjs/BriefcaseManager.d.ts +167 -0
  21. package/lib/cjs/BriefcaseManager.d.ts.map +1 -0
  22. package/lib/cjs/BriefcaseManager.js +406 -0
  23. package/lib/cjs/BriefcaseManager.js.map +1 -0
  24. package/lib/cjs/Category.d.ts +154 -0
  25. package/lib/cjs/Category.d.ts.map +1 -0
  26. package/lib/cjs/Category.js +244 -0
  27. package/lib/cjs/Category.js.map +1 -0
  28. package/lib/cjs/ChangeSummaryManager.d.ts +188 -0
  29. package/lib/cjs/ChangeSummaryManager.d.ts.map +1 -0
  30. package/lib/cjs/ChangeSummaryManager.js +444 -0
  31. package/lib/cjs/ChangeSummaryManager.js.map +1 -0
  32. package/lib/cjs/ChangedElementsDb.d.ts +97 -0
  33. package/lib/cjs/ChangedElementsDb.d.ts.map +1 -0
  34. package/lib/cjs/ChangedElementsDb.js +166 -0
  35. package/lib/cjs/ChangedElementsDb.js.map +1 -0
  36. package/lib/cjs/ChangedElementsManager.d.ts +40 -0
  37. package/lib/cjs/ChangedElementsManager.d.ts.map +1 -0
  38. package/lib/cjs/ChangedElementsManager.js +89 -0
  39. package/lib/cjs/ChangedElementsManager.js.map +1 -0
  40. package/lib/cjs/CheckpointManager.d.ts +101 -0
  41. package/lib/cjs/CheckpointManager.d.ts.map +1 -0
  42. package/lib/cjs/CheckpointManager.js +257 -0
  43. package/lib/cjs/CheckpointManager.js.map +1 -0
  44. package/lib/cjs/ClassRegistry.d.ts +72 -0
  45. package/lib/cjs/ClassRegistry.d.ts.map +1 -0
  46. package/lib/cjs/ClassRegistry.js +154 -0
  47. package/lib/cjs/ClassRegistry.js.map +1 -0
  48. package/lib/cjs/CloudStorageBackend.d.ts +46 -0
  49. package/lib/cjs/CloudStorageBackend.d.ts.map +1 -0
  50. package/lib/cjs/CloudStorageBackend.js +157 -0
  51. package/lib/cjs/CloudStorageBackend.js.map +1 -0
  52. package/lib/cjs/CodeSpecs.d.ts +51 -0
  53. package/lib/cjs/CodeSpecs.d.ts.map +1 -0
  54. package/lib/cjs/CodeSpecs.js +113 -0
  55. package/lib/cjs/CodeSpecs.js.map +1 -0
  56. package/lib/cjs/ConcurrentQuery.d.ts +12 -0
  57. package/lib/cjs/ConcurrentQuery.d.ts.map +1 -0
  58. package/lib/cjs/ConcurrentQuery.js +24 -0
  59. package/lib/cjs/ConcurrentQuery.js.map +1 -0
  60. package/lib/cjs/DevTools.d.ts +72 -0
  61. package/lib/cjs/DevTools.d.ts.map +1 -0
  62. package/lib/cjs/DevTools.js +155 -0
  63. package/lib/cjs/DevTools.js.map +1 -0
  64. package/lib/cjs/DisplayStyle.d.ts +107 -0
  65. package/lib/cjs/DisplayStyle.d.ts.map +1 -0
  66. package/lib/cjs/DisplayStyle.js +292 -0
  67. package/lib/cjs/DisplayStyle.js.map +1 -0
  68. package/lib/cjs/ECDb.d.ts +196 -0
  69. package/lib/cjs/ECDb.d.ts.map +1 -0
  70. package/lib/cjs/ECDb.js +354 -0
  71. package/lib/cjs/ECDb.js.map +1 -0
  72. package/lib/cjs/ECSchemaXmlContext.d.ts +18 -0
  73. package/lib/cjs/ECSchemaXmlContext.d.ts.map +1 -0
  74. package/lib/cjs/ECSchemaXmlContext.js +36 -0
  75. package/lib/cjs/ECSchemaXmlContext.js.map +1 -0
  76. package/lib/cjs/ECSqlStatement.d.ts +467 -0
  77. package/lib/cjs/ECSqlStatement.d.ts.map +1 -0
  78. package/lib/cjs/ECSqlStatement.js +783 -0
  79. package/lib/cjs/ECSqlStatement.js.map +1 -0
  80. package/lib/cjs/Element.d.ts +1082 -0
  81. package/lib/cjs/Element.d.ts.map +1 -0
  82. package/lib/cjs/Element.js +1392 -0
  83. package/lib/cjs/Element.js.map +1 -0
  84. package/lib/cjs/ElementAspect.d.ts +157 -0
  85. package/lib/cjs/ElementAspect.d.ts.map +1 -0
  86. package/lib/cjs/ElementAspect.js +179 -0
  87. package/lib/cjs/ElementAspect.js.map +1 -0
  88. package/lib/cjs/ElementGraphics.d.ts +10 -0
  89. package/lib/cjs/ElementGraphics.d.ts.map +1 -0
  90. package/lib/cjs/ElementGraphics.js +42 -0
  91. package/lib/cjs/ElementGraphics.js.map +1 -0
  92. package/lib/cjs/Entity.d.ts +57 -0
  93. package/lib/cjs/Entity.d.ts.map +1 -0
  94. package/lib/cjs/Entity.js +63 -0
  95. package/lib/cjs/Entity.js.map +1 -0
  96. package/lib/cjs/ExportGraphics.d.ts +302 -0
  97. package/lib/cjs/ExportGraphics.d.ts.map +1 -0
  98. package/lib/cjs/ExportGraphics.js +206 -0
  99. package/lib/cjs/ExportGraphics.js.map +1 -0
  100. package/lib/cjs/ExternalSource.d.ts +95 -0
  101. package/lib/cjs/ExternalSource.d.ts.map +1 -0
  102. package/lib/cjs/ExternalSource.js +126 -0
  103. package/lib/cjs/ExternalSource.js.map +1 -0
  104. package/lib/cjs/GeometrySummary.d.ts +5 -0
  105. package/lib/cjs/GeometrySummary.d.ts.map +1 -0
  106. package/lib/cjs/GeometrySummary.js +378 -0
  107. package/lib/cjs/GeometrySummary.js.map +1 -0
  108. package/lib/cjs/IModelCloneContext.d.ts +74 -0
  109. package/lib/cjs/IModelCloneContext.d.ts.map +1 -0
  110. package/lib/cjs/IModelCloneContext.js +130 -0
  111. package/lib/cjs/IModelCloneContext.js.map +1 -0
  112. package/lib/cjs/IModelDb.d.ts +1107 -0
  113. package/lib/cjs/IModelDb.d.ts.map +1 -0
  114. package/lib/cjs/IModelDb.js +2161 -0
  115. package/lib/cjs/IModelDb.js.map +1 -0
  116. package/lib/cjs/IModelHost.d.ts +284 -0
  117. package/lib/cjs/IModelHost.d.ts.map +1 -0
  118. package/lib/cjs/IModelHost.js +411 -0
  119. package/lib/cjs/IModelHost.js.map +1 -0
  120. package/lib/cjs/IModelJsFs.d.ts +63 -0
  121. package/lib/cjs/IModelJsFs.d.ts.map +1 -0
  122. package/lib/cjs/IModelJsFs.js +141 -0
  123. package/lib/cjs/IModelJsFs.js.map +1 -0
  124. package/lib/cjs/IModelSchemaLoader.d.ts +26 -0
  125. package/lib/cjs/IModelSchemaLoader.d.ts.map +1 -0
  126. package/lib/cjs/IModelSchemaLoader.js +95 -0
  127. package/lib/cjs/IModelSchemaLoader.js.map +1 -0
  128. package/lib/cjs/IpcHost.d.ts +99 -0
  129. package/lib/cjs/IpcHost.d.ts.map +1 -0
  130. package/lib/cjs/IpcHost.js +234 -0
  131. package/lib/cjs/IpcHost.js.map +1 -0
  132. package/lib/cjs/LineStyle.d.ts +312 -0
  133. package/lib/cjs/LineStyle.d.ts.map +1 -0
  134. package/lib/cjs/LineStyle.js +296 -0
  135. package/lib/cjs/LineStyle.js.map +1 -0
  136. package/lib/cjs/LocalhostIpcHost.d.ts +19 -0
  137. package/lib/cjs/LocalhostIpcHost.d.ts.map +1 -0
  138. package/lib/cjs/LocalhostIpcHost.js +52 -0
  139. package/lib/cjs/LocalhostIpcHost.js.map +1 -0
  140. package/lib/cjs/Material.d.ts +102 -0
  141. package/lib/cjs/Material.d.ts.map +1 -0
  142. package/lib/cjs/Material.js +146 -0
  143. package/lib/cjs/Material.js.map +1 -0
  144. package/lib/cjs/Model.d.ts +387 -0
  145. package/lib/cjs/Model.d.ts.map +1 -0
  146. package/lib/cjs/Model.js +469 -0
  147. package/lib/cjs/Model.js.map +1 -0
  148. package/lib/cjs/NativeAppStorage.d.ts +52 -0
  149. package/lib/cjs/NativeAppStorage.d.ts.map +1 -0
  150. package/lib/cjs/NativeAppStorage.js +203 -0
  151. package/lib/cjs/NativeAppStorage.js.map +1 -0
  152. package/lib/cjs/NativeHost.d.ts +71 -0
  153. package/lib/cjs/NativeHost.d.ts.map +1 -0
  154. package/lib/cjs/NativeHost.js +221 -0
  155. package/lib/cjs/NativeHost.js.map +1 -0
  156. package/lib/cjs/NavigationRelationship.d.ts +157 -0
  157. package/lib/cjs/NavigationRelationship.d.ts.map +1 -0
  158. package/lib/cjs/NavigationRelationship.js +226 -0
  159. package/lib/cjs/NavigationRelationship.js.map +1 -0
  160. package/lib/cjs/PromiseMemoizer.d.ts +52 -0
  161. package/lib/cjs/PromiseMemoizer.d.ts.map +1 -0
  162. package/lib/cjs/PromiseMemoizer.js +93 -0
  163. package/lib/cjs/PromiseMemoizer.js.map +1 -0
  164. package/lib/cjs/Relationship.d.ts +400 -0
  165. package/lib/cjs/Relationship.d.ts.map +1 -0
  166. package/lib/cjs/Relationship.js +460 -0
  167. package/lib/cjs/Relationship.js.map +1 -0
  168. package/lib/cjs/RpcBackend.d.ts +23 -0
  169. package/lib/cjs/RpcBackend.d.ts.map +1 -0
  170. package/lib/cjs/RpcBackend.js +94 -0
  171. package/lib/cjs/RpcBackend.js.map +1 -0
  172. package/lib/cjs/SQLiteDb.d.ts +66 -0
  173. package/lib/cjs/SQLiteDb.d.ts.map +1 -0
  174. package/lib/cjs/SQLiteDb.js +140 -0
  175. package/lib/cjs/SQLiteDb.js.map +1 -0
  176. package/lib/cjs/Schema.d.ts +56 -0
  177. package/lib/cjs/Schema.d.ts.map +1 -0
  178. package/lib/cjs/Schema.js +84 -0
  179. package/lib/cjs/Schema.js.map +1 -0
  180. package/lib/cjs/ServerBasedLocks.d.ts +64 -0
  181. package/lib/cjs/ServerBasedLocks.d.ts.map +1 -0
  182. package/lib/cjs/ServerBasedLocks.js +177 -0
  183. package/lib/cjs/ServerBasedLocks.js.map +1 -0
  184. package/lib/cjs/SqliteStatement.d.ts +264 -0
  185. package/lib/cjs/SqliteStatement.d.ts.map +1 -0
  186. package/lib/cjs/SqliteStatement.js +417 -0
  187. package/lib/cjs/SqliteStatement.js.map +1 -0
  188. package/lib/cjs/Texture.d.ts +59 -0
  189. package/lib/cjs/Texture.d.ts.map +1 -0
  190. package/lib/cjs/Texture.js +83 -0
  191. package/lib/cjs/Texture.js.map +1 -0
  192. package/lib/cjs/TxnManager.d.ts +203 -0
  193. package/lib/cjs/TxnManager.d.ts.map +1 -0
  194. package/lib/cjs/TxnManager.js +354 -0
  195. package/lib/cjs/TxnManager.js.map +1 -0
  196. package/lib/cjs/ViewDefinition.d.ts +432 -0
  197. package/lib/cjs/ViewDefinition.d.ts.map +1 -0
  198. package/lib/cjs/ViewDefinition.js +623 -0
  199. package/lib/cjs/ViewDefinition.js.map +1 -0
  200. package/lib/cjs/assets/IModelChange.02.00.00.ecschema.xml +90 -0
  201. package/lib/cjs/core-backend.d.ts +162 -0
  202. package/lib/cjs/core-backend.d.ts.map +1 -0
  203. package/lib/cjs/core-backend.js +181 -0
  204. package/lib/cjs/core-backend.js.map +1 -0
  205. package/lib/cjs/domains/FunctionalElements.d.ts +102 -0
  206. package/lib/cjs/domains/FunctionalElements.d.ts.map +1 -0
  207. package/lib/cjs/domains/FunctionalElements.js +146 -0
  208. package/lib/cjs/domains/FunctionalElements.js.map +1 -0
  209. package/lib/cjs/domains/FunctionalSchema.d.ts +14 -0
  210. package/lib/cjs/domains/FunctionalSchema.d.ts.map +1 -0
  211. package/lib/cjs/domains/FunctionalSchema.js +41 -0
  212. package/lib/cjs/domains/FunctionalSchema.js.map +1 -0
  213. package/lib/cjs/domains/GenericElements.d.ts +178 -0
  214. package/lib/cjs/domains/GenericElements.d.ts.map +1 -0
  215. package/lib/cjs/domains/GenericElements.js +264 -0
  216. package/lib/cjs/domains/GenericElements.js.map +1 -0
  217. package/lib/cjs/domains/GenericSchema.d.ts +11 -0
  218. package/lib/cjs/domains/GenericSchema.d.ts.map +1 -0
  219. package/lib/cjs/domains/GenericSchema.js +29 -0
  220. package/lib/cjs/domains/GenericSchema.js.map +1 -0
  221. package/lib/cjs/rpc-impl/DevToolsRpcImpl.d.ts +16 -0
  222. package/lib/cjs/rpc-impl/DevToolsRpcImpl.d.ts.map +1 -0
  223. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js +33 -0
  224. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js.map +1 -0
  225. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts +40 -0
  226. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts.map +1 -0
  227. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +207 -0
  228. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -0
  229. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts +21 -0
  230. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts.map +1 -0
  231. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js +193 -0
  232. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js.map +1 -0
  233. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts +37 -0
  234. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts.map +1 -0
  235. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js +162 -0
  236. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -0
  237. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.d.ts +17 -0
  238. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.d.ts.map +1 -0
  239. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js +44 -0
  240. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js.map +1 -0
  241. package/lib/cjs/rpc-impl/WipRpcImpl.d.ts +16 -0
  242. package/lib/cjs/rpc-impl/WipRpcImpl.d.ts.map +1 -0
  243. package/lib/cjs/rpc-impl/WipRpcImpl.js +35 -0
  244. package/lib/cjs/rpc-impl/WipRpcImpl.js.map +1 -0
  245. package/package.json +101 -0
@@ -0,0 +1,196 @@
1
+ import { IModelJsNative } from "@bentley/imodeljs-native";
2
+ /** @packageDocumentation
3
+ * @module ECDb
4
+ */
5
+ import { IDisposable } from "@itwin/core-bentley";
6
+ import { ECSqlReader, QueryBinder, QueryOptions, QueryRowFormat } from "@itwin/core-common";
7
+ import { ECSqlStatement } from "./ECSqlStatement";
8
+ import { SqliteStatement } from "./SqliteStatement";
9
+ /** Modes for how to open [ECDb]($backend) files.
10
+ * @public
11
+ */
12
+ export declare enum ECDbOpenMode {
13
+ Readonly = 0,
14
+ ReadWrite = 1,
15
+ /** Opens the file read-write and upgrades the file if necessary to the latest file format version. */
16
+ FileUpgrade = 2
17
+ }
18
+ /** An ECDb file
19
+ * @public
20
+ */
21
+ export declare class ECDb implements IDisposable {
22
+ private _nativeDb?;
23
+ private _concurrentQueryInitialized;
24
+ private readonly _statementCache;
25
+ private _sqliteStatementCache;
26
+ private _concurrentQueryStats;
27
+ /** only for tests
28
+ * @internal
29
+ */
30
+ resetSqliteCache(size: number): void;
31
+ constructor();
32
+ /** Call this function when finished with this ECDb object. This releases the native resources held by the
33
+ * ECDb object.
34
+ */
35
+ dispose(): void;
36
+ /** Create an ECDb
37
+ * @param pathName The path to the ECDb file to create.
38
+ * @throws [IModelError]($common) if the operation failed.
39
+ */
40
+ createDb(pathName: string): void;
41
+ /** Open the ECDb.
42
+ * @param pathName The path to the ECDb file to open
43
+ * @param openMode Open mode
44
+ * @throws [IModelError]($common) if the operation failed.
45
+ */
46
+ openDb(pathName: string, openMode?: ECDbOpenMode): void;
47
+ /** Returns true if the ECDb is open */
48
+ get isOpen(): boolean;
49
+ /** Close the Db after saving any uncommitted changes.
50
+ * @throws [IModelError]($common) if the database is not open.
51
+ */
52
+ closeDb(): void;
53
+ /** @internal use to test statement caching */
54
+ clearStatementCache(): void;
55
+ /** @internal use to test statement caching */
56
+ getCachedStatementCount(): number;
57
+ /** Commit the outermost transaction, writing changes to the file. Then, restart the transaction.
58
+ * @param changesetName The name of the operation that generated these changes.
59
+ * @throws [IModelError]($common) if the database is not open or if the operation failed.
60
+ */
61
+ saveChanges(changesetName?: string): void;
62
+ /** Abandon (cancel) the outermost transaction, discarding all changes since last save. Then, restart the transaction.
63
+ * @throws [IModelError]($common) if the database is not open or if the operation failed.
64
+ */
65
+ abandonChanges(): void;
66
+ /** Import a schema.
67
+ *
68
+ * If the import was successful, the database is automatically saved to disk.
69
+ * @param pathName Path to ECSchema XML file to import.
70
+ * @throws [IModelError]($common) if the database is not open or if the operation failed.
71
+ */
72
+ importSchema(pathName: string): void;
73
+ /**
74
+ * Use a prepared ECSQL statement, potentially from the statement cache. If the requested statement doesn't exist
75
+ * in the statement cache, a new statement is prepared. After the callback completes, the statement is reset and saved
76
+ * in the statement cache so it can be reused in the future. Use this method for ECSQL statements that will be
77
+ * reused often and are expensive to prepare. The statement cache holds the most recently used statements, discarding
78
+ * the oldest statements as it fills. For statements you don't intend to reuse, instead use [[withStatement]].
79
+ * @param sql The SQLite SQL statement to execute
80
+ * @param callback the callback to invoke on the prepared statement
81
+ * @param logErrors Determines if error will be logged if statement fail to prepare
82
+ * @returns the value returned by `callback`.
83
+ * @see [[withStatement]]
84
+ * @public
85
+ */
86
+ withPreparedStatement<T>(ecsql: string, callback: (stmt: ECSqlStatement) => T, logErrors?: boolean): T;
87
+ /**
88
+ * Prepared and execute a callback on an ECSQL statement. After the callback completes the statement is disposed.
89
+ * Use this method for ECSQL statements are either not expected to be reused, or are not expensive to prepare.
90
+ * For statements that will be reused often, instead use [[withPreparedStatement]].
91
+ * @param sql The SQLite SQL statement to execute
92
+ * @param callback the callback to invoke on the prepared statement
93
+ * @param logErrors Determines if error will be logged if statement fail to prepare
94
+ * @returns the value returned by `callback`.
95
+ * @see [[withPreparedStatement]]
96
+ * @public
97
+ */
98
+ withStatement<T>(ecsql: string, callback: (stmt: ECSqlStatement) => T, logErrors?: boolean): T;
99
+ /** Prepare an ECSQL statement.
100
+ * @param ecsql The ECSQL statement to prepare
101
+ * @param logErrors Determines if error will be logged if statement fail to prepare
102
+ * @throws [IModelError]($common) if there is a problem preparing the statement.
103
+ */
104
+ prepareStatement(ecsql: string, logErrors?: boolean): ECSqlStatement;
105
+ /**
106
+ * Use a prepared SQL statement, potentially from the statement cache. If the requested statement doesn't exist
107
+ * in the statement cache, a new statement is prepared. After the callback completes, the statement is reset and saved
108
+ * in the statement cache so it can be reused in the future. Use this method for SQL statements that will be
109
+ * reused often and are expensive to prepare. The statement cache holds the most recently used statements, discarding
110
+ * the oldest statements as it fills. For statements you don't intend to reuse, instead use [[withSqliteStatement]].
111
+ * @param sql The SQLite SQL statement to execute
112
+ * @param callback the callback to invoke on the prepared statement
113
+ * @param logErrors Determines if error will be logged if statement fail to prepare
114
+ * @returns the value returned by `callback`.
115
+ * @see [[withPreparedStatement]]
116
+ * @public
117
+ */
118
+ withPreparedSqliteStatement<T>(sql: string, callback: (stmt: SqliteStatement) => T, logErrors?: boolean): T;
119
+ /**
120
+ * Prepared and execute a callback on a SQL statement. After the callback completes the statement is disposed.
121
+ * Use this method for SQL statements are either not expected to be reused, or are not expensive to prepare.
122
+ * For statements that will be reused often, instead use [[withPreparedSqliteStatement]].
123
+ * @param sql The SQLite SQL statement to execute
124
+ * @param callback the callback to invoke on the prepared statement
125
+ * @param logErrors Determines if error will be logged if statement fail to prepare
126
+ * @returns the value returned by `callback`.
127
+ * @public
128
+ */
129
+ withSqliteStatement<T>(sql: string, callback: (stmt: SqliteStatement) => T, logErrors?: boolean): T;
130
+ /** Prepare an SQL statement.
131
+ * @param sql The SQLite SQL statement to prepare
132
+ * @param logErrors Determines if error will be logged if statement fail to prepare
133
+ * @throws [IModelError]($common) if there is a problem preparing the statement.
134
+ * @internal
135
+ */
136
+ prepareSqliteStatement(sql: string, logErrors?: boolean): SqliteStatement;
137
+ /** @internal */
138
+ get nativeDb(): IModelJsNative.ECDb;
139
+ /** Allow to execute query and read results along with meta data. The result are streamed.
140
+ * @param params The values to bind to the parameters (if the ECSQL has any).
141
+ * @param config Allow to specify certain flags which control how query is executed.
142
+ * @returns Returns *ECSqlQueryReader* which help iterate over result set and also give access to meta data.
143
+ * @beta
144
+ * */
145
+ createQueryReader(ecsql: string, params?: QueryBinder, config?: QueryOptions): ECSqlReader;
146
+ /** Execute a query and stream its results
147
+ * The result of the query is async iterator over the rows. The iterator will get next page automatically once rows in current page has been read.
148
+ * [ECSQL row]($docs/learning/ECSQLRowFormat).
149
+ *
150
+ * See also:
151
+ * - [ECSQL Overview]($docs/learning/backend/ExecutingECSQL)
152
+ * - [Code Examples]($docs/learning/backend/ECSQLCodeExamples)
153
+ *
154
+ * @param ecsql The ECSQL statement to execute
155
+ * @param params The values to bind to the parameters (if the ECSQL has any).
156
+ * @param rowFormat Specify what format the row will be returned. It default to Array format though to make it compilable with previous version use *QueryRowFormat.UseJsPropertyNames*
157
+ * @param options Allow to specify certain flags which control how query is executed.
158
+ * @returns Returns the query result as an *AsyncIterableIterator<any>* which lazy load result as needed. The row format is determined by *rowFormat* parameter.
159
+ * See [ECSQL row format]($docs/learning/ECSQLRowFormat) for details about the format of the returned rows.
160
+ * @throws [IModelError]($common) If there was any error while submitting, preparing or stepping into query
161
+ */
162
+ query(ecsql: string, params?: QueryBinder, rowFormat?: QueryRowFormat, options?: QueryOptions): AsyncIterableIterator<any>;
163
+ /** Compute number of rows that would be returned by the ECSQL.
164
+ *
165
+ * See also:
166
+ * - [ECSQL Overview]($docs/learning/backend/ExecutingECSQL)
167
+ * - [Code Examples]($docs/learning/backend/ECSQLCodeExamples)
168
+ *
169
+ * @param ecsql The ECSQL statement to execute
170
+ * @param params The values to bind to the parameters (if the ECSQL has any).
171
+ * See "[iModel.js Types used in ECSQL Parameter Bindings]($docs/learning/ECSQLParameterTypes)" for details.
172
+ * @returns Return row count.
173
+ * @throws [IModelError]($common) If the statement is invalid
174
+ */
175
+ queryRowCount(ecsql: string, params?: QueryBinder): Promise<number>;
176
+ /** Cancel any previous query with same token and run execute the current specified query.
177
+ * The result of the query is async iterator over the rows. The iterator will get next page automatically once rows in current page has been read.
178
+ * [ECSQL row]($docs/learning/ECSQLRowFormat).
179
+ *
180
+ * See also:
181
+ * - [ECSQL Overview]($docs/learning/backend/ExecutingECSQL)
182
+ * - [Code Examples]($docs/learning/backend/ECSQLCodeExamples)
183
+ *
184
+ * @param ecsql The ECSQL statement to execute
185
+ * @param token None empty restart token. The previous query with same token would be cancelled. This would cause
186
+ * exception which user code must handle.
187
+ * @param params The values to bind to the parameters (if the ECSQL has any).
188
+ * @param rowFormat Specify what format the row will be returned. It default to Array format though to make it compilable with previous version use *QueryRowFormat.UseJsPropertyNames*
189
+ * @param options Allow to specify certain flags which control how query is executed.
190
+ * @returns Returns the query result as an *AsyncIterableIterator<any>* which lazy load result as needed. The row format is determined by *rowFormat* parameter.
191
+ * See [ECSQL row format]($docs/learning/ECSQLRowFormat) for details about the format of the returned rows.
192
+ * @throws [IModelError]($common) If there was any error while submitting, preparing or stepping into query
193
+ */
194
+ restartQuery(token: string, ecsql: string, params?: QueryBinder, rowFormat?: QueryRowFormat, options?: QueryOptions): AsyncIterableIterator<any>;
195
+ }
196
+ //# sourceMappingURL=ECDb.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ECDb.d.ts","sourceRoot":"","sources":["../../src/ECDb.ts"],"names":[],"mappings":"AAIA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AE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;IAOhF;;;;;;;;;;;;;;;;;OAiBG;IACY,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,EAAE,SAAS,iBAAiC,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,qBAAqB,CAAC,GAAG,CAAC;CAKhL"}
@@ -0,0 +1,354 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ECDb = exports.ECDbOpenMode = void 0;
4
+ /** @packageDocumentation
5
+ * @module ECDb
6
+ */
7
+ const core_bentley_1 = require("@itwin/core-bentley");
8
+ const core_common_1 = require("@itwin/core-common");
9
+ const BackendLoggerCategory_1 = require("./BackendLoggerCategory");
10
+ const ConcurrentQuery_1 = require("./ConcurrentQuery");
11
+ const ECSqlStatement_1 = require("./ECSqlStatement");
12
+ const IModelHost_1 = require("./IModelHost");
13
+ const SqliteStatement_1 = require("./SqliteStatement");
14
+ const loggerCategory = BackendLoggerCategory_1.BackendLoggerCategory.ECDb;
15
+ /** Modes for how to open [ECDb]($backend) files.
16
+ * @public
17
+ */
18
+ var ECDbOpenMode;
19
+ (function (ECDbOpenMode) {
20
+ ECDbOpenMode[ECDbOpenMode["Readonly"] = 0] = "Readonly";
21
+ ECDbOpenMode[ECDbOpenMode["ReadWrite"] = 1] = "ReadWrite";
22
+ /** Opens the file read-write and upgrades the file if necessary to the latest file format version. */
23
+ ECDbOpenMode[ECDbOpenMode["FileUpgrade"] = 2] = "FileUpgrade";
24
+ })(ECDbOpenMode = exports.ECDbOpenMode || (exports.ECDbOpenMode = {}));
25
+ /** An ECDb file
26
+ * @public
27
+ */
28
+ class ECDb {
29
+ constructor() {
30
+ this._concurrentQueryInitialized = false;
31
+ this._statementCache = new SqliteStatement_1.StatementCache();
32
+ this._sqliteStatementCache = new SqliteStatement_1.StatementCache();
33
+ this._concurrentQueryStats = { resetTimerHandle: null, logTimerHandle: null, lastActivityTime: Date.now(), dispose: () => { } };
34
+ this._nativeDb = new IModelHost_1.IModelHost.platform.ECDb();
35
+ }
36
+ /** only for tests
37
+ * @internal
38
+ */
39
+ resetSqliteCache(size) {
40
+ this._sqliteStatementCache.clear();
41
+ this._sqliteStatementCache = new SqliteStatement_1.StatementCache(size);
42
+ }
43
+ /** Call this function when finished with this ECDb object. This releases the native resources held by the
44
+ * ECDb object.
45
+ */
46
+ dispose() {
47
+ if (!this._nativeDb)
48
+ return;
49
+ this.closeDb();
50
+ this._nativeDb.dispose();
51
+ this._nativeDb = undefined;
52
+ }
53
+ /** Create an ECDb
54
+ * @param pathName The path to the ECDb file to create.
55
+ * @throws [IModelError]($common) if the operation failed.
56
+ */
57
+ createDb(pathName) {
58
+ const status = this.nativeDb.createDb(pathName);
59
+ if (status !== core_bentley_1.DbResult.BE_SQLITE_OK)
60
+ throw new core_common_1.IModelError(status, "Failed to created ECDb");
61
+ }
62
+ /** Open the ECDb.
63
+ * @param pathName The path to the ECDb file to open
64
+ * @param openMode Open mode
65
+ * @throws [IModelError]($common) if the operation failed.
66
+ */
67
+ openDb(pathName, openMode = ECDbOpenMode.Readonly) {
68
+ const nativeOpenMode = openMode === ECDbOpenMode.Readonly ? core_bentley_1.OpenMode.Readonly : core_bentley_1.OpenMode.ReadWrite;
69
+ const tryUpgrade = openMode === ECDbOpenMode.FileUpgrade;
70
+ const status = this.nativeDb.openDb(pathName, nativeOpenMode, tryUpgrade);
71
+ if (status !== core_bentley_1.DbResult.BE_SQLITE_OK)
72
+ throw new core_common_1.IModelError(status, "Failed to open ECDb");
73
+ }
74
+ /** Returns true if the ECDb is open */
75
+ get isOpen() { return this.nativeDb.isOpen(); }
76
+ /** Close the Db after saving any uncommitted changes.
77
+ * @throws [IModelError]($common) if the database is not open.
78
+ */
79
+ closeDb() {
80
+ this._statementCache.clear();
81
+ this._sqliteStatementCache.clear();
82
+ this.nativeDb.closeDb();
83
+ this._concurrentQueryStats.dispose();
84
+ }
85
+ /** @internal use to test statement caching */
86
+ clearStatementCache() {
87
+ this._statementCache.clear();
88
+ }
89
+ /** @internal use to test statement caching */
90
+ getCachedStatementCount() {
91
+ return this._statementCache.size;
92
+ }
93
+ /** Commit the outermost transaction, writing changes to the file. Then, restart the transaction.
94
+ * @param changesetName The name of the operation that generated these changes.
95
+ * @throws [IModelError]($common) if the database is not open or if the operation failed.
96
+ */
97
+ saveChanges(changesetName) {
98
+ const status = this.nativeDb.saveChanges(changesetName);
99
+ if (status !== core_bentley_1.DbResult.BE_SQLITE_OK)
100
+ throw new core_common_1.IModelError(status, "Failed to save changes");
101
+ }
102
+ /** Abandon (cancel) the outermost transaction, discarding all changes since last save. Then, restart the transaction.
103
+ * @throws [IModelError]($common) if the database is not open or if the operation failed.
104
+ */
105
+ abandonChanges() {
106
+ const status = this.nativeDb.abandonChanges();
107
+ if (status !== core_bentley_1.DbResult.BE_SQLITE_OK)
108
+ throw new core_common_1.IModelError(status, "Failed to abandon changes");
109
+ }
110
+ /** Import a schema.
111
+ *
112
+ * If the import was successful, the database is automatically saved to disk.
113
+ * @param pathName Path to ECSchema XML file to import.
114
+ * @throws [IModelError]($common) if the database is not open or if the operation failed.
115
+ */
116
+ importSchema(pathName) {
117
+ const status = this.nativeDb.importSchema(pathName);
118
+ if (status !== core_bentley_1.DbResult.BE_SQLITE_OK) {
119
+ core_bentley_1.Logger.logError(loggerCategory, `Failed to import schema from '${pathName}'.`);
120
+ throw new core_common_1.IModelError(status, `Failed to import schema from '${pathName}'.`);
121
+ }
122
+ }
123
+ /**
124
+ * Use a prepared ECSQL statement, potentially from the statement cache. If the requested statement doesn't exist
125
+ * in the statement cache, a new statement is prepared. After the callback completes, the statement is reset and saved
126
+ * in the statement cache so it can be reused in the future. Use this method for ECSQL statements that will be
127
+ * reused often and are expensive to prepare. The statement cache holds the most recently used statements, discarding
128
+ * the oldest statements as it fills. For statements you don't intend to reuse, instead use [[withStatement]].
129
+ * @param sql The SQLite SQL statement to execute
130
+ * @param callback the callback to invoke on the prepared statement
131
+ * @param logErrors Determines if error will be logged if statement fail to prepare
132
+ * @returns the value returned by `callback`.
133
+ * @see [[withStatement]]
134
+ * @public
135
+ */
136
+ withPreparedStatement(ecsql, callback, logErrors = true) {
137
+ var _a;
138
+ const stmt = (_a = this._statementCache.findAndRemove(ecsql)) !== null && _a !== void 0 ? _a : this.prepareStatement(ecsql, logErrors);
139
+ const release = () => this._statementCache.addOrDispose(stmt);
140
+ try {
141
+ const val = callback(stmt);
142
+ if (val instanceof Promise) {
143
+ val.then(release, release);
144
+ }
145
+ else {
146
+ release();
147
+ }
148
+ return val;
149
+ }
150
+ catch (err) {
151
+ release();
152
+ throw err;
153
+ }
154
+ }
155
+ /**
156
+ * Prepared and execute a callback on an ECSQL statement. After the callback completes the statement is disposed.
157
+ * Use this method for ECSQL statements are either not expected to be reused, or are not expensive to prepare.
158
+ * For statements that will be reused often, instead use [[withPreparedStatement]].
159
+ * @param sql The SQLite SQL statement to execute
160
+ * @param callback the callback to invoke on the prepared statement
161
+ * @param logErrors Determines if error will be logged if statement fail to prepare
162
+ * @returns the value returned by `callback`.
163
+ * @see [[withPreparedStatement]]
164
+ * @public
165
+ */
166
+ withStatement(ecsql, callback, logErrors = true) {
167
+ const stmt = this.prepareStatement(ecsql, logErrors);
168
+ const release = () => stmt.dispose();
169
+ try {
170
+ const val = callback(stmt);
171
+ if (val instanceof Promise) {
172
+ val.then(release, release);
173
+ }
174
+ else {
175
+ release();
176
+ }
177
+ return val;
178
+ }
179
+ catch (err) {
180
+ release();
181
+ throw err;
182
+ }
183
+ }
184
+ /** Prepare an ECSQL statement.
185
+ * @param ecsql The ECSQL statement to prepare
186
+ * @param logErrors Determines if error will be logged if statement fail to prepare
187
+ * @throws [IModelError]($common) if there is a problem preparing the statement.
188
+ */
189
+ prepareStatement(ecsql, logErrors = true) {
190
+ const stmt = new ECSqlStatement_1.ECSqlStatement();
191
+ stmt.prepare(this.nativeDb, ecsql, logErrors);
192
+ return stmt;
193
+ }
194
+ /**
195
+ * Use a prepared SQL statement, potentially from the statement cache. If the requested statement doesn't exist
196
+ * in the statement cache, a new statement is prepared. After the callback completes, the statement is reset and saved
197
+ * in the statement cache so it can be reused in the future. Use this method for SQL statements that will be
198
+ * reused often and are expensive to prepare. The statement cache holds the most recently used statements, discarding
199
+ * the oldest statements as it fills. For statements you don't intend to reuse, instead use [[withSqliteStatement]].
200
+ * @param sql The SQLite SQL statement to execute
201
+ * @param callback the callback to invoke on the prepared statement
202
+ * @param logErrors Determines if error will be logged if statement fail to prepare
203
+ * @returns the value returned by `callback`.
204
+ * @see [[withPreparedStatement]]
205
+ * @public
206
+ */
207
+ withPreparedSqliteStatement(sql, callback, logErrors = true) {
208
+ var _a;
209
+ const stmt = (_a = this._sqliteStatementCache.findAndRemove(sql)) !== null && _a !== void 0 ? _a : this.prepareSqliteStatement(sql, logErrors);
210
+ const release = () => this._sqliteStatementCache.addOrDispose(stmt);
211
+ try {
212
+ const val = callback(stmt);
213
+ if (val instanceof Promise) {
214
+ val.then(release, release);
215
+ }
216
+ else {
217
+ release();
218
+ }
219
+ return val;
220
+ }
221
+ catch (err) {
222
+ release();
223
+ throw err;
224
+ }
225
+ }
226
+ /**
227
+ * Prepared and execute a callback on a SQL statement. After the callback completes the statement is disposed.
228
+ * Use this method for SQL statements are either not expected to be reused, or are not expensive to prepare.
229
+ * For statements that will be reused often, instead use [[withPreparedSqliteStatement]].
230
+ * @param sql The SQLite SQL statement to execute
231
+ * @param callback the callback to invoke on the prepared statement
232
+ * @param logErrors Determines if error will be logged if statement fail to prepare
233
+ * @returns the value returned by `callback`.
234
+ * @public
235
+ */
236
+ withSqliteStatement(sql, callback, logErrors = true) {
237
+ const stmt = this.prepareSqliteStatement(sql, logErrors);
238
+ const release = () => stmt.dispose();
239
+ try {
240
+ const val = callback(stmt);
241
+ if (val instanceof Promise) {
242
+ val.then(release, release);
243
+ }
244
+ else {
245
+ release();
246
+ }
247
+ return val;
248
+ }
249
+ catch (err) {
250
+ release();
251
+ throw err;
252
+ }
253
+ }
254
+ /** Prepare an SQL statement.
255
+ * @param sql The SQLite SQL statement to prepare
256
+ * @param logErrors Determines if error will be logged if statement fail to prepare
257
+ * @throws [IModelError]($common) if there is a problem preparing the statement.
258
+ * @internal
259
+ */
260
+ prepareSqliteStatement(sql, logErrors = true) {
261
+ const stmt = new SqliteStatement_1.SqliteStatement(sql);
262
+ stmt.prepare(this.nativeDb, logErrors);
263
+ return stmt;
264
+ }
265
+ /** @internal */
266
+ get nativeDb() {
267
+ return this._nativeDb;
268
+ }
269
+ /** Allow to execute query and read results along with meta data. The result are streamed.
270
+ * @param params The values to bind to the parameters (if the ECSQL has any).
271
+ * @param config Allow to specify certain flags which control how query is executed.
272
+ * @returns Returns *ECSqlQueryReader* which help iterate over result set and also give access to meta data.
273
+ * @beta
274
+ * */
275
+ createQueryReader(ecsql, params, config) {
276
+ if (!this._nativeDb || !this._nativeDb.isOpen()) {
277
+ throw new core_common_1.IModelError(core_bentley_1.DbResult.BE_SQLITE_ERROR, "db not open");
278
+ }
279
+ const executor = {
280
+ execute: async (request) => {
281
+ return ConcurrentQuery_1.ConcurrentQuery.executeQueryRequest(this._nativeDb, request);
282
+ },
283
+ };
284
+ return new core_common_1.ECSqlReader(executor, ecsql, params, config);
285
+ }
286
+ /** Execute a query and stream its results
287
+ * The result of the query is async iterator over the rows. The iterator will get next page automatically once rows in current page has been read.
288
+ * [ECSQL row]($docs/learning/ECSQLRowFormat).
289
+ *
290
+ * See also:
291
+ * - [ECSQL Overview]($docs/learning/backend/ExecutingECSQL)
292
+ * - [Code Examples]($docs/learning/backend/ECSQLCodeExamples)
293
+ *
294
+ * @param ecsql The ECSQL statement to execute
295
+ * @param params The values to bind to the parameters (if the ECSQL has any).
296
+ * @param rowFormat Specify what format the row will be returned. It default to Array format though to make it compilable with previous version use *QueryRowFormat.UseJsPropertyNames*
297
+ * @param options Allow to specify certain flags which control how query is executed.
298
+ * @returns Returns the query result as an *AsyncIterableIterator<any>* which lazy load result as needed. The row format is determined by *rowFormat* parameter.
299
+ * See [ECSQL row format]($docs/learning/ECSQLRowFormat) for details about the format of the returned rows.
300
+ * @throws [IModelError]($common) If there was any error while submitting, preparing or stepping into query
301
+ */
302
+ async *query(ecsql, params, rowFormat = core_common_1.QueryRowFormat.UseArrayIndexes, options) {
303
+ const builder = new core_common_1.QueryOptionsBuilder(options);
304
+ if (rowFormat === core_common_1.QueryRowFormat.UseJsPropertyNames) {
305
+ builder.setConvertClassIdsToNames(true);
306
+ }
307
+ const reader = this.createQueryReader(ecsql, params, builder.getOptions());
308
+ while (await reader.step())
309
+ yield reader.formatCurrentRow(rowFormat);
310
+ }
311
+ /** Compute number of rows that would be returned by the ECSQL.
312
+ *
313
+ * See also:
314
+ * - [ECSQL Overview]($docs/learning/backend/ExecutingECSQL)
315
+ * - [Code Examples]($docs/learning/backend/ECSQLCodeExamples)
316
+ *
317
+ * @param ecsql The ECSQL statement to execute
318
+ * @param params The values to bind to the parameters (if the ECSQL has any).
319
+ * See "[iModel.js Types used in ECSQL Parameter Bindings]($docs/learning/ECSQLParameterTypes)" for details.
320
+ * @returns Return row count.
321
+ * @throws [IModelError]($common) If the statement is invalid
322
+ */
323
+ async queryRowCount(ecsql, params) {
324
+ for await (const row of this.query(`select count(*) from (${ecsql})`, params)) {
325
+ return row[0];
326
+ }
327
+ throw new core_common_1.IModelError(core_bentley_1.DbResult.BE_SQLITE_ERROR, "Failed to get row count");
328
+ }
329
+ /** Cancel any previous query with same token and run execute the current specified query.
330
+ * The result of the query is async iterator over the rows. The iterator will get next page automatically once rows in current page has been read.
331
+ * [ECSQL row]($docs/learning/ECSQLRowFormat).
332
+ *
333
+ * See also:
334
+ * - [ECSQL Overview]($docs/learning/backend/ExecutingECSQL)
335
+ * - [Code Examples]($docs/learning/backend/ECSQLCodeExamples)
336
+ *
337
+ * @param ecsql The ECSQL statement to execute
338
+ * @param token None empty restart token. The previous query with same token would be cancelled. This would cause
339
+ * exception which user code must handle.
340
+ * @param params The values to bind to the parameters (if the ECSQL has any).
341
+ * @param rowFormat Specify what format the row will be returned. It default to Array format though to make it compilable with previous version use *QueryRowFormat.UseJsPropertyNames*
342
+ * @param options Allow to specify certain flags which control how query is executed.
343
+ * @returns Returns the query result as an *AsyncIterableIterator<any>* which lazy load result as needed. The row format is determined by *rowFormat* parameter.
344
+ * See [ECSQL row format]($docs/learning/ECSQLRowFormat) for details about the format of the returned rows.
345
+ * @throws [IModelError]($common) If there was any error while submitting, preparing or stepping into query
346
+ */
347
+ async *restartQuery(token, ecsql, params, rowFormat = core_common_1.QueryRowFormat.UseArrayIndexes, options) {
348
+ for await (const row of this.query(ecsql, params, rowFormat, new core_common_1.QueryOptionsBuilder(options).setRestartToken(token).getOptions())) {
349
+ yield row;
350
+ }
351
+ }
352
+ }
353
+ exports.ECDb = ECDb;
354
+ //# sourceMappingURL=ECDb.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ECDb.js","sourceRoot":"","sources":["../../src/ECDb.ts"],"names":[],"mappings":";;;AAKA;;GAEG;AACH,sDAA8E;AAC9E,oDAA8I;AAC9I,mEAAgE;AAChE,uDAAoD;AACpD,qDAAkD;AAClD,6CAA0C;AAC1C,uDAAoE;AAEpE,MAAM,cAAc,GAAW,6CAAqB,CAAC,IAAI,CAAC;AAE1D;;GAEG;AACH,IAAY,YAKX;AALD,WAAY,YAAY;IACtB,uDAAQ,CAAA;IACR,yDAAS,CAAA;IACT,sGAAsG;IACtG,6DAAW,CAAA;AACb,CAAC,EALW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAKvB;AAED;;GAEG;AACH,MAAa,IAAI;IAef;QAbQ,gCAA2B,GAAY,KAAK,CAAC;QACpC,oBAAe,GAAG,IAAI,gCAAc,EAAkB,CAAC;QAChE,0BAAqB,GAAG,IAAI,gCAAc,EAAmB,CAAC;QAC9D,0BAAqB,GAAG,EAAE,gBAAgB,EAAG,IAAY,EAAE,cAAc,EAAG,IAAY,EA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------------------------------------------------------------------------------------\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\nimport { IModelJsNative } from \"@bentley/imodeljs-native\";\r\n/** @packageDocumentation\r\n * @module ECDb\r\n */\r\nimport { DbResult, IDisposable, Logger, OpenMode } from \"@itwin/core-bentley\";\r\nimport { DbQueryRequest, ECSqlReader, IModelError, QueryBinder, QueryOptions, QueryOptionsBuilder, QueryRowFormat } from \"@itwin/core-common\";\r\nimport { BackendLoggerCategory } from \"./BackendLoggerCategory\";\r\nimport { ConcurrentQuery } from \"./ConcurrentQuery\";\r\nimport { ECSqlStatement } from \"./ECSqlStatement\";\r\nimport { IModelHost } from \"./IModelHost\";\r\nimport { SqliteStatement, StatementCache } from \"./SqliteStatement\";\r\n\r\nconst loggerCategory: string = BackendLoggerCategory.ECDb;\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 IDisposable {\r\n private _nativeDb?: IModelJsNative.ECDb;\r\n private _concurrentQueryInitialized: boolean = false;\r\n private readonly _statementCache = new StatementCache<ECSqlStatement>();\r\n private _sqliteStatementCache = new StatementCache<SqliteStatement>();\r\n private _concurrentQueryStats = { resetTimerHandle: (null as any), logTimerHandle: (null as any), lastActivityTime: Date.now(), dispose: () => { } };\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 IModelHost.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 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 /** 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._statementCache.clear();\r\n this._sqliteStatementCache.clear();\r\n this.nativeDb.closeDb();\r\n this._concurrentQueryStats.dispose();\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 }\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 */\r\n public withPreparedStatement<T>(ecsql: string, callback: (stmt: ECSqlStatement) => T, logErrors = true): T {\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 */\r\n public withStatement<T>(ecsql: string, callback: (stmt: ECSqlStatement) => T, logErrors = true): T {\r\n const stmt = this.prepareStatement(ecsql, logErrors);\r\n const release = () => stmt.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 */\r\n public prepareStatement(ecsql: string, logErrors = true): ECSqlStatement {\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.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 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 * @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 *ECSqlQueryReader* which help iterate over result set and also give access to meta data.\r\n * @beta\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, \"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 /** Execute a query and stream its results\r\n * The result of the query is async iterator over the rows. The iterator will get next page automatically once rows in current page has been read.\r\n * [ECSQL row]($docs/learning/ECSQLRowFormat).\r\n *\r\n * See also:\r\n * - [ECSQL Overview]($docs/learning/backend/ExecutingECSQL)\r\n * - [Code Examples]($docs/learning/backend/ECSQLCodeExamples)\r\n *\r\n * @param ecsql The ECSQL statement to execute\r\n * @param params The values to bind to the parameters (if the ECSQL has any).\r\n * @param rowFormat Specify what format the row will be returned. It default to Array format though to make it compilable with previous version use *QueryRowFormat.UseJsPropertyNames*\r\n * @param options Allow to specify certain flags which control how query is executed.\r\n * @returns Returns the query result as an *AsyncIterableIterator<any>* which lazy load result as needed. The row format is determined by *rowFormat* parameter.\r\n * See [ECSQL row format]($docs/learning/ECSQLRowFormat) for details about the format of the returned rows.\r\n * @throws [IModelError]($common) If there was any error while submitting, preparing or stepping into query\r\n */\r\n public async * query(ecsql: string, params?: QueryBinder, rowFormat = QueryRowFormat.UseArrayIndexes, options?: QueryOptions): AsyncIterableIterator<any> {\r\n const builder = new QueryOptionsBuilder(options);\r\n if (rowFormat === QueryRowFormat.UseJsPropertyNames) {\r\n builder.setConvertClassIdsToNames(true);\r\n }\r\n const reader = this.createQueryReader(ecsql, params, builder.getOptions());\r\n while (await reader.step())\r\n yield reader.formatCurrentRow(rowFormat);\r\n }\r\n /** Compute number of rows that would be returned by the ECSQL.\r\n *\r\n * See also:\r\n * - [ECSQL Overview]($docs/learning/backend/ExecutingECSQL)\r\n * - [Code Examples]($docs/learning/backend/ECSQLCodeExamples)\r\n *\r\n * @param ecsql The ECSQL statement to execute\r\n * @param params The values to bind to the parameters (if the ECSQL has any).\r\n * See \"[iModel.js Types used in ECSQL Parameter Bindings]($docs/learning/ECSQLParameterTypes)\" for details.\r\n * @returns Return row count.\r\n * @throws [IModelError]($common) If the statement is invalid\r\n */\r\n public async queryRowCount(ecsql: string, params?: QueryBinder): Promise<number> {\r\n for await (const row of this.query(`select count(*) from (${ecsql})`, params)) {\r\n return row[0] as number;\r\n }\r\n throw new IModelError(DbResult.BE_SQLITE_ERROR, \"Failed to get row count\");\r\n }\r\n\r\n /** Cancel any previous query with same token and run execute the current specified query.\r\n * The result of the query is async iterator over the rows. The iterator will get next page automatically once rows in current page has been read.\r\n * [ECSQL row]($docs/learning/ECSQLRowFormat).\r\n *\r\n * See also:\r\n * - [ECSQL Overview]($docs/learning/backend/ExecutingECSQL)\r\n * - [Code Examples]($docs/learning/backend/ECSQLCodeExamples)\r\n *\r\n * @param ecsql The ECSQL statement to execute\r\n * @param token None empty restart token. The previous query with same token would be cancelled. This would cause\r\n * exception which user code must handle.\r\n * @param params The values to bind to the parameters (if the ECSQL has any).\r\n * @param rowFormat Specify what format the row will be returned. It default to Array format though to make it compilable with previous version use *QueryRowFormat.UseJsPropertyNames*\r\n * @param options Allow to specify certain flags which control how query is executed.\r\n * @returns Returns the query result as an *AsyncIterableIterator<any>* which lazy load result as needed. The row format is determined by *rowFormat* parameter.\r\n * See [ECSQL row format]($docs/learning/ECSQLRowFormat) for details about the format of the returned rows.\r\n * @throws [IModelError]($common) If there was any error while submitting, preparing or stepping into query\r\n */\r\n public async * restartQuery(token: string, ecsql: string, params?: QueryBinder, rowFormat = QueryRowFormat.UseArrayIndexes, options?: QueryOptions): AsyncIterableIterator<any> {\r\n for await (const row of this.query(ecsql, params, rowFormat, new QueryOptionsBuilder(options).setRestartToken(token).getOptions())) {\r\n yield row;\r\n }\r\n }\r\n}\r\n"]}
@@ -0,0 +1,18 @@
1
+ /** @packageDocumentation
2
+ * @module Schema
3
+ */
4
+ import { IModelJsNative } from "@bentley/imodeljs-native";
5
+ /** @internal */
6
+ export declare type SchemaKey = IModelJsNative.ECSchemaXmlContext.SchemaKey;
7
+ /** @internal */
8
+ export declare type SchemaMatchType = IModelJsNative.ECSchemaXmlContext.SchemaMatchType;
9
+ /** @internal */
10
+ export declare class ECSchemaXmlContext {
11
+ private _nativeContext;
12
+ constructor();
13
+ addSchemaPath(searchPath: string): void;
14
+ setSchemaLocater(locater: IModelJsNative.ECSchemaXmlContext.SchemaLocaterCallback): void;
15
+ setFirstSchemaLocater(locater: IModelJsNative.ECSchemaXmlContext.SchemaLocaterCallback): void;
16
+ readSchemaFromXmlFile(filePath: string): any;
17
+ }
18
+ //# sourceMappingURL=ECSchemaXmlContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ECSchemaXmlContext.d.ts","sourceRoot":"","sources":["../../src/ECSchemaXmlContext.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAG1D,gBAAgB;AAChB,oBAAY,SAAS,GAAG,cAAc,CAAC,kBAAkB,CAAC,SAAS,CAAC;AAEpE,gBAAgB;AAChB,oBAAY,eAAe,GAAG,cAAc,CAAC,kBAAkB,CAAC,eAAe,CAAC;AAEhF,gBAAgB;AAChB,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,cAAc,CAAgD;;IAM/D,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAIvC,gBAAgB,CAAC,OAAO,EAAE,cAAc,CAAC,kBAAkB,CAAC,qBAAqB,GAAG,IAAI;IAIxF,qBAAqB,CAAC,OAAO,EAAE,cAAc,CAAC,kBAAkB,CAAC,qBAAqB,GAAG,IAAI;IAI7F,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG;CAQpD"}