@itwin/core-backend 3.4.4 → 3.4.6

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 (226) hide show
  1. package/CHANGELOG.md +11 -1
  2. package/lib/cjs/AliCloudStorageService.d.ts +23 -23
  3. package/lib/cjs/AliCloudStorageService.js +71 -71
  4. package/lib/cjs/AliCloudStorageService.js.map +1 -1
  5. package/lib/cjs/BackendHubAccess.d.ts +224 -224
  6. package/lib/cjs/BackendHubAccess.js +41 -41
  7. package/lib/cjs/BackendHubAccess.js.map +1 -1
  8. package/lib/cjs/BackendLoggerCategory.d.ts +91 -91
  9. package/lib/cjs/BackendLoggerCategory.js +99 -99
  10. package/lib/cjs/BackendLoggerCategory.js.map +1 -1
  11. package/lib/cjs/BisCoreSchema.d.ts +21 -21
  12. package/lib/cjs/BisCoreSchema.js +60 -60
  13. package/lib/cjs/BisCoreSchema.js.map +1 -1
  14. package/lib/cjs/BriefcaseManager.d.ts +165 -165
  15. package/lib/cjs/BriefcaseManager.js +405 -405
  16. package/lib/cjs/BriefcaseManager.js.map +1 -1
  17. package/lib/cjs/Category.d.ts +153 -153
  18. package/lib/cjs/Category.js +243 -243
  19. package/lib/cjs/Category.js.map +1 -1
  20. package/lib/cjs/ChangeSummaryManager.d.ts +187 -187
  21. package/lib/cjs/ChangeSummaryManager.js +445 -445
  22. package/lib/cjs/ChangeSummaryManager.js.map +1 -1
  23. package/lib/cjs/ChangedElementsDb.d.ts +99 -99
  24. package/lib/cjs/ChangedElementsDb.js +165 -165
  25. package/lib/cjs/ChangedElementsDb.js.map +1 -1
  26. package/lib/cjs/ChangedElementsManager.d.ts +39 -39
  27. package/lib/cjs/ChangedElementsManager.js +88 -88
  28. package/lib/cjs/ChangedElementsManager.js.map +1 -1
  29. package/lib/cjs/CheckpointManager.d.ts +120 -120
  30. package/lib/cjs/CheckpointManager.js +343 -343
  31. package/lib/cjs/CheckpointManager.js.map +1 -1
  32. package/lib/cjs/ClassRegistry.d.ts +79 -79
  33. package/lib/cjs/ClassRegistry.js +249 -249
  34. package/lib/cjs/ClassRegistry.js.map +1 -1
  35. package/lib/cjs/CloudSqlite.d.ts +349 -349
  36. package/lib/cjs/CloudSqlite.js +151 -151
  37. package/lib/cjs/CloudSqlite.js.map +1 -1
  38. package/lib/cjs/CloudStorageBackend.d.ts +58 -58
  39. package/lib/cjs/CloudStorageBackend.js +173 -173
  40. package/lib/cjs/CloudStorageBackend.js.map +1 -1
  41. package/lib/cjs/CodeService.d.ts +396 -396
  42. package/lib/cjs/CodeService.js +63 -63
  43. package/lib/cjs/CodeService.js.map +1 -1
  44. package/lib/cjs/CodeSpecs.d.ts +50 -50
  45. package/lib/cjs/CodeSpecs.js +112 -112
  46. package/lib/cjs/CodeSpecs.js.map +1 -1
  47. package/lib/cjs/ConcurrentQuery.d.ts +11 -11
  48. package/lib/cjs/ConcurrentQuery.js +30 -30
  49. package/lib/cjs/ConcurrentQuery.js.map +1 -1
  50. package/lib/cjs/CustomViewState3dCreator.d.ts +21 -21
  51. package/lib/cjs/CustomViewState3dCreator.js +81 -81
  52. package/lib/cjs/CustomViewState3dCreator.js.map +1 -1
  53. package/lib/cjs/DevTools.d.ts +71 -71
  54. package/lib/cjs/DevTools.js +154 -154
  55. package/lib/cjs/DevTools.js.map +1 -1
  56. package/lib/cjs/DisplayStyle.d.ts +106 -106
  57. package/lib/cjs/DisplayStyle.js +256 -256
  58. package/lib/cjs/DisplayStyle.js.map +1 -1
  59. package/lib/cjs/ECDb.d.ts +191 -191
  60. package/lib/cjs/ECDb.js +350 -350
  61. package/lib/cjs/ECDb.js.map +1 -1
  62. package/lib/cjs/ECSchemaXmlContext.d.ts +18 -18
  63. package/lib/cjs/ECSchemaXmlContext.js +41 -41
  64. package/lib/cjs/ECSchemaXmlContext.js.map +1 -1
  65. package/lib/cjs/ECSqlStatement.d.ts +466 -466
  66. package/lib/cjs/ECSqlStatement.js +791 -791
  67. package/lib/cjs/ECSqlStatement.js.map +1 -1
  68. package/lib/cjs/Element.d.ts +1120 -1120
  69. package/lib/cjs/Element.js +1438 -1438
  70. package/lib/cjs/Element.js.map +1 -1
  71. package/lib/cjs/ElementAspect.d.ts +161 -161
  72. package/lib/cjs/ElementAspect.js +187 -187
  73. package/lib/cjs/ElementAspect.js.map +1 -1
  74. package/lib/cjs/ElementGraphics.d.ts +9 -9
  75. package/lib/cjs/ElementGraphics.js +41 -41
  76. package/lib/cjs/ElementGraphics.js.map +1 -1
  77. package/lib/cjs/ElementTreeWalker.d.ts +162 -162
  78. package/lib/cjs/ElementTreeWalker.js +409 -409
  79. package/lib/cjs/ElementTreeWalker.js.map +1 -1
  80. package/lib/cjs/Entity.d.ts +106 -106
  81. package/lib/cjs/Entity.js +134 -134
  82. package/lib/cjs/Entity.js.map +1 -1
  83. package/lib/cjs/EntityReferences.d.ts +45 -45
  84. package/lib/cjs/EntityReferences.js +91 -91
  85. package/lib/cjs/EntityReferences.js.map +1 -1
  86. package/lib/cjs/ExportGraphics.d.ts +317 -317
  87. package/lib/cjs/ExportGraphics.js +208 -208
  88. package/lib/cjs/ExportGraphics.js.map +1 -1
  89. package/lib/cjs/ExternalSource.d.ts +96 -96
  90. package/lib/cjs/ExternalSource.js +131 -131
  91. package/lib/cjs/ExternalSource.js.map +1 -1
  92. package/lib/cjs/GeoCoordConfig.d.ts +19 -19
  93. package/lib/cjs/GeoCoordConfig.js +82 -82
  94. package/lib/cjs/GeoCoordConfig.js.map +1 -1
  95. package/lib/cjs/GeometrySummary.d.ts +4 -4
  96. package/lib/cjs/GeometrySummary.js +380 -380
  97. package/lib/cjs/GeometrySummary.js.map +1 -1
  98. package/lib/cjs/HubMock.d.ts +93 -93
  99. package/lib/cjs/HubMock.js +190 -190
  100. package/lib/cjs/HubMock.js.map +1 -1
  101. package/lib/cjs/IModelCloneContext.d.ts +89 -89
  102. package/lib/cjs/IModelCloneContext.js +159 -159
  103. package/lib/cjs/IModelCloneContext.js.map +1 -1
  104. package/lib/cjs/IModelDb.d.ts +1180 -1180
  105. package/lib/cjs/IModelDb.js +2371 -2371
  106. package/lib/cjs/IModelDb.js.map +1 -1
  107. package/lib/cjs/IModelHost.d.ts +361 -361
  108. package/lib/cjs/IModelHost.js +489 -489
  109. package/lib/cjs/IModelHost.js.map +1 -1
  110. package/lib/cjs/IModelJsFs.d.ts +62 -62
  111. package/lib/cjs/IModelJsFs.js +140 -140
  112. package/lib/cjs/IModelJsFs.js.map +1 -1
  113. package/lib/cjs/IpcHost.d.ts +98 -98
  114. package/lib/cjs/IpcHost.js +234 -234
  115. package/lib/cjs/IpcHost.js.map +1 -1
  116. package/lib/cjs/LineStyle.d.ts +311 -311
  117. package/lib/cjs/LineStyle.js +295 -295
  118. package/lib/cjs/LineStyle.js.map +1 -1
  119. package/lib/cjs/LocalHub.d.ts +162 -162
  120. package/lib/cjs/LocalHub.js +587 -587
  121. package/lib/cjs/LocalHub.js.map +1 -1
  122. package/lib/cjs/LocalhostIpcHost.d.ts +20 -20
  123. package/lib/cjs/LocalhostIpcHost.js +81 -81
  124. package/lib/cjs/LocalhostIpcHost.js.map +1 -1
  125. package/lib/cjs/Material.d.ts +103 -103
  126. package/lib/cjs/Material.js +147 -147
  127. package/lib/cjs/Material.js.map +1 -1
  128. package/lib/cjs/Model.d.ts +392 -392
  129. package/lib/cjs/Model.js +485 -485
  130. package/lib/cjs/Model.js.map +1 -1
  131. package/lib/cjs/NativeAppStorage.d.ts +51 -51
  132. package/lib/cjs/NativeAppStorage.js +202 -202
  133. package/lib/cjs/NativeAppStorage.js.map +1 -1
  134. package/lib/cjs/NativeHost.d.ts +52 -52
  135. package/lib/cjs/NativeHost.js +168 -168
  136. package/lib/cjs/NativeHost.js.map +1 -1
  137. package/lib/cjs/NavigationRelationship.d.ts +156 -156
  138. package/lib/cjs/NavigationRelationship.js +225 -225
  139. package/lib/cjs/NavigationRelationship.js.map +1 -1
  140. package/lib/cjs/PromiseMemoizer.d.ts +51 -51
  141. package/lib/cjs/PromiseMemoizer.js +101 -101
  142. package/lib/cjs/PromiseMemoizer.js.map +1 -1
  143. package/lib/cjs/PropertyStore.d.ts +132 -132
  144. package/lib/cjs/PropertyStore.js +11 -11
  145. package/lib/cjs/PropertyStore.js.map +1 -1
  146. package/lib/cjs/Relationship.d.ts +416 -416
  147. package/lib/cjs/Relationship.js +494 -494
  148. package/lib/cjs/Relationship.js.map +1 -1
  149. package/lib/cjs/RpcBackend.d.ts +28 -28
  150. package/lib/cjs/RpcBackend.js +126 -126
  151. package/lib/cjs/RpcBackend.js.map +1 -1
  152. package/lib/cjs/SQLiteDb.d.ts +219 -219
  153. package/lib/cjs/SQLiteDb.js +214 -214
  154. package/lib/cjs/SQLiteDb.js.map +1 -1
  155. package/lib/cjs/Schema.d.ts +55 -55
  156. package/lib/cjs/Schema.js +83 -83
  157. package/lib/cjs/Schema.js.map +1 -1
  158. package/lib/cjs/ServerBasedLocks.d.ts +57 -57
  159. package/lib/cjs/ServerBasedLocks.js +168 -168
  160. package/lib/cjs/ServerBasedLocks.js.map +1 -1
  161. package/lib/cjs/SqliteStatement.d.ts +283 -283
  162. package/lib/cjs/SqliteStatement.js +448 -448
  163. package/lib/cjs/SqliteStatement.js.map +1 -1
  164. package/lib/cjs/Texture.d.ts +58 -58
  165. package/lib/cjs/Texture.js +82 -82
  166. package/lib/cjs/Texture.js.map +1 -1
  167. package/lib/cjs/TileStorage.d.ts +18 -18
  168. package/lib/cjs/TileStorage.js +90 -90
  169. package/lib/cjs/TileStorage.js.map +1 -1
  170. package/lib/cjs/TxnManager.d.ts +202 -202
  171. package/lib/cjs/TxnManager.js +356 -356
  172. package/lib/cjs/TxnManager.js.map +1 -1
  173. package/lib/cjs/ViewDefinition.d.ts +439 -439
  174. package/lib/cjs/ViewDefinition.js +646 -646
  175. package/lib/cjs/ViewDefinition.js.map +1 -1
  176. package/lib/cjs/ViewStateHydrator.d.ts +13 -13
  177. package/lib/cjs/ViewStateHydrator.js +103 -103
  178. package/lib/cjs/ViewStateHydrator.js.map +1 -1
  179. package/lib/cjs/assets/IModelChange.02.00.00.ecschema.xml +90 -90
  180. package/lib/cjs/assets/Settings/Schemas/Cloud.Schema.json +67 -67
  181. package/lib/cjs/assets/Settings/Schemas/Gcs.schema.json +31 -31
  182. package/lib/cjs/assets/Settings/Schemas/Workspace.Schema.json +52 -52
  183. package/lib/cjs/assets/Settings/backend.setting.json5 +138 -138
  184. package/lib/cjs/core-backend.d.ts +183 -183
  185. package/lib/cjs/core-backend.js +203 -203
  186. package/lib/cjs/core-backend.js.map +1 -1
  187. package/lib/cjs/domains/FunctionalElements.d.ts +101 -101
  188. package/lib/cjs/domains/FunctionalElements.js +145 -145
  189. package/lib/cjs/domains/FunctionalElements.js.map +1 -1
  190. package/lib/cjs/domains/FunctionalSchema.d.ts +13 -13
  191. package/lib/cjs/domains/FunctionalSchema.js +40 -40
  192. package/lib/cjs/domains/FunctionalSchema.js.map +1 -1
  193. package/lib/cjs/domains/GenericElements.d.ts +177 -177
  194. package/lib/cjs/domains/GenericElements.js +263 -263
  195. package/lib/cjs/domains/GenericElements.js.map +1 -1
  196. package/lib/cjs/domains/GenericSchema.d.ts +10 -10
  197. package/lib/cjs/domains/GenericSchema.js +28 -28
  198. package/lib/cjs/domains/GenericSchema.js.map +1 -1
  199. package/lib/cjs/rpc-impl/DevToolsRpcImpl.d.ts +15 -15
  200. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js +32 -32
  201. package/lib/cjs/rpc-impl/DevToolsRpcImpl.js.map +1 -1
  202. package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts +46 -46
  203. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +287 -287
  204. package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -1
  205. package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts +22 -22
  206. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js +202 -202
  207. package/lib/cjs/rpc-impl/IModelTileRpcImpl.js.map +1 -1
  208. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts +36 -36
  209. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js +168 -168
  210. package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -1
  211. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.d.ts +16 -16
  212. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js +43 -43
  213. package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js.map +1 -1
  214. package/lib/cjs/rpc-impl/WipRpcImpl.d.ts +15 -15
  215. package/lib/cjs/rpc-impl/WipRpcImpl.js +37 -37
  216. package/lib/cjs/rpc-impl/WipRpcImpl.js.map +1 -1
  217. package/lib/cjs/workspace/Settings.d.ts +186 -186
  218. package/lib/cjs/workspace/Settings.js +155 -155
  219. package/lib/cjs/workspace/Settings.js.map +1 -1
  220. package/lib/cjs/workspace/SettingsSchemas.d.ts +75 -75
  221. package/lib/cjs/workspace/SettingsSchemas.js +191 -191
  222. package/lib/cjs/workspace/SettingsSchemas.js.map +1 -1
  223. package/lib/cjs/workspace/Workspace.d.ts +414 -414
  224. package/lib/cjs/workspace/Workspace.js +543 -543
  225. package/lib/cjs/workspace/Workspace.js.map +1 -1
  226. package/package.json +12 -12
