@itwin/core-backend 3.4.0-dev.8 → 3.5.0-dev.4

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 (261) hide show
  1. package/CHANGELOG.md +41 -1
  2. package/lib/cjs/AliCloudStorageService.d.ts +23 -17
  3. package/lib/cjs/AliCloudStorageService.d.ts.map +1 -1
  4. package/lib/cjs/AliCloudStorageService.js +71 -68
  5. package/lib/cjs/AliCloudStorageService.js.map +1 -1
  6. package/lib/cjs/BackendHubAccess.d.ts +224 -224
  7. package/lib/cjs/BackendHubAccess.d.ts.map +1 -1
  8. package/lib/cjs/BackendHubAccess.js +41 -41
  9. package/lib/cjs/BackendHubAccess.js.map +1 -1
  10. package/lib/cjs/BackendLoggerCategory.d.ts +91 -87
  11. package/lib/cjs/BackendLoggerCategory.d.ts.map +1 -1
  12. package/lib/cjs/BackendLoggerCategory.js +99 -95
  13. package/lib/cjs/BackendLoggerCategory.js.map +1 -1
  14. package/lib/cjs/BisCoreSchema.d.ts +21 -21
  15. package/lib/cjs/BisCoreSchema.js +60 -60
  16. package/lib/cjs/BisCoreSchema.js.map +1 -1
  17. package/lib/cjs/BriefcaseManager.d.ts +165 -165
  18. package/lib/cjs/BriefcaseManager.js +405 -405
  19. package/lib/cjs/BriefcaseManager.js.map +1 -1
  20. package/lib/cjs/Category.d.ts +153 -153
  21. package/lib/cjs/Category.js +243 -243
  22. package/lib/cjs/Category.js.map +1 -1
  23. package/lib/cjs/ChangeSummaryManager.d.ts +187 -187
  24. package/lib/cjs/ChangeSummaryManager.js +445 -445
  25. package/lib/cjs/ChangeSummaryManager.js.map +1 -1
  26. package/lib/cjs/ChangedElementsDb.d.ts +99 -98
  27. package/lib/cjs/ChangedElementsDb.d.ts.map +1 -1
  28. package/lib/cjs/ChangedElementsDb.js +165 -165
  29. package/lib/cjs/ChangedElementsDb.js.map +1 -1
  30. package/lib/cjs/ChangedElementsManager.d.ts +39 -39
  31. package/lib/cjs/ChangedElementsManager.js +88 -88
  32. package/lib/cjs/ChangedElementsManager.js.map +1 -1
  33. package/lib/cjs/CheckpointManager.d.ts +120 -122
  34. package/lib/cjs/CheckpointManager.d.ts.map +1 -1
  35. package/lib/cjs/CheckpointManager.js +343 -354
  36. package/lib/cjs/CheckpointManager.js.map +1 -1
  37. package/lib/cjs/ClassRegistry.d.ts +71 -71
  38. package/lib/cjs/ClassRegistry.d.ts.map +1 -1
  39. package/lib/cjs/ClassRegistry.js +215 -213
  40. package/lib/cjs/ClassRegistry.js.map +1 -1
  41. package/lib/cjs/CloudSqlite.d.ts +350 -0
  42. package/lib/cjs/CloudSqlite.d.ts.map +1 -0
  43. package/lib/cjs/CloudSqlite.js +152 -0
  44. package/lib/cjs/CloudSqlite.js.map +1 -0
  45. package/lib/cjs/CloudStorageBackend.d.ts +58 -46
  46. package/lib/cjs/CloudStorageBackend.d.ts.map +1 -1
  47. package/lib/cjs/CloudStorageBackend.js +173 -164
  48. package/lib/cjs/CloudStorageBackend.js.map +1 -1
  49. package/lib/cjs/CodeService.d.ts +397 -0
  50. package/lib/cjs/CodeService.d.ts.map +1 -0
  51. package/lib/cjs/CodeService.js +64 -0
  52. package/lib/cjs/CodeService.js.map +1 -0
  53. package/lib/cjs/CodeSpecs.d.ts +50 -50
  54. package/lib/cjs/CodeSpecs.js +112 -112
  55. package/lib/cjs/CodeSpecs.js.map +1 -1
  56. package/lib/cjs/ConcurrentQuery.d.ts +11 -11
  57. package/lib/cjs/ConcurrentQuery.js +30 -30
  58. package/lib/cjs/ConcurrentQuery.js.map +1 -1
  59. package/lib/cjs/CustomViewState3dCreator.d.ts +32 -32
  60. package/lib/cjs/CustomViewState3dCreator.d.ts.map +1 -1
  61. package/lib/cjs/CustomViewState3dCreator.js +113 -98
  62. package/lib/cjs/CustomViewState3dCreator.js.map +1 -1
  63. package/lib/cjs/DevTools.d.ts +71 -71
  64. package/lib/cjs/DevTools.d.ts.map +1 -1
  65. package/lib/cjs/DevTools.js +154 -154
  66. package/lib/cjs/DevTools.js.map +1 -1
  67. package/lib/cjs/DisplayStyle.d.ts +106 -106
  68. package/lib/cjs/DisplayStyle.js +256 -256
  69. package/lib/cjs/DisplayStyle.js.map +1 -1
  70. package/lib/cjs/ECDb.d.ts +191 -191
  71. package/lib/cjs/ECDb.js +350 -350
  72. package/lib/cjs/ECDb.js.map +1 -1
  73. package/lib/cjs/ECSchemaXmlContext.d.ts +18 -18
  74. package/lib/cjs/ECSchemaXmlContext.js +41 -41
  75. package/lib/cjs/ECSchemaXmlContext.js.map +1 -1
  76. package/lib/cjs/ECSqlStatement.d.ts +466 -466
  77. package/lib/cjs/ECSqlStatement.js +791 -791
  78. package/lib/cjs/ECSqlStatement.js.map +1 -1
  79. package/lib/cjs/Element.d.ts +1109 -1109
  80. package/lib/cjs/Element.d.ts.map +1 -1
  81. package/lib/cjs/Element.js +1420 -1417
  82. package/lib/cjs/Element.js.map +1 -1
  83. package/lib/cjs/ElementAspect.d.ts +156 -156
  84. package/lib/cjs/ElementAspect.js +178 -178
  85. package/lib/cjs/ElementAspect.js.map +1 -1
  86. package/lib/cjs/ElementGraphics.d.ts +9 -9
  87. package/lib/cjs/ElementGraphics.js +41 -41
  88. package/lib/cjs/ElementGraphics.js.map +1 -1
  89. package/lib/cjs/ElementTreeWalker.d.ts +162 -162
  90. package/lib/cjs/ElementTreeWalker.d.ts.map +1 -1
  91. package/lib/cjs/ElementTreeWalker.js +409 -409
  92. package/lib/cjs/ElementTreeWalker.js.map +1 -1
  93. package/lib/cjs/Entity.d.ts +76 -76
  94. package/lib/cjs/Entity.js +82 -82
  95. package/lib/cjs/Entity.js.map +1 -1
  96. package/lib/cjs/ExportGraphics.d.ts +317 -317
  97. package/lib/cjs/ExportGraphics.d.ts.map +1 -1
  98. package/lib/cjs/ExportGraphics.js +208 -208
  99. package/lib/cjs/ExportGraphics.js.map +1 -1
  100. package/lib/cjs/ExternalSource.d.ts +94 -94
  101. package/lib/cjs/ExternalSource.d.ts.map +1 -1
  102. package/lib/cjs/ExternalSource.js +125 -125
  103. package/lib/cjs/ExternalSource.js.map +1 -1
  104. package/lib/cjs/GeoCoordConfig.d.ts +19 -13
  105. package/lib/cjs/GeoCoordConfig.d.ts.map +1 -1
  106. package/lib/cjs/GeoCoordConfig.js +82 -73
  107. package/lib/cjs/GeoCoordConfig.js.map +1 -1
  108. package/lib/cjs/GeometrySummary.d.ts +4 -4
  109. package/lib/cjs/GeometrySummary.js +380 -380
  110. package/lib/cjs/GeometrySummary.js.map +1 -1
  111. package/lib/cjs/HubMock.d.ts +93 -93
  112. package/lib/cjs/HubMock.d.ts.map +1 -1
  113. package/lib/cjs/HubMock.js +190 -190
  114. package/lib/cjs/HubMock.js.map +1 -1
  115. package/lib/cjs/IModelCloneContext.d.ts +85 -85
  116. package/lib/cjs/IModelCloneContext.js +150 -150
  117. package/lib/cjs/IModelCloneContext.js.map +1 -1
  118. package/lib/cjs/IModelDb.d.ts +1164 -1151
  119. package/lib/cjs/IModelDb.d.ts.map +1 -1
  120. package/lib/cjs/IModelDb.js +2324 -2286
  121. package/lib/cjs/IModelDb.js.map +1 -1
  122. package/lib/cjs/IModelHost.d.ts +361 -347
  123. package/lib/cjs/IModelHost.d.ts.map +1 -1
  124. package/lib/cjs/IModelHost.js +489 -455
  125. package/lib/cjs/IModelHost.js.map +1 -1
  126. package/lib/cjs/IModelJsFs.d.ts +62 -62
  127. package/lib/cjs/IModelJsFs.d.ts.map +1 -1
  128. package/lib/cjs/IModelJsFs.js +140 -140
  129. package/lib/cjs/IModelJsFs.js.map +1 -1
  130. package/lib/cjs/IpcHost.d.ts +98 -98
  131. package/lib/cjs/IpcHost.js +234 -234
  132. package/lib/cjs/IpcHost.js.map +1 -1
  133. package/lib/cjs/LineStyle.d.ts +311 -311
  134. package/lib/cjs/LineStyle.js +295 -295
  135. package/lib/cjs/LineStyle.js.map +1 -1
  136. package/lib/cjs/LocalHub.d.ts +162 -162
  137. package/lib/cjs/LocalHub.js +587 -587
  138. package/lib/cjs/LocalHub.js.map +1 -1
  139. package/lib/cjs/LocalhostIpcHost.d.ts +20 -20
  140. package/lib/cjs/LocalhostIpcHost.js +81 -81
  141. package/lib/cjs/LocalhostIpcHost.js.map +1 -1
  142. package/lib/cjs/Material.d.ts +103 -101
  143. package/lib/cjs/Material.d.ts.map +1 -1
  144. package/lib/cjs/Material.js +147 -145
  145. package/lib/cjs/Material.js.map +1 -1
  146. package/lib/cjs/Model.d.ts +386 -386
  147. package/lib/cjs/Model.d.ts.map +1 -1
  148. package/lib/cjs/Model.js +471 -468
  149. package/lib/cjs/Model.js.map +1 -1
  150. package/lib/cjs/NativeAppStorage.d.ts +51 -51
  151. package/lib/cjs/NativeAppStorage.js +202 -202
  152. package/lib/cjs/NativeAppStorage.js.map +1 -1
  153. package/lib/cjs/NativeHost.d.ts +52 -52
  154. package/lib/cjs/NativeHost.js +168 -168
  155. package/lib/cjs/NativeHost.js.map +1 -1
  156. package/lib/cjs/NavigationRelationship.d.ts +156 -156
  157. package/lib/cjs/NavigationRelationship.js +225 -225
  158. package/lib/cjs/NavigationRelationship.js.map +1 -1
  159. package/lib/cjs/PromiseMemoizer.d.ts +51 -51
  160. package/lib/cjs/PromiseMemoizer.d.ts.map +1 -1
  161. package/lib/cjs/PromiseMemoizer.js +101 -95
  162. package/lib/cjs/PromiseMemoizer.js.map +1 -1
  163. package/lib/cjs/PropertyStore.d.ts +133 -0
  164. package/lib/cjs/PropertyStore.d.ts.map +1 -0
  165. package/lib/cjs/PropertyStore.js +12 -0
  166. package/lib/cjs/PropertyStore.js.map +1 -0
  167. package/lib/cjs/Relationship.d.ts +400 -400
  168. package/lib/cjs/Relationship.js +465 -465
  169. package/lib/cjs/Relationship.js.map +1 -1
  170. package/lib/cjs/RpcBackend.d.ts +28 -28
  171. package/lib/cjs/RpcBackend.js +126 -126
  172. package/lib/cjs/RpcBackend.js.map +1 -1
  173. package/lib/cjs/SQLiteDb.d.ts +219 -173
  174. package/lib/cjs/SQLiteDb.d.ts.map +1 -1
  175. package/lib/cjs/SQLiteDb.js +214 -211
  176. package/lib/cjs/SQLiteDb.js.map +1 -1
  177. package/lib/cjs/Schema.d.ts +55 -55
  178. package/lib/cjs/Schema.js +83 -83
  179. package/lib/cjs/Schema.js.map +1 -1
  180. package/lib/cjs/ServerBasedLocks.d.ts +57 -57
  181. package/lib/cjs/ServerBasedLocks.js +168 -168
  182. package/lib/cjs/ServerBasedLocks.js.map +1 -1
  183. package/lib/cjs/SqliteStatement.d.ts +283 -271
  184. package/lib/cjs/SqliteStatement.d.ts.map +1 -1
  185. package/lib/cjs/SqliteStatement.js +448 -426
  186. package/lib/cjs/SqliteStatement.js.map +1 -1
  187. package/lib/cjs/Texture.d.ts +58 -58
  188. package/lib/cjs/Texture.js +82 -82
  189. package/lib/cjs/Texture.js.map +1 -1
  190. package/lib/cjs/TileStorage.d.ts +19 -0
  191. package/lib/cjs/TileStorage.d.ts.map +1 -0
  192. package/lib/cjs/TileStorage.js +91 -0
  193. package/lib/cjs/TileStorage.js.map +1 -0
  194. package/lib/cjs/TxnManager.d.ts +202 -202
  195. package/lib/cjs/TxnManager.d.ts.map +1 -1
  196. package/lib/cjs/TxnManager.js +356 -353
  197. package/lib/cjs/TxnManager.js.map +1 -1
  198. package/lib/cjs/ViewDefinition.d.ts +435 -435
  199. package/lib/cjs/ViewDefinition.d.ts.map +1 -1
  200. package/lib/cjs/ViewDefinition.js +635 -629
  201. package/lib/cjs/ViewDefinition.js.map +1 -1
  202. package/lib/cjs/ViewStateHydrator.d.ts +13 -13
  203. package/lib/cjs/ViewStateHydrator.js +103 -103
  204. package/lib/cjs/ViewStateHydrator.js.map +1 -1
  205. package/lib/cjs/assets/IModelChange.02.00.00.ecschema.xml +90 -90
  206. package/lib/cjs/assets/Settings/Schemas/Cloud.Schema.json +67 -67
  207. package/lib/cjs/assets/Settings/Schemas/Gcs.schema.json +31 -21
  208. package/lib/cjs/assets/Settings/Schemas/Workspace.Schema.json +52 -52
  209. package/lib/cjs/assets/Settings/backend.setting.json5 +138 -138
  210. package/lib/cjs/core-backend.d.ts +182 -175
  211. package/lib/cjs/core-backend.d.ts.map +1 -1
  212. package/lib/cjs/core-backend.js +202 -195
  213. package/lib/cjs/core-backend.js.map +1 -1
  214. package/lib/cjs/domains/FunctionalElements.d.ts +101 -101
  215. package/lib/cjs/domains/FunctionalElements.js +145 -145
  216. package/lib/cjs/domains/FunctionalElements.js.map +1 -1
  217. package/lib/cjs/domains/FunctionalSchema.d.ts +13 -13
  218. package/lib/cjs/domains/FunctionalSchema.js +40 -40
  219. package/lib/cjs/domains/FunctionalSchema.js.map +1 -1
  220. package/lib/cjs/domains/GenericElements.d.ts +177 -177
  221. package/lib/cjs/domains/GenericElements.js +263 -263
  222. package/lib/cjs/domains/GenericElements.js.map +1 -1
  223. package/lib/cjs/domains/GenericSchema.d.ts +10 -10
  224. package/lib/cjs/domains/GenericSchema.js +28 -28
  225. package/lib/cjs/domains/GenericSchema.js.map +1 -1
  226. package/lib/cjs/rpc-impl/DevToolsRpcImpl.d.ts +15 -15
  227. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js +32 -32
  228. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js.map +1 -1
  229. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts +45 -45
  230. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +262 -262
  231. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -1
  232. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts +22 -20
  233. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts.map +1 -1
  234. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js +204 -195
  235. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js.map +1 -1
  236. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts +36 -36
  237. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts.map +1 -1
  238. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js +168 -165
  239. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -1
  240. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.d.ts +16 -16
  241. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js +43 -43
  242. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js.map +1 -1
  243. package/lib/cjs/rpc-impl/WipRpcImpl.d.ts +15 -15
  244. package/lib/cjs/rpc-impl/WipRpcImpl.js +37 -37
  245. package/lib/cjs/rpc-impl/WipRpcImpl.js.map +1 -1
  246. package/lib/cjs/workspace/Settings.d.ts +186 -186
  247. package/lib/cjs/workspace/Settings.d.ts.map +1 -1
  248. package/lib/cjs/workspace/Settings.js +155 -152
  249. package/lib/cjs/workspace/Settings.js.map +1 -1
  250. package/lib/cjs/workspace/SettingsSchemas.d.ts +75 -75
  251. package/lib/cjs/workspace/SettingsSchemas.js +191 -191
  252. package/lib/cjs/workspace/SettingsSchemas.js.map +1 -1
  253. package/lib/cjs/workspace/Workspace.d.ts +414 -401
  254. package/lib/cjs/workspace/Workspace.d.ts.map +1 -1
  255. package/lib/cjs/workspace/Workspace.js +543 -534
  256. package/lib/cjs/workspace/Workspace.js.map +1 -1
  257. package/package.json +19 -20
  258. package/lib/cjs/IModelSchemaLoader.d.ts +0 -26
  259. package/lib/cjs/IModelSchemaLoader.d.ts.map +0 -1
  260. package/lib/cjs/IModelSchemaLoader.js +0 -122
  261. package/lib/cjs/IModelSchemaLoader.js.map +0 -1
