@itwin/core-backend 4.0.0-dev.10 → 4.0.0-dev.100
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +68 -1
- package/lib/cjs/BackendHubAccess.d.ts +226 -224
- package/lib/cjs/BackendHubAccess.d.ts.map +1 -1
- package/lib/cjs/BackendHubAccess.js +41 -41
- package/lib/cjs/BackendHubAccess.js.map +1 -1
- package/lib/cjs/BackendLoggerCategory.d.ts +90 -91
- package/lib/cjs/BackendLoggerCategory.d.ts.map +1 -1
- package/lib/cjs/BackendLoggerCategory.js +98 -99
- package/lib/cjs/BackendLoggerCategory.js.map +1 -1
- package/lib/cjs/BisCoreSchema.d.ts +21 -21
- package/lib/cjs/BisCoreSchema.js +60 -60
- package/lib/cjs/BlobContainerService.d.ts +120 -0
- package/lib/cjs/BlobContainerService.d.ts.map +1 -0
- package/lib/cjs/BlobContainerService.js +18 -0
- package/lib/cjs/BlobContainerService.js.map +1 -0
- package/lib/cjs/BriefcaseManager.d.ts +184 -170
- package/lib/cjs/BriefcaseManager.d.ts.map +1 -1
- package/lib/cjs/BriefcaseManager.js +421 -414
- package/lib/cjs/BriefcaseManager.js.map +1 -1
- package/lib/cjs/Category.d.ts +153 -153
- package/lib/cjs/Category.js +243 -243
- package/lib/cjs/Category.js.map +1 -1
- package/lib/cjs/ChangeSummaryManager.d.ts +187 -187
- package/lib/cjs/ChangeSummaryManager.js +444 -445
- package/lib/cjs/ChangeSummaryManager.js.map +1 -1
- package/lib/cjs/ChangedElementsDb.d.ts +99 -99
- package/lib/cjs/ChangedElementsDb.js +165 -165
- package/lib/cjs/ChangedElementsManager.d.ts +39 -39
- package/lib/cjs/ChangedElementsManager.js +88 -88
- package/lib/cjs/ChannelControl.d.ts +70 -0
- package/lib/cjs/ChannelControl.d.ts.map +1 -0
- package/lib/cjs/ChannelControl.js +89 -0
- package/lib/cjs/ChannelControl.js.map +1 -0
- package/lib/cjs/CheckpointManager.d.ts +121 -121
- package/lib/cjs/CheckpointManager.d.ts.map +1 -1
- package/lib/cjs/CheckpointManager.js +351 -349
- package/lib/cjs/CheckpointManager.js.map +1 -1
- package/lib/cjs/ClassRegistry.d.ts +79 -79
- package/lib/cjs/ClassRegistry.js +249 -245
- package/lib/cjs/ClassRegistry.js.map +1 -1
- package/lib/cjs/CloudSqlite.d.ts +572 -350
- package/lib/cjs/CloudSqlite.d.ts.map +1 -1
- package/lib/cjs/CloudSqlite.js +374 -153
- package/lib/cjs/CloudSqlite.js.map +1 -1
- package/lib/cjs/CodeService.d.ts +399 -396
- package/lib/cjs/CodeService.d.ts.map +1 -1
- package/lib/cjs/CodeService.js +63 -63
- package/lib/cjs/CodeService.js.map +1 -1
- package/lib/cjs/CodeSpecs.d.ts +58 -55
- package/lib/cjs/CodeSpecs.d.ts.map +1 -1
- package/lib/cjs/CodeSpecs.js +154 -124
- package/lib/cjs/CodeSpecs.js.map +1 -1
- package/lib/cjs/ConcurrentQuery.d.ts +13 -13
- package/lib/cjs/ConcurrentQuery.d.ts.map +1 -1
- package/lib/cjs/ConcurrentQuery.js +36 -36
- package/lib/cjs/CustomViewState3dCreator.d.ts +21 -21
- package/lib/cjs/CustomViewState3dCreator.d.ts.map +1 -1
- package/lib/cjs/CustomViewState3dCreator.js +80 -81
- package/lib/cjs/CustomViewState3dCreator.js.map +1 -1
- package/lib/cjs/DevTools.d.ts +74 -71
- package/lib/cjs/DevTools.d.ts.map +1 -1
- package/lib/cjs/DevTools.js +156 -154
- package/lib/cjs/DevTools.js.map +1 -1
- package/lib/cjs/DisplayStyle.d.ts +104 -106
- package/lib/cjs/DisplayStyle.d.ts.map +1 -1
- package/lib/cjs/DisplayStyle.js +251 -256
- package/lib/cjs/DisplayStyle.js.map +1 -1
- package/lib/cjs/ECDb.d.ts +194 -191
- package/lib/cjs/ECDb.d.ts.map +1 -1
- package/lib/cjs/ECDb.js +351 -350
- package/lib/cjs/ECDb.js.map +1 -1
- package/lib/cjs/ECSchemaXmlContext.d.ts +18 -18
- package/lib/cjs/ECSchemaXmlContext.d.ts.map +1 -1
- package/lib/cjs/ECSchemaXmlContext.js +41 -41
- package/lib/cjs/ECSqlStatement.d.ts +473 -473
- package/lib/cjs/ECSqlStatement.js +791 -791
- package/lib/cjs/Element.d.ts +1105 -1109
- package/lib/cjs/Element.d.ts.map +1 -1
- package/lib/cjs/Element.js +1416 -1427
- package/lib/cjs/Element.js.map +1 -1
- package/lib/cjs/ElementAspect.d.ts +175 -179
- package/lib/cjs/ElementAspect.d.ts.map +1 -1
- package/lib/cjs/ElementAspect.js +202 -211
- package/lib/cjs/ElementAspect.js.map +1 -1
- package/lib/cjs/ElementGraphics.d.ts +9 -9
- package/lib/cjs/ElementGraphics.js +41 -41
- package/lib/cjs/ElementGraphics.js.map +1 -1
- package/lib/cjs/ElementTreeWalker.d.ts +162 -162
- package/lib/cjs/ElementTreeWalker.d.ts.map +1 -1
- package/lib/cjs/ElementTreeWalker.js +409 -409
- package/lib/cjs/ElementTreeWalker.js.map +1 -1
- package/lib/cjs/Entity.d.ts +102 -106
- package/lib/cjs/Entity.d.ts.map +1 -1
- package/lib/cjs/Entity.js +118 -134
- package/lib/cjs/Entity.js.map +1 -1
- package/lib/cjs/EntityReferences.d.ts +49 -49
- package/lib/cjs/EntityReferences.d.ts.map +1 -1
- package/lib/cjs/EntityReferences.js +95 -95
- package/lib/cjs/ExportGraphics.d.ts +317 -317
- package/lib/cjs/ExportGraphics.d.ts.map +1 -1
- package/lib/cjs/ExportGraphics.js +208 -208
- package/lib/cjs/ExternalSource.d.ts +95 -96
- package/lib/cjs/ExternalSource.d.ts.map +1 -1
- package/lib/cjs/ExternalSource.js +130 -131
- package/lib/cjs/ExternalSource.js.map +1 -1
- package/lib/cjs/GeoCoordConfig.d.ts +19 -19
- package/lib/cjs/GeoCoordConfig.js +85 -85
- package/lib/cjs/GeoCoordConfig.js.map +1 -1
- package/lib/cjs/GeometrySummary.d.ts +4 -4
- package/lib/cjs/GeometrySummary.js +333 -333
- package/lib/cjs/GeometrySummary.js.map +1 -1
- package/lib/cjs/HubMock.d.ts +94 -94
- package/lib/cjs/HubMock.js +220 -222
- package/lib/cjs/HubMock.js.map +1 -1
- package/lib/cjs/IModelCloneContext.d.ts +8 -8
- package/lib/cjs/IModelCloneContext.d.ts.map +1 -1
- package/lib/cjs/IModelCloneContext.js +15 -15
- package/lib/cjs/IModelDb.d.ts +1222 -1196
- package/lib/cjs/IModelDb.d.ts.map +1 -1
- package/lib/cjs/IModelDb.js +2389 -2392
- package/lib/cjs/IModelDb.js.map +1 -1
- package/lib/cjs/IModelElementCloneContext.d.ts +89 -89
- package/lib/cjs/IModelElementCloneContext.js +159 -159
- package/lib/cjs/IModelHost.d.ts +370 -369
- package/lib/cjs/IModelHost.d.ts.map +1 -1
- package/lib/cjs/IModelHost.js +476 -496
- package/lib/cjs/IModelHost.js.map +1 -1
- package/lib/cjs/IModelJsFs.d.ts +62 -62
- package/lib/cjs/IModelJsFs.js +139 -140
- package/lib/cjs/IModelJsFs.js.map +1 -1
- package/lib/cjs/IpcHost.d.ts +104 -104
- package/lib/cjs/IpcHost.js +276 -278
- package/lib/cjs/IpcHost.js.map +1 -1
- package/lib/cjs/LineStyle.d.ts +311 -311
- package/lib/cjs/LineStyle.js +295 -295
- package/lib/cjs/LocalHub.d.ts +162 -162
- package/lib/cjs/LocalHub.d.ts.map +1 -1
- package/lib/cjs/LocalHub.js +579 -584
- package/lib/cjs/LocalHub.js.map +1 -1
- package/lib/cjs/LocalhostIpcHost.d.ts +21 -20
- package/lib/cjs/LocalhostIpcHost.d.ts.map +1 -1
- package/lib/cjs/LocalhostIpcHost.js +79 -81
- package/lib/cjs/LocalhostIpcHost.js.map +1 -1
- package/lib/cjs/Material.d.ts +131 -131
- package/lib/cjs/Material.d.ts.map +1 -1
- package/lib/cjs/Material.js +185 -181
- package/lib/cjs/Material.js.map +1 -1
- package/lib/cjs/Model.d.ts +391 -392
- package/lib/cjs/Model.d.ts.map +1 -1
- package/lib/cjs/Model.js +487 -485
- package/lib/cjs/Model.js.map +1 -1
- package/lib/cjs/NativeAppStorage.d.ts +51 -51
- package/lib/cjs/NativeAppStorage.js +202 -202
- package/lib/cjs/NativeAppStorage.js.map +1 -1
- package/lib/cjs/NativeHost.d.ts +52 -52
- package/lib/cjs/NativeHost.d.ts.map +1 -1
- package/lib/cjs/NativeHost.js +158 -163
- package/lib/cjs/NativeHost.js.map +1 -1
- package/lib/cjs/NavigationRelationship.d.ts +156 -156
- package/lib/cjs/NavigationRelationship.js +225 -225
- package/lib/cjs/NavigationRelationship.js.map +1 -1
- package/lib/cjs/PromiseMemoizer.d.ts +51 -51
- package/lib/cjs/PromiseMemoizer.d.ts.map +1 -1
- package/lib/cjs/PromiseMemoizer.js +101 -101
- package/lib/cjs/PromiseMemoizer.js.map +1 -1
- package/lib/cjs/PropertyStore.d.ts +123 -132
- package/lib/cjs/PropertyStore.d.ts.map +1 -1
- package/lib/cjs/PropertyStore.js +179 -11
- package/lib/cjs/PropertyStore.js.map +1 -1
- package/lib/cjs/Relationship.d.ts +413 -416
- package/lib/cjs/Relationship.d.ts.map +1 -1
- package/lib/cjs/Relationship.js +491 -494
- package/lib/cjs/Relationship.js.map +1 -1
- package/lib/cjs/RpcBackend.d.ts +5 -5
- package/lib/cjs/RpcBackend.js +32 -32
- package/lib/cjs/SQLiteDb.d.ts +317 -219
- package/lib/cjs/SQLiteDb.d.ts.map +1 -1
- package/lib/cjs/SQLiteDb.js +318 -214
- package/lib/cjs/SQLiteDb.js.map +1 -1
- package/lib/cjs/Schema.d.ts +55 -55
- package/lib/cjs/Schema.js +83 -83
- package/lib/cjs/Schema.js.map +1 -1
- package/lib/cjs/ServerBasedLocks.d.ts +57 -57
- package/lib/cjs/ServerBasedLocks.js +168 -168
- package/lib/cjs/ServerBasedLocks.js.map +1 -1
- package/lib/cjs/SqliteStatement.d.ts +360 -360
- package/lib/cjs/SqliteStatement.d.ts.map +1 -1
- package/lib/cjs/SqliteStatement.js +586 -586
- package/lib/cjs/Texture.d.ts +58 -58
- package/lib/cjs/Texture.js +82 -82
- package/lib/cjs/Texture.js.map +1 -1
- package/lib/cjs/TileStorage.d.ts +44 -18
- package/lib/cjs/TileStorage.d.ts.map +1 -1
- package/lib/cjs/TileStorage.js +109 -90
- package/lib/cjs/TileStorage.js.map +1 -1
- package/lib/cjs/TxnManager.d.ts +202 -202
- package/lib/cjs/TxnManager.d.ts.map +1 -1
- package/lib/cjs/TxnManager.js +356 -356
- package/lib/cjs/TxnManager.js.map +1 -1
- package/lib/cjs/ViewDefinition.d.ts +429 -439
- package/lib/cjs/ViewDefinition.d.ts.map +1 -1
- package/lib/cjs/ViewDefinition.js +640 -646
- package/lib/cjs/ViewDefinition.js.map +1 -1
- package/lib/cjs/ViewStateHydrator.d.ts +13 -13
- package/lib/cjs/ViewStateHydrator.js +103 -103
- package/lib/cjs/core-backend.d.ts +181 -184
- package/lib/cjs/core-backend.d.ts.map +1 -1
- package/lib/cjs/core-backend.js +205 -204
- package/lib/cjs/core-backend.js.map +1 -1
- package/lib/cjs/domains/FunctionalElements.d.ts +101 -101
- package/lib/cjs/domains/FunctionalElements.js +145 -145
- package/lib/cjs/domains/FunctionalElements.js.map +1 -1
- package/lib/cjs/domains/FunctionalSchema.d.ts +13 -13
- package/lib/cjs/domains/FunctionalSchema.d.ts.map +1 -1
- package/lib/cjs/domains/FunctionalSchema.js +39 -40
- package/lib/cjs/domains/FunctionalSchema.js.map +1 -1
- package/lib/cjs/domains/GenericElements.d.ts +177 -177
- package/lib/cjs/domains/GenericElements.js +263 -263
- package/lib/cjs/domains/GenericSchema.d.ts +10 -10
- package/lib/cjs/domains/GenericSchema.js +28 -28
- package/lib/cjs/rpc/multipart.d.ts +11 -11
- package/lib/cjs/rpc/multipart.js +71 -71
- package/lib/cjs/rpc/tracing.d.ts +28 -28
- package/lib/cjs/rpc/tracing.js +73 -74
- package/lib/cjs/rpc/tracing.js.map +1 -1
- package/lib/cjs/rpc/web/logging.d.ts +9 -9
- package/lib/cjs/rpc/web/logging.js +43 -43
- package/lib/cjs/rpc/web/request.d.ts +6 -6
- package/lib/cjs/rpc/web/request.js +73 -74
- package/lib/cjs/rpc/web/request.js.map +1 -1
- package/lib/cjs/rpc/web/response.d.ts +6 -6
- package/lib/cjs/rpc/web/response.js +105 -106
- package/lib/cjs/rpc/web/response.js.map +1 -1
- package/lib/cjs/rpc-impl/DevToolsRpcImpl.d.ts +15 -15
- package/lib/cjs/rpc-impl/DevToolsRpcImpl.js +32 -32
- package/lib/cjs/rpc-impl/IModelReadRpcImpl.d.ts +47 -47
- package/lib/cjs/rpc-impl/IModelReadRpcImpl.js +293 -294
- package/lib/cjs/rpc-impl/IModelReadRpcImpl.js.map +1 -1
- package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts +20 -22
- package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts.map +1 -1
- package/lib/cjs/rpc-impl/IModelTileRpcImpl.js +193 -205
- package/lib/cjs/rpc-impl/IModelTileRpcImpl.js.map +1 -1
- package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts +36 -36
- package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js +166 -168
- package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -1
- package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.d.ts +16 -16
- package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js +42 -43
- package/lib/cjs/rpc-impl/SnapshotIModelRpcImpl.js.map +1 -1
- package/lib/cjs/rpc-impl/WipRpcImpl.d.ts +15 -15
- package/lib/cjs/rpc-impl/WipRpcImpl.js +37 -37
- package/lib/cjs/workspace/Settings.d.ts +186 -186
- package/lib/cjs/workspace/Settings.d.ts.map +1 -1
- package/lib/cjs/workspace/Settings.js +155 -155
- package/lib/cjs/workspace/Settings.js.map +1 -1
- package/lib/cjs/workspace/SettingsSchemas.d.ts +75 -75
- package/lib/cjs/workspace/SettingsSchemas.js +190 -191
- package/lib/cjs/workspace/SettingsSchemas.js.map +1 -1
- package/lib/cjs/workspace/Workspace.d.ts +411 -414
- package/lib/cjs/workspace/Workspace.d.ts.map +1 -1
- package/lib/cjs/workspace/Workspace.js +521 -543
- package/lib/cjs/workspace/Workspace.js.map +1 -1
- package/package.json +25 -28
- package/lib/cjs/AliCloudStorageService.d.ts +0 -24
- package/lib/cjs/AliCloudStorageService.d.ts.map +0 -1
- package/lib/cjs/AliCloudStorageService.js +0 -72
- package/lib/cjs/AliCloudStorageService.js.map +0 -1
- package/lib/cjs/CloudStorageBackend.d.ts +0 -59
- package/lib/cjs/CloudStorageBackend.d.ts.map +0 -1
- package/lib/cjs/CloudStorageBackend.js +0 -174
- package/lib/cjs/CloudStorageBackend.js.map +0 -1
package/lib/cjs/SQLiteDb.js
CHANGED
|
@@ -1,215 +1,319 @@
|
|
|
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
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
* -
|
|
88
|
-
*
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
* For statements
|
|
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
|
-
|
|
146
|
-
const stmt = this.prepareSqliteStatement(sql);
|
|
147
|
-
const release = () =>
|
|
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
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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.VersionedSqliteDb = exports.SQLiteDb = void 0;
|
|
11
|
+
const fs = require("fs");
|
|
12
|
+
const path_1 = require("path");
|
|
13
|
+
const semver = require("semver");
|
|
14
|
+
const core_bentley_1 = require("@itwin/core-bentley");
|
|
15
|
+
const CloudSqlite_1 = require("./CloudSqlite");
|
|
16
|
+
const IModelHost_1 = require("./IModelHost");
|
|
17
|
+
const IModelJsFs_1 = require("./IModelJsFs");
|
|
18
|
+
const SqliteStatement_1 = require("./SqliteStatement");
|
|
19
|
+
// cspell:ignore savepoint julianday rowid
|
|
20
|
+
/* eslint-disable @typescript-eslint/unified-signatures */
|
|
21
|
+
/**
|
|
22
|
+
* A "generic" SQLiteDb. This class may be used to access local files or databases in a cloud container.
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
class SQLiteDb {
|
|
26
|
+
constructor() {
|
|
27
|
+
/** @internal */
|
|
28
|
+
this.nativeDb = new IModelHost_1.IModelHost.platform.SQLiteDb();
|
|
29
|
+
this._sqliteStatementCache = new SqliteStatement_1.StatementCache();
|
|
30
|
+
}
|
|
31
|
+
/** @internal */
|
|
32
|
+
static createBlobIO() {
|
|
33
|
+
return new IModelHost_1.IModelHost.platform.BlobIO();
|
|
34
|
+
}
|
|
35
|
+
/** alias for closeDb.
|
|
36
|
+
* @deprecated in 4.0, use [[closeDb]]
|
|
37
|
+
*/
|
|
38
|
+
dispose() {
|
|
39
|
+
this.closeDb();
|
|
40
|
+
}
|
|
41
|
+
createDb(dbName, container, params) {
|
|
42
|
+
this.nativeDb.createDb(dbName, container, params);
|
|
43
|
+
}
|
|
44
|
+
openDb(dbName, openMode, container) {
|
|
45
|
+
this.nativeDb.openDb(dbName, openMode, container);
|
|
46
|
+
}
|
|
47
|
+
/** Close SQLiteDb.
|
|
48
|
+
* @param saveChanges if true, call `saveChanges` before closing db. Otherwise unsaved changes are abandoned.
|
|
49
|
+
*/
|
|
50
|
+
closeDb(saveChanges) {
|
|
51
|
+
if (saveChanges && this.isOpen)
|
|
52
|
+
this.saveChanges();
|
|
53
|
+
this._sqliteStatementCache.clear();
|
|
54
|
+
this.nativeDb.closeDb();
|
|
55
|
+
}
|
|
56
|
+
/** Returns true if this SQLiteDb is open */
|
|
57
|
+
get isOpen() { return this.nativeDb.isOpen(); }
|
|
58
|
+
/** Returns true if this SQLiteDb is open readonly */
|
|
59
|
+
get isReadonly() { return this.nativeDb.isReadonly(); }
|
|
60
|
+
/** Create a new table in this database. */
|
|
61
|
+
createTable(args) {
|
|
62
|
+
const timestampCol = args.addTimestamp ? ",lastMod TIMESTAMP NOT NULL DEFAULT(julianday('now'))" : "";
|
|
63
|
+
const constraints = args.constraints ? `,${args.constraints}` : "";
|
|
64
|
+
this.executeSQL(`CREATE TABLE ${args.tableName}(${args.columns}${timestampCol}${constraints})`);
|
|
65
|
+
if (args.addTimestamp)
|
|
66
|
+
this.executeSQL(`CREATE TRIGGER ${args.tableName}_timestamp AFTER UPDATE ON ${args.tableName} WHEN old.lastMod=new.lastMod AND old.lastMod != julianday('now') BEGIN UPDATE ${args.tableName} SET lastMod=julianday('now') WHERE rowid=new.rowid; END`);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get the last modified date for a row in a table of this database.
|
|
70
|
+
* @note the table must have been created with `addTimestamp: true`
|
|
71
|
+
*/
|
|
72
|
+
readLastModTime(tableName, rowId) {
|
|
73
|
+
return this.withSqliteStatement(`SELECT lastMod from ${tableName} WHERE rowid=?`, (stmt) => {
|
|
74
|
+
stmt.bindInteger(1, rowId);
|
|
75
|
+
return stmt.getValueDate(0);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Open a database, perform an operation, then close the database.
|
|
80
|
+
*
|
|
81
|
+
* Details:
|
|
82
|
+
* - if database is open, throw an error
|
|
83
|
+
* - open a database
|
|
84
|
+
* - call a function with the database opened. If it is async, await its return.
|
|
85
|
+
* - if function throws, abandon all changes, close database, and rethrow
|
|
86
|
+
* - save all changes
|
|
87
|
+
* - close the database
|
|
88
|
+
* @return value from operation
|
|
89
|
+
*/
|
|
90
|
+
withOpenDb(args, operation) {
|
|
91
|
+
if (this.isOpen)
|
|
92
|
+
throw new Error("database is already open");
|
|
93
|
+
const save = () => this.closeDb(true), abandon = () => this.closeDb(false);
|
|
94
|
+
this.openDb(args.dbName, args.openMode ?? core_bentley_1.OpenMode.Readonly, args.container);
|
|
95
|
+
try {
|
|
96
|
+
const result = operation();
|
|
97
|
+
result instanceof Promise ? result.then(save, abandon) : save();
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
catch (e) {
|
|
101
|
+
abandon();
|
|
102
|
+
throw e;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Perform an operation on a database in a CloudContainer with the write lock held.
|
|
107
|
+
*
|
|
108
|
+
* Details:
|
|
109
|
+
* - acquire the write lock on a CloudContainer
|
|
110
|
+
* - call `withOpenDb` with openMode `ReadWrite`
|
|
111
|
+
* - upload changes
|
|
112
|
+
* - release the write lock
|
|
113
|
+
* @param args arguments to lock the container and open the database
|
|
114
|
+
* @param operation an operation performed on the database with the write lock held.
|
|
115
|
+
* @return value from operation
|
|
116
|
+
* @internal
|
|
117
|
+
*/
|
|
118
|
+
async withLockedContainer(args, operation) {
|
|
119
|
+
return CloudSqlite_1.CloudSqlite.withWriteLock(args.moniker, args.container, async () => this.withOpenDb({ ...args, openMode: core_bentley_1.OpenMode.ReadWrite }, operation), args.busyHandler);
|
|
120
|
+
}
|
|
121
|
+
/** vacuum this database
|
|
122
|
+
* @see https://www.sqlite.org/lang_vacuum.html
|
|
123
|
+
*/
|
|
124
|
+
vacuum(args) {
|
|
125
|
+
this.nativeDb.vacuum(args);
|
|
126
|
+
}
|
|
127
|
+
/** Commit the outermost transaction, writing changes to the file. Then, restart the default transaction. */
|
|
128
|
+
saveChanges() {
|
|
129
|
+
this.nativeDb.saveChanges();
|
|
130
|
+
}
|
|
131
|
+
/** Abandon (cancel) the outermost transaction, discarding all changes since last save. Then, restart the default transaction. */
|
|
132
|
+
abandonChanges() {
|
|
133
|
+
this.nativeDb.abandonChanges();
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Use a prepared SQL statement, potentially from the statement cache. If the requested statement doesn't exist
|
|
137
|
+
* in the statement cache, a new statement is prepared. After the callback completes, the statement is reset and saved
|
|
138
|
+
* in the statement cache so it can be reused in the future. Use this method for SQL statements that will be
|
|
139
|
+
* reused often and are expensive to prepare. The statement cache holds the most recently used statements, discarding
|
|
140
|
+
* the oldest statements as it fills. For statements you don't intend to reuse, instead use [[withSqliteStatement]].
|
|
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
|
+
withPreparedSqliteStatement(sql, callback) {
|
|
146
|
+
const stmt = this._sqliteStatementCache.findAndRemove(sql) ?? this.prepareSqliteStatement(sql);
|
|
147
|
+
const release = () => this._sqliteStatementCache.addOrDispose(stmt);
|
|
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
|
+
* Prepare and execute a callback on a SQL statement. After the callback completes the statement is disposed.
|
|
160
|
+
* Use this method for SQL statements are either not expected to be reused, or are not expensive to prepare.
|
|
161
|
+
* For statements that will be reused often, instead use [[withPreparedSqliteStatement]].
|
|
162
|
+
* @param sql The SQLite SQL statement to execute
|
|
163
|
+
* @param callback the callback to invoke on the prepared statement
|
|
164
|
+
* @returns the value returned by `callback`.
|
|
165
|
+
*/
|
|
166
|
+
withSqliteStatement(sql, callback) {
|
|
167
|
+
const stmt = this.prepareSqliteStatement(sql);
|
|
168
|
+
const release = () => stmt.dispose();
|
|
169
|
+
try {
|
|
170
|
+
const val = callback(stmt);
|
|
171
|
+
val instanceof Promise ? val.then(release, release) : release();
|
|
172
|
+
return val;
|
|
173
|
+
}
|
|
174
|
+
catch (err) {
|
|
175
|
+
release();
|
|
176
|
+
throw err;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Perform an operation on this database within a [savepoint](https://www.sqlite.org/lang_savepoint.html). If the operation completes successfully, the
|
|
181
|
+
* changes remain in the current transaction. If the operation throws an exception, the savepoint is rolled back
|
|
182
|
+
* and all changes to the database from this method are reversed, leaving the transaction exactly as it was before this method.
|
|
183
|
+
*/
|
|
184
|
+
withSavePoint(savePointName, operation) {
|
|
185
|
+
if (this.isReadonly)
|
|
186
|
+
throw new Error("database is readonly");
|
|
187
|
+
this.executeSQL(`SAVEPOINT ${savePointName}`);
|
|
188
|
+
try {
|
|
189
|
+
operation();
|
|
190
|
+
this.executeSQL(`RELEASE ${savePointName}`);
|
|
191
|
+
}
|
|
192
|
+
catch (e) {
|
|
193
|
+
this.executeSQL(`ROLLBACK TO ${savePointName}`);
|
|
194
|
+
throw e;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/** Prepare an SQL statement.
|
|
198
|
+
* @param sql The SQLite SQL statement to prepare
|
|
199
|
+
* @param logErrors Determine if errors are logged or not
|
|
200
|
+
* @internal
|
|
201
|
+
*/
|
|
202
|
+
prepareSqliteStatement(sql, logErrors = true) {
|
|
203
|
+
const stmt = new SqliteStatement_1.SqliteStatement(sql);
|
|
204
|
+
stmt.prepare(this.nativeDb, logErrors);
|
|
205
|
+
return stmt;
|
|
206
|
+
}
|
|
207
|
+
/** execute an SQL statement */
|
|
208
|
+
executeSQL(sql) {
|
|
209
|
+
const stmt = this.prepareSqliteStatement(sql);
|
|
210
|
+
try {
|
|
211
|
+
return stmt.step();
|
|
212
|
+
}
|
|
213
|
+
finally {
|
|
214
|
+
stmt.dispose();
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
exports.SQLiteDb = SQLiteDb;
|
|
219
|
+
/**
|
|
220
|
+
* Abstract base class for a SQLite database that has [[SQLiteDb.RequiredVersionRanges]] stored in it.
|
|
221
|
+
* This class provides version checking when the database is opened, to guarantee that a valid version of software is
|
|
222
|
+
* always used for access.
|
|
223
|
+
*
|
|
224
|
+
* Notes:
|
|
225
|
+
* - This class may be used either to access a local file, or one stored in a cloud container.
|
|
226
|
+
* - Subclasses must provide a `myVersion` member indicating the version of its software, and implement the `createDDL` member to create its
|
|
227
|
+
* tables.
|
|
228
|
+
* @beta
|
|
229
|
+
*/
|
|
230
|
+
class VersionedSqliteDb extends SQLiteDb {
|
|
231
|
+
/**
|
|
232
|
+
* Change the "versions required to open this database" property stored in this database. After this call,
|
|
233
|
+
* versions of software that don't meet the supplied ranges will fail.
|
|
234
|
+
* @param versions the new versions required for reading and writing this database.
|
|
235
|
+
* @note the database must be opened for write access.
|
|
236
|
+
*/
|
|
237
|
+
setRequiredVersions(versions) {
|
|
238
|
+
// NOTE: It might look tempting to just stringify the supplied `versions` object, but we only include required members - there may be others.
|
|
239
|
+
this.nativeDb.saveFileProperty(VersionedSqliteDb._versionProps, JSON.stringify({ readVersion: versions.readVersion, writeVersion: versions.writeVersion }));
|
|
240
|
+
}
|
|
241
|
+
/** Get the required version ranges necessary to open this VersionedSqliteDb. */
|
|
242
|
+
getRequiredVersions() {
|
|
243
|
+
const checkIsString = (value) => {
|
|
244
|
+
if (typeof value !== "string")
|
|
245
|
+
throw new Error(`CloudDb ${this.nativeDb.getFilePath()} has invalid "versions" property`);
|
|
246
|
+
return value;
|
|
247
|
+
};
|
|
248
|
+
const versionJson = checkIsString(this.nativeDb.queryFileProperty(VersionedSqliteDb._versionProps, true));
|
|
249
|
+
const versionRanges = JSON.parse(versionJson);
|
|
250
|
+
checkIsString(versionRanges.readVersion);
|
|
251
|
+
checkIsString(versionRanges.writeVersion);
|
|
252
|
+
return versionRanges;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Create a new database file for the subclass of VersionedSqliteDb.
|
|
256
|
+
* @param fileName the name of a local
|
|
257
|
+
* @note The required versions are saved as [[myVersion]] or newer for both read and write.
|
|
258
|
+
*/
|
|
259
|
+
static createNewDb(fileName) {
|
|
260
|
+
const db = new this(); // "as any" necessary because VersionedSqliteDb is abstract
|
|
261
|
+
IModelJsFs_1.IModelJsFs.recursiveMkDirSync((0, path_1.dirname)(fileName));
|
|
262
|
+
if (fs.existsSync(fileName))
|
|
263
|
+
fs.unlinkSync(fileName);
|
|
264
|
+
db.createDb(fileName);
|
|
265
|
+
db.createDDL();
|
|
266
|
+
const minVer = `^${db.myVersion}`;
|
|
267
|
+
db.setRequiredVersions({ readVersion: minVer, writeVersion: minVer });
|
|
268
|
+
db.closeDb(true);
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Verify that this version of the software meets the required version range (as appropriate, read or write) stored in the database.
|
|
272
|
+
* Throws otherwise.
|
|
273
|
+
*/
|
|
274
|
+
verifyVersions() {
|
|
275
|
+
const versions = this.getRequiredVersions();
|
|
276
|
+
const isReadonly = this.isReadonly; // so we can tell read/write after the file is closed.
|
|
277
|
+
const range = isReadonly ? versions.readVersion : versions.writeVersion;
|
|
278
|
+
if (semver.satisfies(this.myVersion, range))
|
|
279
|
+
return;
|
|
280
|
+
this.closeDb();
|
|
281
|
+
const tooNew = semver.gtr(this.myVersion, range);
|
|
282
|
+
throw new Error(`${this.nativeDb.getFilePath()} requires ${tooNew ? "older" : "newer"} version of ${this.constructor.name} for ${isReadonly ? "read" : "write"}`);
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Open this database and verify that this version of the software meets the required version range (as appropriate, read or write) stored in the database.
|
|
286
|
+
* Throws otherwise.
|
|
287
|
+
* @see [[SqliteDb.openDb]] for argument types
|
|
288
|
+
*/
|
|
289
|
+
openDb(dbName, openMode, container) {
|
|
290
|
+
super.openDb(dbName, openMode, container);
|
|
291
|
+
this.verifyVersions();
|
|
292
|
+
}
|
|
293
|
+
async upgradeSchema(arg) {
|
|
294
|
+
// can't use "this" because it checks for version, which we don't want here
|
|
295
|
+
return (arg.lockContainer) ?
|
|
296
|
+
super.withLockedContainer({ dbName: arg.dbName, ...arg.lockContainer }, async () => arg.upgradeFn) :
|
|
297
|
+
super.withOpenDb({ ...arg, openMode: core_bentley_1.OpenMode.ReadWrite }, arg.upgradeFn);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
VersionedSqliteDb._versionProps = { namespace: "SQLiteDb", name: "versions" };
|
|
301
|
+
exports.VersionedSqliteDb = VersionedSqliteDb;
|
|
302
|
+
/** @public */
|
|
303
|
+
(function (SQLiteDb) {
|
|
304
|
+
/** Default transaction mode for SQLiteDbs.
|
|
305
|
+
* @see https://www.sqlite.org/lang_transaction.html
|
|
306
|
+
*/
|
|
307
|
+
let DefaultTxnMode;
|
|
308
|
+
(function (DefaultTxnMode) {
|
|
309
|
+
/** no default transaction is started. You must use BEGIN/COMMIT or SQLite will use implicit transactions */
|
|
310
|
+
DefaultTxnMode[DefaultTxnMode["None"] = 0] = "None";
|
|
311
|
+
/** A deferred transaction is started when the file is first opened. This is the default. */
|
|
312
|
+
DefaultTxnMode[DefaultTxnMode["Deferred"] = 1] = "Deferred";
|
|
313
|
+
/** An immediate transaction is started when the file is first opened. */
|
|
314
|
+
DefaultTxnMode[DefaultTxnMode["Immediate"] = 2] = "Immediate";
|
|
315
|
+
/** An exclusive transaction is started when the file is first opened. */
|
|
316
|
+
DefaultTxnMode[DefaultTxnMode["Exclusive"] = 3] = "Exclusive";
|
|
317
|
+
})(DefaultTxnMode = SQLiteDb.DefaultTxnMode || (SQLiteDb.DefaultTxnMode = {}));
|
|
318
|
+
})(SQLiteDb = exports.SQLiteDb || (exports.SQLiteDb = {}));
|
|
215
319
|
//# sourceMappingURL=SQLiteDb.js.map
|