@@ -1,215 +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 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 = {}));
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 = {}));
215
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;;;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,MA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C,sBAAsB,CAAC,GAAG,CAAC,CAAC;QAC9C,IAAI;YACF,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC;SACpB;gBAAS;YACR,IAAI,CAAC,OAAO,EAAE,CAAC;SAChB;IACH,CAAC;CACF;AA1MD,4BA0MC;AAED,cAAc;AACd,WAAiB,QAAQ;IAqDvB;;OAEG;IACH,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;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
+ {"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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CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC;QAC9C,IAAI;YACF,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC;SACpB;gBAAS;YACR,IAAI,CAAC,OAAO,EAAE,CAAC;SAChB;IACH,CAAC;CACF;AA1MD,4BA0MC;AAED,cAAc;AACd,WAAiB,QAAQ;IAqDvB;;OAEG;IACH,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;AAgDH,CAAC,EAjHgB,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAiHxB","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 { IModelJsNative } from \"@bentley/imodeljs-native\";\r\nimport { DbResult, IDisposable, OpenMode } from \"@itwin/core-bentley\";\r\nimport { LocalFileName } from \"@itwin/core-common\";\r\nimport { CloudSqlite } from \"./CloudSqlite\";\r\nimport { IModelHost } from \"./IModelHost\";\r\nimport { SqliteStatement, StatementCache } from \"./SqliteStatement\";\r\n\r\n// cspell:ignore savepoint\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 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): void;\r\n /** @beta */\r\n public createDb(dbName: string, container?: CloudSqlite.CloudContainer, params?: SQLiteDb.CreateParams): void;\r\n /** @internal */\r\n public createDb(dbName: string, container?: CloudSqlite.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 * @beta\r\n */\r\n public openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams, container?: CloudSqlite.CloudContainer): void;\r\n\r\n /** @internal */\r\n public openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams, container?: CloudSqlite.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. Otherwise unsaved changes are abandoned.\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 this SQLiteDb is open */\r\n public get isOpen(): boolean { return this.nativeDb.isOpen(); }\r\n\r\n /** Returns true if this SQLiteDb is open readonly */\r\n public get isReadonly(): boolean { return this.nativeDb.isReadonly(); }\r\n\r\n /**\r\n * Open a database, perform an operation, then close the database.\r\n *\r\n * Details:\r\n * - if database is open, throw an error\r\n * - open a database\r\n * - call a function with the database opened. If it is async, await its return.\r\n * - if function throws, abandon all changes, close database, and rethrow\r\n * - save all changes\r\n * - close the database\r\n * @return value from operation\r\n */\r\n public withOpenDb<T>(args: SQLiteDb.WithOpenDbArgs, operation: () => T): T {\r\n if (this.isOpen)\r\n throw new Error(\"database is already open\");\r\n\r\n const save = () => this.closeDb(true), abandon = () => this.closeDb(false);\r\n this.openDb(args.dbName, args.openMode ?? OpenMode.Readonly, args.container);\r\n try {\r\n const result = operation();\r\n result instanceof Promise ? result.then(save, abandon) : save();\r\n return result;\r\n } catch (e) {\r\n abandon();\r\n throw e;\r\n }\r\n }\r\n\r\n /**\r\n * Perform an operation on a database in a CloudContainer with the write lock held.\r\n *\r\n * Details:\r\n * - acquire the write lock on a CloudContainer\r\n * - call `withOpenDb` with openMode `ReadWrite`\r\n * - upload changes\r\n * - release the write lock\r\n * @param args arguments to lock the container and open the database\r\n * @param operation an operation performed on the database with the write lock held.\r\n * @return value from operation\r\n * @internal\r\n */\r\n public async withLockedContainer<T>(args: CloudSqlite.LockAndOpenArgs, operation: () => T) {\r\n return CloudSqlite.withWriteLock(args.user, args.container, () => this.withOpenDb({ ...args, openMode: OpenMode.ReadWrite }, operation), 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?: SQLiteDb.VacuumDbArgs) {\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 = callback(stmt);\r\n val instanceof Promise ? val.then(release, release) : release();\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 = callback(stmt);\r\n val instanceof Promise ? val.then(release, release) : release();\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 * Perform an operation on this database within a [savepoint](https://www.sqlite.org/lang_savepoint.html). If the operation completes successfully, the\r\n * changes remain in the current transaction. If the operation throws an exception, the savepoint is rolled back\r\n * and all changes to the database from this method are reversed, leaving the transaction exactly as it was before this method.\r\n */\r\n public withSavePoint(savePointName: string, operation: () => void) {\r\n if (this.isReadonly)\r\n throw new Error(\"database is readonly\");\r\n\r\n this.executeSQL(`SAVEPOINT ${savePointName}`);\r\n try {\r\n operation();\r\n this.executeSQL(`RELEASE ${savePointName}`);\r\n } catch (e) {\r\n this.executeSQL(`ROLLBACK TO ${savePointName}`);\r\n throw e;\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 /** interface for reading and writing to a blob in a SQLiteDb\r\n * @internal\r\n */\r\n export interface BlobIO {\r\n /** Close this BlobIO if it is opened.\r\n * @note this BlobIO *may* be reused after this call by calling `open` again.\r\n */\r\n close(): void;\r\n /** get the total number of bytes in the blob */\r\n getNumBytes(): number;\r\n /** @return true if this BlobIO was successfully opened and may be use to read or write the blob */\r\n isValid(): boolean;\r\n /** Open this BlobIO against a table/row/column in a Db */\r\n open(\r\n /** The database for the blob */\r\n db: IModelJsNative.AnyDb,\r\n args: {\r\n /** the name of the table for the blob*/\r\n tableName: string;\r\n /** the name of the column for the blob */\r\n columnName: string;\r\n /** The rowId of the blob */\r\n row: number;\r\n /** If true, open this BlobIO for write access */\r\n writeable?: boolean;\r\n }): void;\r\n /** Read from a blob\r\n * @returns the contents of the requested byte range\r\n */\r\n read(args: {\r\n /** The number of bytes to read */\r\n numBytes: number;\r\n /** starting offset within the blob to read */\r\n offset: number;\r\n /** If present and of sufficient size, use this ArrayBuffer for the value. */\r\n blob?: ArrayBuffer;\r\n }): Uint8Array;\r\n /** Reposition this BlobIO to a new rowId\r\n * @note this BlobIO must be valid when this methods is called.\r\n */\r\n changeRow(row: number): void;\r\n /** Write to a blob */\r\n write(args: {\r\n /** The number of bytes to write */\r\n numBytes: number;\r\n /** starting offset within the blob to write */\r\n offset: number;\r\n /** the value to write */\r\n blob: ArrayBuffer;\r\n }): void;\r\n }\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 /** Size of a SQLiteDb page in bytes */\r\n export interface PageSize {\r\n /** see https://www.sqlite.org/pragma.html#pragma_page_size */\r\n pageSize?: number;\r\n }\r\n\r\n /** Parameters for creating a new SQLiteDb */\r\n export type CreateParams = OpenOrCreateParams & PageSize;\r\n\r\n /** Arguments for `SqliteDb.withOpenDb` */\r\n export interface WithOpenDbArgs {\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?: CloudSqlite.CloudContainer;\r\n }\r\n\r\n /** Arguments for `SQLiteDb.vacuum` */\r\n export interface VacuumDbArgs extends PageSize {\r\n /** if present, name of new file to [vacuum into](https://www.sqlite.org/lang_vacuum.html) */\r\n into?: LocalFileName;\r\n }\r\n}\r\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