@@ -1,212 +1,215 @@
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 SQLiteDb
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.SQLiteDb = void 0;
11
- const imodeljs_native_1 = require("@bentley/imodeljs-native");
12
- const core_bentley_1 = require("@itwin/core-bentley");
13
- const IModelHost_1 = require("./IModelHost");
14
- const SqliteStatement_1 = require("./SqliteStatement");
15
- /* eslint-disable @typescript-eslint/unified-signatures */
16
- /** A SQLiteDb file
17
- * @public
18
- */
19
- class SQLiteDb {
20
- constructor() {
21
- /** @internal */
22
- this.nativeDb = new IModelHost_1.IModelHost.platform.SQLiteDb();
23
- this._sqliteStatementCache = new SqliteStatement_1.StatementCache();
24
- }
25
- /** @internal */
26
- static createCloudContainer(args) {
27
- return new IModelHost_1.IModelHost.platform.CloudContainer(args);
28
- }
29
- /** @internal */
30
- static createCloudCache(args) {
31
- return new IModelHost_1.IModelHost.platform.CloudCache(args);
32
- }
33
- /** @internal */
34
- static startCloudPrefetch(container, dbName, args) {
35
- return new IModelHost_1.IModelHost.platform.CloudPrefetch(container, dbName, args);
36
- }
37
- /** @internal */
38
- static createBlobIO() {
39
- return new IModelHost_1.IModelHost.platform.BlobIO();
40
- }
41
- /** alias for closeDb. */
42
- dispose() {
43
- this.closeDb();
44
- }
45
- /** Create a SQLiteDb
46
- * @param dbName The path to the SQLiteDb file to create.
47
- */
48
- createDb(dbName, container, params) {
49
- this.nativeDb.createDb(dbName, container, params);
50
- }
51
- /** @internal */
52
- openDb(dbName, openMode, container) {
53
- this.nativeDb.openDb(dbName, openMode, container);
54
- }
55
- /** Close SQLiteDb.
56
- * @param saveChanges if true, call `saveChanges` before closing db.
57
- */
58
- closeDb(saveChanges) {
59
- if (saveChanges && this.isOpen)
60
- this.saveChanges();
61
- this._sqliteStatementCache.clear();
62
- this.nativeDb.closeDb();
63
- }
64
- /** Returns true if the SQLiteDb is open */
65
- get isOpen() { return this.nativeDb.isOpen(); }
66
- /**
67
- * 1. open a database
68
- * 2. call a function supplying the open SQliteDb as argument. If it is async, await its return.
69
- * 3. close the database (even if exceptions are thrown)
70
- */
71
- static withOpenDb(args, operation) {
72
- var _a;
73
- const db = new SQLiteDb();
74
- db.openDb(args.dbName, (_a = args.openMode) !== null && _a !== void 0 ? _a : core_bentley_1.OpenMode.Readonly, args.container);
75
- let fromPromise = false;
76
- try {
77
- const result = operation(db);
78
- if (result instanceof Promise) {
79
- fromPromise = true;
80
- const doClose = () => db.closeDb();
81
- result.then(doClose, doClose);
82
- }
83
- return result;
84
- }
85
- finally {
86
- if (!fromPromise)
87
- db.closeDb();
88
- }
89
- }
90
- /**
91
- * 1. acquire the write lock on a CloudContainer
92
- * 2. open a ReadWrite database in the container
93
- * 3. call a function with the opened database as an argument
94
- * 4. close the database
95
- * 5. release the write lock and upload changes.
96
- * @internal
97
- */
98
- static async withLockedContainer(args,
99
- /** an asynchronous operation performed on the database with the write lock held. */
100
- operation) {
101
- const fn = async () => SQLiteDb.withOpenDb({ ...args, openMode: core_bentley_1.OpenMode.ReadWrite }, operation);
102
- await imodeljs_native_1.CloudSqlite.withWriteLock(args.user, args.container, fn, args.busyHandler);
103
- }
104
- /** vacuum this database
105
- * @see https://www.sqlite.org/lang_vacuum.html
106
- */
107
- vacuum(args) {
108
- this.nativeDb.vacuum(args);
109
- }
110
- /** Commit the outermost transaction, writing changes to the file. Then, restart the transaction. */
111
- saveChanges() {
112
- this.nativeDb.saveChanges();
113
- }
114
- /** Abandon (cancel) the outermost transaction, discarding all changes since last save. Then, restart the transaction. */
115
- abandonChanges() {
116
- this.nativeDb.abandonChanges();
117
- }
118
- /**
119
- * Use a prepared SQL statement, potentially from the statement cache. If the requested statement doesn't exist
120
- * in the statement cache, a new statement is prepared. After the callback completes, the statement is reset and saved
121
- * in the statement cache so it can be reused in the future. Use this method for SQL statements that will be
122
- * reused often and are expensive to prepare. The statement cache holds the most recently used statements, discarding
123
- * the oldest statements as it fills. For statements you don't intend to reuse, instead use [[withSqliteStatement]].
124
- * @param sql The SQLite SQL statement to execute
125
- * @param callback the callback to invoke on the prepared statement
126
- * @returns the value returned by `callback`.
127
- */
128
- withPreparedSqliteStatement(sql, callback) {
129
- var _a;
130
- const stmt = (_a = this._sqliteStatementCache.findAndRemove(sql)) !== null && _a !== void 0 ? _a : this.prepareSqliteStatement(sql);
131
- const release = () => this._sqliteStatementCache.addOrDispose(stmt);
132
- try {
133
- const val = callback(stmt);
134
- if (val instanceof Promise) {
135
- val.then(release, release);
136
- }
137
- else {
138
- release();
139
- }
140
- return val;
141
- }
142
- catch (err) {
143
- release();
144
- throw err;
145
- }
146
- }
147
- /**
148
- * Prepared and execute a callback on a SQL statement. After the callback completes the statement is disposed.
149
- * Use this method for SQL statements are either not expected to be reused, or are not expensive to prepare.
150
- * For statements that will be reused often, instead use [[withPreparedSqliteStatement]].
151
- * @param sql The SQLite SQL statement to execute
152
- * @param callback the callback to invoke on the prepared statement
153
- * @returns the value returned by `callback`.
154
- */
155
- withSqliteStatement(sql, callback) {
156
- const stmt = this.prepareSqliteStatement(sql);
157
- const release = () => stmt.dispose();
158
- try {
159
- const val = callback(stmt);
160
- if (val instanceof Promise) {
161
- val.then(release, release);
162
- }
163
- else {
164
- release();
165
- }
166
- return val;
167
- }
168
- catch (err) {
169
- release();
170
- throw err;
171
- }
172
- }
173
- /** Prepare an SQL statement.
174
- * @param sql The SQLite SQL statement to prepare
175
- * @param logErrors Determine if errors are logged or not
176
- * @internal
177
- */
178
- prepareSqliteStatement(sql, logErrors = true) {
179
- const stmt = new SqliteStatement_1.SqliteStatement(sql);
180
- stmt.prepare(this.nativeDb, logErrors);
181
- return stmt;
182
- }
183
- /** execute an SQL statement */
184
- executeSQL(sql) {
185
- const stmt = this.prepareSqliteStatement(sql);
186
- try {
187
- return stmt.step();
188
- }
189
- finally {
190
- stmt.dispose();
191
- }
192
- }
193
- }
194
- exports.SQLiteDb = SQLiteDb;
195
- /** @public */
196
- (function (SQLiteDb) {
197
- /** Default transaction mode for SQLiteDbs.
198
- * @see https://www.sqlite.org/lang_transaction.html
199
- */
200
- let DefaultTxnMode;
201
- (function (DefaultTxnMode) {
202
- /** no default transaction is started. You must use BEGIN/COMMIT or SQLite will use implicit transactions */
203
- DefaultTxnMode[DefaultTxnMode["None"] = 0] = "None";
204
- /** A deferred transaction is started when the file is first opened. This is the default. */
205
- DefaultTxnMode[DefaultTxnMode["Deferred"] = 1] = "Deferred";
206
- /** An immediate transaction is started when the file is first opened. */
207
- DefaultTxnMode[DefaultTxnMode["Immediate"] = 2] = "Immediate";
208
- /** An exclusive transaction is started when the file is first opened. */
209
- DefaultTxnMode[DefaultTxnMode["Exclusive"] = 3] = "Exclusive";
210
- })(DefaultTxnMode = SQLiteDb.DefaultTxnMode || (SQLiteDb.DefaultTxnMode = {}));
211
- })(SQLiteDb = exports.SQLiteDb || (exports.SQLiteDb = {}));
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 SQLiteDb
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.SQLiteDb = void 0;
11
+ const core_bentley_1 = require("@itwin/core-bentley");
12
+ const CloudSqlite_1 = require("./CloudSqlite");
13
+ const IModelHost_1 = require("./IModelHost");
14
+ const SqliteStatement_1 = require("./SqliteStatement");
15
+ // cspell:ignore savepoint
16
+ /* eslint-disable @typescript-eslint/unified-signatures */
17
+ /** A SQLiteDb file
18
+ * @public
19
+ */
20
+ class SQLiteDb {
21
+ constructor() {
22
+ /** @internal */
23
+ this.nativeDb = new IModelHost_1.IModelHost.platform.SQLiteDb();
24
+ this._sqliteStatementCache = new SqliteStatement_1.StatementCache();
25
+ }
26
+ /** @internal */
27
+ static createBlobIO() {
28
+ return new IModelHost_1.IModelHost.platform.BlobIO();
29
+ }
30
+ /** alias for closeDb. */
31
+ dispose() {
32
+ this.closeDb();
33
+ }
34
+ /** @internal */
35
+ createDb(dbName, container, params) {
36
+ this.nativeDb.createDb(dbName, container, params);
37
+ }
38
+ /** @internal */
39
+ openDb(dbName, openMode, container) {
40
+ this.nativeDb.openDb(dbName, openMode, container);
41
+ }
42
+ /** Close SQLiteDb.
43
+ * @param saveChanges if true, call `saveChanges` before closing db. Otherwise unsaved changes are abandoned.
44
+ */
45
+ closeDb(saveChanges) {
46
+ if (saveChanges && this.isOpen)
47
+ this.saveChanges();
48
+ this._sqliteStatementCache.clear();
49
+ this.nativeDb.closeDb();
50
+ }
51
+ /** Returns true if this SQLiteDb is open */
52
+ get isOpen() { return this.nativeDb.isOpen(); }
53
+ /** Returns true if this SQLiteDb is open readonly */
54
+ get isReadonly() { return this.nativeDb.isReadonly(); }
55
+ /**
56
+ * Open a database, perform an operation, then close the database.
57
+ *
58
+ * Details:
59
+ * - if database is open, throw an error
60
+ * - open a database
61
+ * - call a function with the database opened. If it is async, await its return.
62
+ * - if function throws, abandon all changes, close database, and rethrow
63
+ * - save all changes
64
+ * - close the database
65
+ * @return value from operation
66
+ */
67
+ withOpenDb(args, operation) {
68
+ var _a;
69
+ if (this.isOpen)
70
+ throw new Error("database is already open");
71
+ const save = () => this.closeDb(true), abandon = () => this.closeDb(false);
72
+ this.openDb(args.dbName, (_a = args.openMode) !== null && _a !== void 0 ? _a : core_bentley_1.OpenMode.Readonly, args.container);
73
+ try {
74
+ const result = operation();
75
+ result instanceof Promise ? result.then(save, abandon) : save();
76
+ return result;
77
+ }
78
+ catch (e) {
79
+ abandon();
80
+ throw e;
81
+ }
82
+ }
83
+ /**
84
+ * Perform an operation on a database in a CloudContainer with the write lock held.
85
+ *
86
+ * Details:
87
+ * - acquire the write lock on a CloudContainer
88
+ * - call `withOpenDb` with openMode `ReadWrite`
89
+ * - upload changes
90
+ * - release the write lock
91
+ * @param args arguments to lock the container and open the database
92
+ * @param operation an operation performed on the database with the write lock held.
93
+ * @return value from operation
94
+ * @internal
95
+ */
96
+ async withLockedContainer(args, operation) {
97
+ return CloudSqlite_1.CloudSqlite.withWriteLock(args.user, args.container, () => this.withOpenDb({ ...args, openMode: core_bentley_1.OpenMode.ReadWrite }, operation), args.busyHandler);
98
+ }
99
+ /** vacuum this database
100
+ * @see https://www.sqlite.org/lang_vacuum.html
101
+ */
102
+ vacuum(args) {
103
+ this.nativeDb.vacuum(args);
104
+ }
105
+ /** Commit the outermost transaction, writing changes to the file. Then, restart the transaction. */
106
+ saveChanges() {
107
+ this.nativeDb.saveChanges();
108
+ }
109
+ /** Abandon (cancel) the outermost transaction, discarding all changes since last save. Then, restart the transaction. */
110
+ abandonChanges() {
111
+ this.nativeDb.abandonChanges();
112
+ }
113
+ /**
114
+ * Use a prepared SQL statement, potentially from the statement cache. If the requested statement doesn't exist
115
+ * in the statement cache, a new statement is prepared. After the callback completes, the statement is reset and saved
116
+ * in the statement cache so it can be reused in the future. Use this method for SQL statements that will be
117
+ * reused often and are expensive to prepare. The statement cache holds the most recently used statements, discarding
118
+ * the oldest statements as it fills. For statements you don't intend to reuse, instead use [[withSqliteStatement]].
119
+ * @param sql The SQLite SQL statement to execute
120
+ * @param callback the callback to invoke on the prepared statement
121
+ * @returns the value returned by `callback`.
122
+ */
123
+ withPreparedSqliteStatement(sql, callback) {
124
+ var _a;
125
+ const stmt = (_a = this._sqliteStatementCache.findAndRemove(sql)) !== null && _a !== void 0 ? _a : this.prepareSqliteStatement(sql);
126
+ const release = () => this._sqliteStatementCache.addOrDispose(stmt);
127
+ try {
128
+ const val = callback(stmt);
129
+ val instanceof Promise ? val.then(release, release) : release();
130
+ return val;
131
+ }
132
+ catch (err) {
133
+ release();
134
+ throw err;
135
+ }
136
+ }
137
+ /**
138
+ * Prepared and execute a callback on a SQL statement. After the callback completes the statement is disposed.
139
+ * Use this method for SQL statements are either not expected to be reused, or are not expensive to prepare.
140
+ * For statements that will be reused often, instead use [[withPreparedSqliteStatement]].
141
+ * @param sql The SQLite SQL statement to execute
142
+ * @param callback the callback to invoke on the prepared statement
143
+ * @returns the value returned by `callback`.
144
+ */
145
+ withSqliteStatement(sql, callback) {
146
+ const stmt = this.prepareSqliteStatement(sql);
147
+ const release = () => stmt.dispose();
148
+ try {
149
+ const val = callback(stmt);
150
+ val instanceof Promise ? val.then(release, release) : release();
151
+ return val;
152
+ }
153
+ catch (err) {
154
+ release();
155
+ throw err;
156
+ }
157
+ }
158
+ /**
159
+ * Perform an operation on this database within a [savepoint](https://www.sqlite.org/lang_savepoint.html). If the operation completes successfully, the
160
+ * changes remain in the current transaction. If the operation throws an exception, the savepoint is rolled back
161
+ * and all changes to the database from this method are reversed, leaving the transaction exactly as it was before this method.
162
+ */
163
+ withSavePoint(savePointName, operation) {
164
+ if (this.isReadonly)
165
+ throw new Error("database is readonly");
166
+ this.executeSQL(`SAVEPOINT ${savePointName}`);
167
+ try {
168
+ operation();
169
+ this.executeSQL(`RELEASE ${savePointName}`);
170
+ }
171
+ catch (e) {
172
+ this.executeSQL(`ROLLBACK TO ${savePointName}`);
173
+ throw e;
174
+ }
175
+ }
176
+ /** Prepare an SQL statement.
177
+ * @param sql The SQLite SQL statement to prepare
178
+ * @param logErrors Determine if errors are logged or not
179
+ * @internal
180
+ */
181
+ prepareSqliteStatement(sql, logErrors = true) {
182
+ const stmt = new SqliteStatement_1.SqliteStatement(sql);
183
+ stmt.prepare(this.nativeDb, logErrors);
184
+ return stmt;
185
+ }
186
+ /** execute an SQL statement */
187
+ executeSQL(sql) {
188
+ const stmt = this.prepareSqliteStatement(sql);
189
+ try {
190
+ return stmt.step();
191
+ }
192
+ finally {
193
+ stmt.dispose();
194
+ }
195
+ }
196
+ }
197
+ exports.SQLiteDb = SQLiteDb;
198
+ /** @public */
199
+ (function (SQLiteDb) {
200
+ /** Default transaction mode for SQLiteDbs.
201
+ * @see https://www.sqlite.org/lang_transaction.html
202
+ */
203
+ let DefaultTxnMode;
204
+ (function (DefaultTxnMode) {
205
+ /** no default transaction is started. You must use BEGIN/COMMIT or SQLite will use implicit transactions */
206
+ DefaultTxnMode[DefaultTxnMode["None"] = 0] = "None";
207
+ /** A deferred transaction is started when the file is first opened. This is the default. */
208
+ DefaultTxnMode[DefaultTxnMode["Deferred"] = 1] = "Deferred";
209
+ /** An immediate transaction is started when the file is first opened. */
210
+ DefaultTxnMode[DefaultTxnMode["Immediate"] = 2] = "Immediate";
211
+ /** An exclusive transaction is started when the file is first opened. */
212
+ DefaultTxnMode[DefaultTxnMode["Exclusive"] = 3] = "Exclusive";
213
+ })(DefaultTxnMode = SQLiteDb.DefaultTxnMode || (SQLiteDb.DefaultTxnMode = {}));
214
+ })(SQLiteDb = exports.SQLiteDb || (exports.SQLiteDb = {}));
212
215
  //# sourceMappingURL=SQLiteDb.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SQLiteDb.js","sourceRoot":"","sources":["../../src/SQLiteDb.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,8DAAuE;AACvE,sDAAsE;AAEtE,6CAA0C;AAC1C,uDAAoE;AAEpE,0DAA0D;AAE1D;;GAEG;AACH,MAAa,QAAQ;IAArB;QACE,gBAAgB;QACA,aAAQ,GAAG,IAAI,uBAAU,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;QACtD,0BAAqB,GAAG,IAAI,gCAAc,EAAmB,CAAC;IAmNxE,CAAC;IAjNC,gBAAgB;IACT,MAAM,CAAC,oBAAoB,CAAC,IAAsC;QACvE,OAAO,IAAI,uBAAU,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC;IACD,gBAAgB;IACT,MAAM,CAAC,gBAAgB,CAAC,IAA4B;QACzD,OAAO,IAAI,uBAAU,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAClD,CAAC;IACD,gBAAgB;IACT,MAAM,CAAC,kBAAkB,CAAC,SAAkC,EAAE,MAAc,EAAE,IAAgC;QACnH,OAAO,IAAI,uBAAU,CAAC,QAAQ,CAAC,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IACxE,CAAC;IACD,gBAAgB;IACT,MAAM,CAAC,YAAY;QACxB,OAAO,IAAI,uBAAU,CAAC,QAAQ,C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AO,EAAE,CAAC;SAChB;IACH,CAAC;CACF;AAtND,4BAsNC;AAED,cAAc;AACd,WAAiB,QAAQ;IAcvB;;QAEI;IACJ,IAAY,cASX;IATD,WAAY,cAAc;QACxB,4GAA4G;QAC5G,mDAAQ,CAAA;QACR,4FAA4F;QAC5F,2DAAY,CAAA;QACZ,yEAAyE;QACzE,6DAAa,CAAA;QACb,yEAAyE;QACzE,6DAAa,CAAA;IACf,CAAC,EATW,cAAc,GAAd,uBAAc,KAAd,uBAAc,QASzB;AA8BH,CAAC,EAxDgB,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAwDxB","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module SQLiteDb\r\n */\r\n\r\nimport { CloudSqlite, IModelJsNative } from \"@bentley/imodeljs-native\";\r\nimport { DbResult, IDisposable, OpenMode } from \"@itwin/core-bentley\";\r\nimport { LocalFileName } from \"@itwin/core-common\";\r\nimport { IModelHost } from \"./IModelHost\";\r\nimport { SqliteStatement, StatementCache } from \"./SqliteStatement\";\r\n\r\n/* eslint-disable @typescript-eslint/unified-signatures */\r\n\r\n/** A SQLiteDb file\r\n * @public\r\n */\r\nexport class SQLiteDb implements IDisposable {\r\n /** @internal */\r\n public readonly nativeDb = new IModelHost.platform.SQLiteDb();\r\n private _sqliteStatementCache = new StatementCache<SqliteStatement>();\r\n\r\n /** @internal */\r\n public static createCloudContainer(args: CloudSqlite.ContainerAccessProps): SQLiteDb.CloudContainer {\r\n return new IModelHost.platform.CloudContainer(args);\r\n }\r\n /** @internal */\r\n public static createCloudCache(args: CloudSqlite.CacheProps): SQLiteDb.CloudCache {\r\n return new IModelHost.platform.CloudCache(args);\r\n }\r\n /** @internal */\r\n public static startCloudPrefetch(container: SQLiteDb.CloudContainer, dbName: string, args?: CloudSqlite.PrefetchProps): SQLiteDb.CloudPrefetch {\r\n return new IModelHost.platform.CloudPrefetch(container, dbName, args);\r\n }\r\n /** @internal */\r\n public static createBlobIO(): SQLiteDb.BlobIO {\r\n return new IModelHost.platform.BlobIO();\r\n }\r\n\r\n /** alias for closeDb. */\r\n public dispose(): void {\r\n this.closeDb();\r\n }\r\n\r\n /** Create a SQLiteDb\r\n * @param dbName The path to the SQLiteDb file to create.\r\n */\r\n public createDb(dbName: string, container?: SQLiteDb.CloudContainer, params?: SQLiteDb.CreateParams): void {\r\n this.nativeDb.createDb(dbName, container, params);\r\n }\r\n\r\n /** Open a SQLiteDb.\r\n * @param dbName The path to the SQLiteDb file to open\r\n */\r\n public openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams): void;\r\n /**\r\n * @param container optional CloudContainer holding database\r\n * @internal\r\n */\r\n public openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams, container?: SQLiteDb.CloudContainer): void;\r\n\r\n /** @internal */\r\n public openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams, container?: SQLiteDb.CloudContainer): void {\r\n this.nativeDb.openDb(dbName, openMode, container);\r\n }\r\n\r\n /** Close SQLiteDb.\r\n * @param saveChanges if true, call `saveChanges` before closing db.\r\n */\r\n public closeDb(saveChanges?: boolean): void {\r\n if (saveChanges && this.isOpen)\r\n this.saveChanges();\r\n this._sqliteStatementCache.clear();\r\n this.nativeDb.closeDb();\r\n }\r\n\r\n /** Returns true if the SQLiteDb is open */\r\n public get isOpen(): boolean { return this.nativeDb.isOpen(); }\r\n\r\n /**\r\n * 1. open a database\r\n * 2. call a function supplying the open SQliteDb as argument. If it is async, await its return.\r\n * 3. close the database (even if exceptions are thrown)\r\n */\r\n public static withOpenDb<T>(args: {\r\n /** The name of the database to open */\r\n dbName: string;\r\n /** either an object with the open parameters or just OpenMode value. */\r\n openMode?: OpenMode | SQLiteDb.OpenParams;\r\n /** @internal */\r\n container?: SQLiteDb.CloudContainer;\r\n }, operation: (db: SQLiteDb) => T): T {\r\n const db = new SQLiteDb();\r\n db.openDb(args.dbName, args.openMode ?? OpenMode.Readonly, args.container);\r\n let fromPromise = false;\r\n\r\n try {\r\n const result = operation(db);\r\n if (result instanceof Promise) {\r\n fromPromise = true;\r\n const doClose = () => db.closeDb();\r\n result.then(doClose, doClose);\r\n }\r\n return result;\r\n } finally {\r\n if (!fromPromise)\r\n db.closeDb();\r\n }\r\n }\r\n\r\n /**\r\n * 1. acquire the write lock on a CloudContainer\r\n * 2. open a ReadWrite database in the container\r\n * 3. call a function with the opened database as an argument\r\n * 4. close the database\r\n * 5. release the write lock and upload changes.\r\n * @internal\r\n */\r\n public static async withLockedContainer(\r\n args: {\r\n /** the name to be displayed in the event of lock collisions */\r\n user: string;\r\n /** the name of the database within the container */\r\n dbName: string;\r\n /** the CloudContainer on which the operation will be performed */\r\n container: SQLiteDb.CloudContainer;\r\n /** if present, function called when the write lock is currently held by another user. */\r\n busyHandler?: CloudSqlite.WriteLockBusyHandler;\r\n },\r\n /** an asynchronous operation performed on the database with the write lock held. */\r\n operation: (db: SQLiteDb) => Promise<void>) {\r\n const fn = async () => SQLiteDb.withOpenDb({ ...args, openMode: OpenMode.ReadWrite }, operation);\r\n await CloudSqlite.withWriteLock(args.user, args.container, fn, args.busyHandler);\r\n }\r\n\r\n /** vacuum this database\r\n * @see https://www.sqlite.org/lang_vacuum.html\r\n */\r\n public vacuum(args?: {\r\n /** new page size\r\n * @see https://www.sqlite.org/pragma.html#pragma_page_size\r\n */\r\n pageSize?: number;\r\n /** if present, name of new file to vacuum into */\r\n into?: LocalFileName;\r\n }) {\r\n this.nativeDb.vacuum(args);\r\n }\r\n\r\n /** Commit the outermost transaction, writing changes to the file. Then, restart the transaction. */\r\n public saveChanges(): void {\r\n this.nativeDb.saveChanges();\r\n }\r\n\r\n /** Abandon (cancel) the outermost transaction, discarding all changes since last save. Then, restart the transaction. */\r\n public abandonChanges(): void {\r\n this.nativeDb.abandonChanges();\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 * @returns the value returned by `callback`.\r\n */\r\n public withPreparedSqliteStatement<T>(sql: string, callback: (stmt: SqliteStatement) => T): T {\r\n const stmt = this._sqliteStatementCache.findAndRemove(sql) ?? this.prepareSqliteStatement(sql);\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 * @returns the value returned by `callback`.\r\n */\r\n public withSqliteStatement<T>(sql: string, callback: (stmt: SqliteStatement) => T): T {\r\n const stmt = this.prepareSqliteStatement(sql);\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 Determine if errors are logged or not\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 /** execute an SQL statement */\r\n public executeSQL(sql: string): DbResult {\r\n const stmt = this.prepareSqliteStatement(sql);\r\n try {\r\n return stmt.step();\r\n } finally {\r\n stmt.dispose();\r\n }\r\n }\r\n}\r\n\r\n/** @public */\r\nexport namespace SQLiteDb {\r\n /** A CloudSqlite container that may be connected to a CloudCache.\r\n * @internal\r\n */\r\n export type CloudContainer = IModelJsNative.CloudContainer;\r\n /** @internal */\r\n export type CloudCache = IModelJsNative.CloudCache;\r\n /** @internal */\r\n export type CloudPrefetch = IModelJsNative.CloudPrefetch;\r\n /** Incremental IO for blobs\r\n * @internal\r\n */\r\n export type BlobIO = IModelJsNative.BlobIO;\r\n\r\n /** Default transaction mode for SQLiteDbs.\r\n * @see https://www.sqlite.org/lang_transaction.html\r\n */\r\n export enum DefaultTxnMode {\r\n /** no default transaction is started. You must use BEGIN/COMMIT or SQLite will use implicit transactions */\r\n None = 0,\r\n /** A deferred transaction is started when the file is first opened. This is the default. */\r\n Deferred = 1,\r\n /** An immediate transaction is started when the file is first opened. */\r\n Immediate = 2,\r\n /** An exclusive transaction is started when the file is first opened. */\r\n Exclusive = 3\r\n }\r\n\r\n /** parameters common to opening or creating a new SQLiteDb */\r\n export interface OpenOrCreateParams {\r\n /** If true, do not require that the `be_Prop` table exist */\r\n rawSQLite?: boolean;\r\n /** @see immutable option at https://www.sqlite.org/c3ref/open.html */\r\n immutable?: boolean;\r\n /** Do not attempt to verify that the file is a valid sQLite file before opening. */\r\n skipFileCheck?: boolean;\r\n /** the default transaction mode\r\n * @see [[SQLiteDb.DefaultTxnMode]]\r\n */\r\n defaultTxn?: 0 | 1 | 2 | 3;\r\n /** see query parameters from 'URI Filenames' in https://www.sqlite.org/c3ref/open.html */\r\n queryParam?: string;\r\n }\r\n\r\n /** Parameters for opening an existing SQLiteDb */\r\n export interface OpenParams extends OpenOrCreateParams {\r\n /** use OpenMode.ReadWrite to open the file with write access */\r\n openMode: OpenMode;\r\n }\r\n\r\n /** Parameters for creating a new SQLiteDb */\r\n export interface CreateParams extends OpenOrCreateParams {\r\n /** see https://www.sqlite.org/pragma.html#pragma_page_size */\r\n pageSize?: number;\r\n }\r\n\r\n}\r\n"]}
1
+ {"version":3,"file":"SQLiteDb.js","sourceRoot":"","sources":["../../src/SQLiteDb.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,sDAAsE;AAEtE,+CAA4C;AAC5C,6CAA0C;AAC1C,uDAAoE;AAEpE,0BAA0B;AAC1B,0DAA0D;AAE1D;;GAEG;AACH,MAAa,QAAQ;IAArB;QACE,gBAAgB;QACA,aAAQ,GAAG,IAAI,uBAAU,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;QACtD,0BAAqB,GAAG,IAAI,gCAAc,EAAmB,CAAC;IAuMxE,CAAC;IArMC,gBAAgB;IACT,MAAM,CAAC,YAAY;QACxB,OAAO,IAAI,uBAAU,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;IAC1C,CAAC;IAED,yBAAyB;IAClB,OAAO;QACZ,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;IAQD,gBAAgB;IACT,QAAQ,CAAC,MAAc,EAAE,SAAsC,EAAE,MAA8B;QACpG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IACpD,CAAC;IAYD,gBAAgB;IACT,MAAM,CAAC,MAAc,EAAE,QAAwC,EAAE,SAAsC;QAC5G,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;IACpD,CAAC;IAED;;OAEG;IACI,OAAO,CAAC,WAAqB;QAClC,IAAI,WAAW,IAAI,IAAI,CAAC,MAAM;YAC5B,IAAI,CAAC,WAAW,EAAE,CAAC;QACrB,IAAI,CAAC,qBAAqB,CAAC,KAAK,EAAE,CAAC;Q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ASX;IATD,WAAY,cAAc;QACxB,4GAA4G;QAC5G,mDAAQ,CAAA;QACR,4FAA4F;QAC5F,2DAAY,CAAA;QACZ,yEAAyE;QACzE,6DAAa,CAAA;QACb,yEAAyE;QACzE,6DAAa,CAAA;IACf,CAAC,EATW,cAAc,GAAd,uBAAc,KAAd,uBAAc,QASzB;AAgDH,CAAC,EAjHgB,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAiHxB","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module SQLiteDb\n */\n\nimport { IModelJsNative } from \"@bentley/imodeljs-native\";\nimport { DbResult, IDisposable, OpenMode } from \"@itwin/core-bentley\";\nimport { LocalFileName } from \"@itwin/core-common\";\nimport { CloudSqlite } from \"./CloudSqlite\";\nimport { IModelHost } from \"./IModelHost\";\nimport { SqliteStatement, StatementCache } from \"./SqliteStatement\";\n\n// cspell:ignore savepoint\n/* eslint-disable @typescript-eslint/unified-signatures */\n\n/** A SQLiteDb file\n * @public\n */\nexport class SQLiteDb implements IDisposable {\n /** @internal */\n public readonly nativeDb = new IModelHost.platform.SQLiteDb();\n private _sqliteStatementCache = new StatementCache<SqliteStatement>();\n\n /** @internal */\n public static createBlobIO(): SQLiteDb.BlobIO {\n return new IModelHost.platform.BlobIO();\n }\n\n /** alias for closeDb. */\n public dispose(): void {\n this.closeDb();\n }\n\n /** Create a SQLiteDb\n * @param dbName The path to the SQLiteDb file to create.\n */\n public createDb(dbName: string): void;\n /** @beta */\n public createDb(dbName: string, container?: CloudSqlite.CloudContainer, params?: SQLiteDb.CreateParams): void;\n /** @internal */\n public createDb(dbName: string, container?: CloudSqlite.CloudContainer, params?: SQLiteDb.CreateParams): void {\n this.nativeDb.createDb(dbName, container, params);\n }\n\n /** Open a SQLiteDb.\n * @param dbName The path to the SQLiteDb file to open\n */\n public openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams): void;\n /**\n * @param container optional CloudContainer holding database\n * @beta\n */\n public openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams, container?: CloudSqlite.CloudContainer): void;\n\n /** @internal */\n public openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams, container?: CloudSqlite.CloudContainer): void {\n this.nativeDb.openDb(dbName, openMode, container);\n }\n\n /** Close SQLiteDb.\n * @param saveChanges if true, call `saveChanges` before closing db. Otherwise unsaved changes are abandoned.\n */\n public closeDb(saveChanges?: boolean): void {\n if (saveChanges && this.isOpen)\n this.saveChanges();\n this._sqliteStatementCache.clear();\n this.nativeDb.closeDb();\n }\n\n /** Returns true if this SQLiteDb is open */\n public get isOpen(): boolean { return this.nativeDb.isOpen(); }\n\n /** Returns true if this SQLiteDb is open readonly */\n public get isReadonly(): boolean { return this.nativeDb.isReadonly(); }\n\n /**\n * Open a database, perform an operation, then close the database.\n *\n * Details:\n * - if database is open, throw an error\n * - open a database\n * - call a function with the database opened. If it is async, await its return.\n * - if function throws, abandon all changes, close database, and rethrow\n * - save all changes\n * - close the database\n * @return value from operation\n */\n public withOpenDb<T>(args: SQLiteDb.WithOpenDbArgs, operation: () => T): T {\n if (this.isOpen)\n throw new Error(\"database is already open\");\n\n const save = () => this.closeDb(true), abandon = () => this.closeDb(false);\n this.openDb(args.dbName, args.openMode ?? OpenMode.Readonly, args.container);\n try {\n const result = operation();\n result instanceof Promise ? result.then(save, abandon) : save();\n return result;\n } catch (e) {\n abandon();\n throw e;\n }\n }\n\n /**\n * Perform an operation on a database in a CloudContainer with the write lock held.\n *\n * Details:\n * - acquire the write lock on a CloudContainer\n * - call `withOpenDb` with openMode `ReadWrite`\n * - upload changes\n * - release the write lock\n * @param args arguments to lock the container and open the database\n * @param operation an operation performed on the database with the write lock held.\n * @return value from operation\n * @internal\n */\n public async withLockedContainer<T>(args: CloudSqlite.LockAndOpenArgs, operation: () => T) {\n return CloudSqlite.withWriteLock(args.user, args.container, () => this.withOpenDb({ ...args, openMode: OpenMode.ReadWrite }, operation), args.busyHandler);\n }\n\n /** vacuum this database\n * @see https://www.sqlite.org/lang_vacuum.html\n */\n public vacuum(args?: SQLiteDb.VacuumDbArgs) {\n this.nativeDb.vacuum(args);\n }\n\n /** Commit the outermost transaction, writing changes to the file. Then, restart the transaction. */\n public saveChanges(): void {\n this.nativeDb.saveChanges();\n }\n\n /** Abandon (cancel) the outermost transaction, discarding all changes since last save. Then, restart the transaction. */\n public abandonChanges(): void {\n this.nativeDb.abandonChanges();\n }\n\n /**\n * Use a prepared SQL statement, potentially from the statement cache. If the requested statement doesn't exist\n * in the statement cache, a new statement is prepared. After the callback completes, the statement is reset and saved\n * in the statement cache so it can be reused in the future. Use this method for SQL statements that will be\n * reused often and are expensive to prepare. The statement cache holds the most recently used statements, discarding\n * the oldest statements as it fills. For statements you don't intend to reuse, instead use [[withSqliteStatement]].\n * @param sql The SQLite SQL statement to execute\n * @param callback the callback to invoke on the prepared statement\n * @returns the value returned by `callback`.\n */\n public withPreparedSqliteStatement<T>(sql: string, callback: (stmt: SqliteStatement) => T): T {\n const stmt = this._sqliteStatementCache.findAndRemove(sql) ?? this.prepareSqliteStatement(sql);\n const release = () => this._sqliteStatementCache.addOrDispose(stmt);\n try {\n const val = callback(stmt);\n val instanceof Promise ? val.then(release, release) : release();\n return val;\n } catch (err) {\n release();\n throw err;\n }\n }\n\n /**\n * Prepared and execute a callback on a SQL statement. After the callback completes the statement is disposed.\n * Use this method for SQL statements are either not expected to be reused, or are not expensive to prepare.\n * For statements that will be reused often, instead use [[withPreparedSqliteStatement]].\n * @param sql The SQLite SQL statement to execute\n * @param callback the callback to invoke on the prepared statement\n * @returns the value returned by `callback`.\n */\n public withSqliteStatement<T>(sql: string, callback: (stmt: SqliteStatement) => T): T {\n const stmt = this.prepareSqliteStatement(sql);\n const release = () => stmt.dispose();\n try {\n const val = callback(stmt);\n val instanceof Promise ? val.then(release, release) : release();\n return val;\n } catch (err) {\n release();\n throw err;\n }\n }\n\n /**\n * Perform an operation on this database within a [savepoint](https://www.sqlite.org/lang_savepoint.html). If the operation completes successfully, the\n * changes remain in the current transaction. If the operation throws an exception, the savepoint is rolled back\n * and all changes to the database from this method are reversed, leaving the transaction exactly as it was before this method.\n */\n public withSavePoint(savePointName: string, operation: () => void) {\n if (this.isReadonly)\n throw new Error(\"database is readonly\");\n\n this.executeSQL(`SAVEPOINT ${savePointName}`);\n try {\n operation();\n this.executeSQL(`RELEASE ${savePointName}`);\n } catch (e) {\n this.executeSQL(`ROLLBACK TO ${savePointName}`);\n throw e;\n }\n }\n\n /** Prepare an SQL statement.\n * @param sql The SQLite SQL statement to prepare\n * @param logErrors Determine if errors are logged or not\n * @internal\n */\n public prepareSqliteStatement(sql: string, logErrors = true): SqliteStatement {\n const stmt = new SqliteStatement(sql);\n stmt.prepare(this.nativeDb, logErrors);\n return stmt;\n }\n\n /** execute an SQL statement */\n public executeSQL(sql: string): DbResult {\n const stmt = this.prepareSqliteStatement(sql);\n try {\n return stmt.step();\n } finally {\n stmt.dispose();\n }\n }\n}\n\n/** @public */\nexport namespace SQLiteDb {\n /** interface for reading and writing to a blob in a SQLiteDb\n * @internal\n */\n export interface BlobIO {\n /** Close this BlobIO if it is opened.\n * @note this BlobIO *may* be reused after this call by calling `open` again.\n */\n close(): void;\n /** get the total number of bytes in the blob */\n getNumBytes(): number;\n /** @return true if this BlobIO was successfully opened and may be use to read or write the blob */\n isValid(): boolean;\n /** Open this BlobIO against a table/row/column in a Db */\n open(\n /** The database for the blob */\n db: IModelJsNative.AnyDb,\n args: {\n /** the name of the table for the blob*/\n tableName: string;\n /** the name of the column for the blob */\n columnName: string;\n /** The rowId of the blob */\n row: number;\n /** If true, open this BlobIO for write access */\n writeable?: boolean;\n }): void;\n /** Read from a blob\n * @returns the contents of the requested byte range\n */\n read(args: {\n /** The number of bytes to read */\n numBytes: number;\n /** starting offset within the blob to read */\n offset: number;\n /** If present and of sufficient size, use this ArrayBuffer for the value. */\n blob?: ArrayBuffer;\n }): Uint8Array;\n /** Reposition this BlobIO to a new rowId\n * @note this BlobIO must be valid when this methods is called.\n */\n changeRow(row: number): void;\n /** Write to a blob */\n write(args: {\n /** The number of bytes to write */\n numBytes: number;\n /** starting offset within the blob to write */\n offset: number;\n /** the value to write */\n blob: ArrayBuffer;\n }): void;\n }\n\n /** Default transaction mode for SQLiteDbs.\n * @see https://www.sqlite.org/lang_transaction.html\n */\n export enum DefaultTxnMode {\n /** no default transaction is started. You must use BEGIN/COMMIT or SQLite will use implicit transactions */\n None = 0,\n /** A deferred transaction is started when the file is first opened. This is the default. */\n Deferred = 1,\n /** An immediate transaction is started when the file is first opened. */\n Immediate = 2,\n /** An exclusive transaction is started when the file is first opened. */\n Exclusive = 3\n }\n\n /** parameters common to opening or creating a new SQLiteDb */\n export interface OpenOrCreateParams {\n /** If true, do not require that the `be_Prop` table exist */\n rawSQLite?: boolean;\n /** @see immutable option at https://www.sqlite.org/c3ref/open.html */\n immutable?: boolean;\n /** Do not attempt to verify that the file is a valid sQLite file before opening. */\n skipFileCheck?: boolean;\n /** the default transaction mode\n * @see [[SQLiteDb.DefaultTxnMode]]\n */\n defaultTxn?: 0 | 1 | 2 | 3;\n /** see query parameters from 'URI Filenames' in https://www.sqlite.org/c3ref/open.html */\n queryParam?: string;\n }\n\n /** Parameters for opening an existing SQLiteDb */\n export interface OpenParams extends OpenOrCreateParams {\n /** use OpenMode.ReadWrite to open the file with write access */\n openMode: OpenMode;\n }\n\n /** Size of a SQLiteDb page in bytes */\n export interface PageSize {\n /** see https://www.sqlite.org/pragma.html#pragma_page_size */\n pageSize?: number;\n }\n\n /** Parameters for creating a new SQLiteDb */\n export type CreateParams = OpenOrCreateParams & PageSize;\n\n /** Arguments for `SqliteDb.withOpenDb` */\n export interface WithOpenDbArgs {\n /** The name of the database to open */\n dbName: string;\n /** either an object with the open parameters or just OpenMode value. */\n openMode?: OpenMode | SQLiteDb.OpenParams;\n /** @internal */\n container?: CloudSqlite.CloudContainer;\n }\n\n /** Arguments for `SQLiteDb.vacuum` */\n export interface VacuumDbArgs extends PageSize {\n /** if present, name of new file to [vacuum into](https://www.sqlite.org/lang_vacuum.html) */\n into?: LocalFileName;\n }\n}\n"]}
@@ -1,56 +1,56 @@
1
- /** @packageDocumentation
2
- * @module Schema
3
- */
4
- /** Base class for all schema classes - see [working with schemas and elements in TypeScript]($docs/learning/backend/SchemasAndElementsInTypeScript.md).
5
- * @public
6
- */
7
- export declare class Schema {
8
- /** The name of the BIS schema handled by this Schema.
9
- * @note Every subclass of Schema ** MUST ** override this method to identify its BIS schema.
10
- * Failure to do so will ordinarily result in an error when the schema is registered, since there may only
11
- * be one JavaScript class for a given BIS schema (usually the errant schema will collide with its superclass.)
12
- */
13
- static get schemaName(): string;
14
- /** if true, this Schema is a proxy for a missing Domain marked with the `BisCore.SchemaHasBehavior` customAttribute.
15
- * Classes generated for this Schema will disallow protected operations.
16
- * @internal
17
- */
18
- static get missingRequiredBehavior(): boolean;
19
- /** Get a semver-compatible string from a padded version string.
20
- * works on unpadded version strings as well
21
- * if there is no write version, it will be added
22
- * @example Schema.toSemverString("1.02.03") === "1.2.3"
23
- * @example Schema.toSemverString("1.01") === "1.0.1" // write version was added
24
- * @beta
25
- */
26
- static toSemverString(paddedVersion: string): string;
27
- /** Schemas may not be instantiated. The method is not private only because that precludes subclassing. It throws an
28
- * error if it is ever called.
29
- * @internal
30
- */
31
- protected constructor();
32
- }
33
- /** Manages registered schemas
34
- * @public
35
- */
36
- export declare class Schemas {
37
- private static readonly _registeredSchemas;
38
- private constructor();
39
- /** Register a schema prior to using it.
40
- * @throws [[IModelError]] if a schema of the same name is already registered.
41
- */
42
- static registerSchema(schema: typeof Schema): void;
43
- /** Unregister a schema, by name, if one is already registered.
44
- * This function is not normally needed, but is useful for cases where a generated *proxy* schema needs to be replaced by the *real* schema.
45
- * @param schemaName Name of the schema to unregister
46
- * @return true if the schema was unregistered
47
- * @internal
48
- */
49
- static unregisterSchema(schemaName: string): boolean;
50
- /** Look up a previously registered schema
51
- * @param schemaName The name of the schema
52
- * @returns the previously registered schema or undefined if not registered.
53
- */
54
- static getRegisteredSchema(schemaName: string): typeof Schema | undefined;
55
- }
1
+ /** @packageDocumentation
2
+ * @module Schema
3
+ */
4
+ /** Base class for all schema classes - see [working with schemas and elements in TypeScript]($docs/learning/backend/SchemasAndElementsInTypeScript.md).
5
+ * @public
6
+ */
7
+ export declare class Schema {
8
+ /** The name of the BIS schema handled by this Schema.
9
+ * @note Every subclass of Schema ** MUST ** override this method to identify its BIS schema.
10
+ * Failure to do so will ordinarily result in an error when the schema is registered, since there may only
11
+ * be one JavaScript class for a given BIS schema (usually the errant schema will collide with its superclass.)
12
+ */
13
+ static get schemaName(): string;
14
+ /** if true, this Schema is a proxy for a missing Domain marked with the `BisCore.SchemaHasBehavior` customAttribute.
15
+ * Classes generated for this Schema will disallow protected operations.
16
+ * @internal
17
+ */
18
+ static get missingRequiredBehavior(): boolean;
19
+ /** Get a semver-compatible string from a padded version string.
20
+ * works on unpadded version strings as well
21
+ * if there is no write version, it will be added
22
+ * @example Schema.toSemverString("1.02.03") === "1.2.3"
23
+ * @example Schema.toSemverString("1.01") === "1.0.1" // write version was added
24
+ * @beta
25
+ */
26
+ static toSemverString(paddedVersion: string): string;
27
+ /** Schemas may not be instantiated. The method is not private only because that precludes subclassing. It throws an
28
+ * error if it is ever called.
29
+ * @internal
30
+ */
31
+ protected constructor();
32
+ }
33
+ /** Manages registered schemas
34
+ * @public
35
+ */
36
+ export declare class Schemas {
37
+ private static readonly _registeredSchemas;
38
+ private constructor();
39
+ /** Register a schema prior to using it.
40
+ * @throws [[IModelError]] if a schema of the same name is already registered.
41
+ */
42
+ static registerSchema(schema: typeof Schema): void;
43
+ /** Unregister a schema, by name, if one is already registered.
44
+ * This function is not normally needed, but is useful for cases where a generated *proxy* schema needs to be replaced by the *real* schema.
45
+ * @param schemaName Name of the schema to unregister
46
+ * @return true if the schema was unregistered
47
+ * @internal
48
+ */
49
+ static unregisterSchema(schemaName: string): boolean;
50
+ /** Look up a previously registered schema
51
+ * @param schemaName The name of the schema
52
+ * @returns the previously registered schema or undefined if not registered.
53
+ */
54
+ static getRegisteredSchema(schemaName: string): typeof Schema | undefined;
55
+ }
56
56
  //# sourceMappingURL=Schema.d.ts.map