@itwin/core-backend 3.4.0-dev.9 → 3.5.0-dev.11
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 +41 -1
- package/lib/cjs/AliCloudStorageService.d.ts +8 -2
- package/lib/cjs/AliCloudStorageService.d.ts.map +1 -1
- package/lib/cjs/AliCloudStorageService.js +4 -1
- package/lib/cjs/AliCloudStorageService.js.map +1 -1
- package/lib/cjs/BackendHubAccess.d.ts.map +1 -1
- package/lib/cjs/BackendHubAccess.js.map +1 -1
- package/lib/cjs/BackendLoggerCategory.d.ts +9 -5
- package/lib/cjs/BackendLoggerCategory.d.ts.map +1 -1
- package/lib/cjs/BackendLoggerCategory.js +9 -5
- package/lib/cjs/BackendLoggerCategory.js.map +1 -1
- package/lib/cjs/ChangedElementsDb.d.ts +1 -0
- package/lib/cjs/ChangedElementsDb.d.ts.map +1 -1
- package/lib/cjs/ChangedElementsDb.js +2 -2
- package/lib/cjs/ChangedElementsDb.js.map +1 -1
- package/lib/cjs/CheckpointManager.d.ts +2 -4
- package/lib/cjs/CheckpointManager.d.ts.map +1 -1
- package/lib/cjs/CheckpointManager.js +8 -19
- package/lib/cjs/CheckpointManager.js.map +1 -1
- package/lib/cjs/ClassRegistry.d.ts.map +1 -1
- package/lib/cjs/ClassRegistry.js +3 -1
- package/lib/cjs/ClassRegistry.js.map +1 -1
- package/lib/cjs/CloudSqlite.d.ts +350 -0
- package/lib/cjs/CloudSqlite.d.ts.map +1 -0
- package/lib/cjs/CloudSqlite.js +152 -0
- package/lib/cjs/CloudSqlite.js.map +1 -0
- package/lib/cjs/CloudStorageBackend.d.ts +16 -4
- package/lib/cjs/CloudStorageBackend.d.ts.map +1 -1
- package/lib/cjs/CloudStorageBackend.js +12 -3
- package/lib/cjs/CloudStorageBackend.js.map +1 -1
- package/lib/cjs/CodeService.d.ts +397 -0
- package/lib/cjs/CodeService.d.ts.map +1 -0
- package/lib/cjs/CodeService.js +64 -0
- package/lib/cjs/CodeService.js.map +1 -0
- package/lib/cjs/CodeSpecs.js.map +1 -1
- package/lib/cjs/CustomViewState3dCreator.d.ts.map +1 -1
- package/lib/cjs/CustomViewState3dCreator.js +15 -0
- package/lib/cjs/CustomViewState3dCreator.js.map +1 -1
- package/lib/cjs/DevTools.d.ts.map +1 -1
- package/lib/cjs/DevTools.js.map +1 -1
- package/lib/cjs/Element.d.ts.map +1 -1
- package/lib/cjs/Element.js +20 -17
- package/lib/cjs/Element.js.map +1 -1
- package/lib/cjs/ElementTreeWalker.d.ts.map +1 -1
- package/lib/cjs/ElementTreeWalker.js.map +1 -1
- package/lib/cjs/ExportGraphics.d.ts +9 -9
- package/lib/cjs/ExportGraphics.d.ts.map +1 -1
- package/lib/cjs/ExportGraphics.js.map +1 -1
- package/lib/cjs/ExternalSource.d.ts.map +1 -1
- package/lib/cjs/ExternalSource.js.map +1 -1
- package/lib/cjs/GeoCoordConfig.d.ts +7 -1
- package/lib/cjs/GeoCoordConfig.d.ts.map +1 -1
- package/lib/cjs/GeoCoordConfig.js +16 -7
- package/lib/cjs/GeoCoordConfig.js.map +1 -1
- package/lib/cjs/GeometrySummary.js +1 -1
- package/lib/cjs/GeometrySummary.js.map +1 -1
- package/lib/cjs/HubMock.d.ts.map +1 -1
- package/lib/cjs/HubMock.js +7 -7
- package/lib/cjs/HubMock.js.map +1 -1
- package/lib/cjs/IModelDb.d.ts +18 -5
- package/lib/cjs/IModelDb.d.ts.map +1 -1
- package/lib/cjs/IModelDb.js +63 -25
- package/lib/cjs/IModelDb.js.map +1 -1
- package/lib/cjs/IModelHost.d.ts +20 -6
- package/lib/cjs/IModelHost.d.ts.map +1 -1
- package/lib/cjs/IModelHost.js +56 -22
- package/lib/cjs/IModelHost.js.map +1 -1
- package/lib/cjs/IModelJsFs.d.ts +1 -1
- package/lib/cjs/IModelJsFs.d.ts.map +1 -1
- package/lib/cjs/IModelJsFs.js +2 -2
- package/lib/cjs/IModelJsFs.js.map +1 -1
- package/lib/cjs/LocalHub.js +1 -1
- package/lib/cjs/LocalHub.js.map +1 -1
- package/lib/cjs/Material.d.ts +3 -1
- package/lib/cjs/Material.d.ts.map +1 -1
- package/lib/cjs/Material.js +3 -1
- package/lib/cjs/Material.js.map +1 -1
- package/lib/cjs/Model.d.ts.map +1 -1
- package/lib/cjs/Model.js +5 -2
- package/lib/cjs/Model.js.map +1 -1
- package/lib/cjs/PromiseMemoizer.d.ts.map +1 -1
- package/lib/cjs/PromiseMemoizer.js +10 -4
- package/lib/cjs/PromiseMemoizer.js.map +1 -1
- package/lib/cjs/PropertyStore.d.ts +133 -0
- package/lib/cjs/PropertyStore.d.ts.map +1 -0
- package/lib/cjs/PropertyStore.js +12 -0
- package/lib/cjs/PropertyStore.js.map +1 -0
- package/lib/cjs/SQLiteDb.d.ts +110 -64
- package/lib/cjs/SQLiteDb.d.ts.map +1 -1
- package/lib/cjs/SQLiteDb.js +61 -58
- package/lib/cjs/SQLiteDb.js.map +1 -1
- package/lib/cjs/SqliteStatement.d.ts +14 -2
- package/lib/cjs/SqliteStatement.d.ts.map +1 -1
- package/lib/cjs/SqliteStatement.js +50 -28
- package/lib/cjs/SqliteStatement.js.map +1 -1
- package/lib/cjs/TileStorage.d.ts +19 -0
- package/lib/cjs/TileStorage.d.ts.map +1 -0
- package/lib/cjs/TileStorage.js +91 -0
- package/lib/cjs/TileStorage.js.map +1 -0
- package/lib/cjs/TxnManager.d.ts.map +1 -1
- package/lib/cjs/TxnManager.js +5 -2
- package/lib/cjs/TxnManager.js.map +1 -1
- package/lib/cjs/ViewDefinition.d.ts.map +1 -1
- package/lib/cjs/ViewDefinition.js +8 -2
- package/lib/cjs/ViewDefinition.js.map +1 -1
- package/lib/cjs/assets/Settings/Schemas/Gcs.schema.json +10 -0
- package/lib/cjs/assets/Settings/backend.setting.json5 +1 -1
- package/lib/cjs/core-backend.d.ts +9 -2
- package/lib/cjs/core-backend.d.ts.map +1 -1
- package/lib/cjs/core-backend.js +10 -3
- package/lib/cjs/core-backend.js.map +1 -1
- package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts +2 -0
- package/lib/cjs/rpc-impl/IModelTileRpcImpl.d.ts.map +1 -1
- package/lib/cjs/rpc-impl/IModelTileRpcImpl.js +11 -2
- package/lib/cjs/rpc-impl/IModelTileRpcImpl.js.map +1 -1
- package/lib/cjs/rpc-impl/RpcBriefcaseUtility.d.ts.map +1 -1
- package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js +3 -0
- package/lib/cjs/rpc-impl/RpcBriefcaseUtility.js.map +1 -1
- package/lib/cjs/workspace/Settings.d.ts.map +1 -1
- package/lib/cjs/workspace/Settings.js +4 -1
- package/lib/cjs/workspace/Settings.js.map +1 -1
- package/lib/cjs/workspace/Workspace.d.ts +31 -18
- package/lib/cjs/workspace/Workspace.d.ts.map +1 -1
- package/lib/cjs/workspace/Workspace.js +34 -25
- package/lib/cjs/workspace/Workspace.js.map +1 -1
- package/package.json +18 -19
- package/lib/cjs/IModelSchemaLoader.d.ts +0 -26
- package/lib/cjs/IModelSchemaLoader.d.ts.map +0 -1
- package/lib/cjs/IModelSchemaLoader.js +0 -122
- package/lib/cjs/IModelSchemaLoader.js.map +0 -1
package/lib/cjs/SQLiteDb.js
CHANGED
|
@@ -8,10 +8,11 @@
|
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.SQLiteDb = void 0;
|
|
11
|
-
const imodeljs_native_1 = require("@bentley/imodeljs-native");
|
|
12
11
|
const core_bentley_1 = require("@itwin/core-bentley");
|
|
12
|
+
const CloudSqlite_1 = require("./CloudSqlite");
|
|
13
13
|
const IModelHost_1 = require("./IModelHost");
|
|
14
14
|
const SqliteStatement_1 = require("./SqliteStatement");
|
|
15
|
+
// cspell:ignore savepoint
|
|
15
16
|
/* eslint-disable @typescript-eslint/unified-signatures */
|
|
16
17
|
/** A SQLiteDb file
|
|
17
18
|
* @public
|
|
@@ -23,18 +24,6 @@ class SQLiteDb {
|
|
|
23
24
|
this._sqliteStatementCache = new SqliteStatement_1.StatementCache();
|
|
24
25
|
}
|
|
25
26
|
/** @internal */
|
|
26
|
-
static createCloudContainer(args) {
|
|
27
|
-
return new IModelHost_1.IModelHost.platform.CloudContainer(args);
|
|
28
|
-
}
|
|
29
|
-
/** @internal */
|
|
30
|
-
static createCloudCache(args) {
|
|
31
|
-
return new IModelHost_1.IModelHost.platform.CloudCache(args);
|
|
32
|
-
}
|
|
33
|
-
/** @internal */
|
|
34
|
-
static startCloudPrefetch(container, dbName, args) {
|
|
35
|
-
return new IModelHost_1.IModelHost.platform.CloudPrefetch(container, dbName, args);
|
|
36
|
-
}
|
|
37
|
-
/** @internal */
|
|
38
27
|
static createBlobIO() {
|
|
39
28
|
return new IModelHost_1.IModelHost.platform.BlobIO();
|
|
40
29
|
}
|
|
@@ -42,9 +31,7 @@ class SQLiteDb {
|
|
|
42
31
|
dispose() {
|
|
43
32
|
this.closeDb();
|
|
44
33
|
}
|
|
45
|
-
/**
|
|
46
|
-
* @param dbName The path to the SQLiteDb file to create.
|
|
47
|
-
*/
|
|
34
|
+
/** @internal */
|
|
48
35
|
createDb(dbName, container, params) {
|
|
49
36
|
this.nativeDb.createDb(dbName, container, params);
|
|
50
37
|
}
|
|
@@ -53,7 +40,7 @@ class SQLiteDb {
|
|
|
53
40
|
this.nativeDb.openDb(dbName, openMode, container);
|
|
54
41
|
}
|
|
55
42
|
/** Close SQLiteDb.
|
|
56
|
-
* @param saveChanges if true, call `saveChanges` before closing db.
|
|
43
|
+
* @param saveChanges if true, call `saveChanges` before closing db. Otherwise unsaved changes are abandoned.
|
|
57
44
|
*/
|
|
58
45
|
closeDb(saveChanges) {
|
|
59
46
|
if (saveChanges && this.isOpen)
|
|
@@ -61,45 +48,53 @@ class SQLiteDb {
|
|
|
61
48
|
this._sqliteStatementCache.clear();
|
|
62
49
|
this.nativeDb.closeDb();
|
|
63
50
|
}
|
|
64
|
-
/** Returns true if
|
|
51
|
+
/** Returns true if this SQLiteDb is open */
|
|
65
52
|
get isOpen() { return this.nativeDb.isOpen(); }
|
|
53
|
+
/** Returns true if this SQLiteDb is open readonly */
|
|
54
|
+
get isReadonly() { return this.nativeDb.isReadonly(); }
|
|
66
55
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
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
|
|
70
66
|
*/
|
|
71
|
-
|
|
67
|
+
withOpenDb(args, operation) {
|
|
72
68
|
var _a;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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);
|
|
76
73
|
try {
|
|
77
|
-
const result = operation(
|
|
78
|
-
|
|
79
|
-
fromPromise = true;
|
|
80
|
-
const doClose = () => db.closeDb();
|
|
81
|
-
result.then(doClose, doClose);
|
|
82
|
-
}
|
|
74
|
+
const result = operation();
|
|
75
|
+
result instanceof Promise ? result.then(save, abandon) : save();
|
|
83
76
|
return result;
|
|
84
77
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
78
|
+
catch (e) {
|
|
79
|
+
abandon();
|
|
80
|
+
throw e;
|
|
88
81
|
}
|
|
89
82
|
}
|
|
90
83
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
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
|
|
96
94
|
* @internal
|
|
97
95
|
*/
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
operation) {
|
|
101
|
-
const fn = async () => SQLiteDb.withOpenDb({ ...args, openMode: core_bentley_1.OpenMode.ReadWrite }, operation);
|
|
102
|
-
await imodeljs_native_1.CloudSqlite.withWriteLock(args.user, args.container, fn, args.busyHandler);
|
|
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);
|
|
103
98
|
}
|
|
104
99
|
/** vacuum this database
|
|
105
100
|
* @see https://www.sqlite.org/lang_vacuum.html
|
|
@@ -131,12 +126,7 @@ class SQLiteDb {
|
|
|
131
126
|
const release = () => this._sqliteStatementCache.addOrDispose(stmt);
|
|
132
127
|
try {
|
|
133
128
|
const val = callback(stmt);
|
|
134
|
-
|
|
135
|
-
val.then(release, release);
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
release();
|
|
139
|
-
}
|
|
129
|
+
val instanceof Promise ? val.then(release, release) : release();
|
|
140
130
|
return val;
|
|
141
131
|
}
|
|
142
132
|
catch (err) {
|
|
@@ -157,12 +147,7 @@ class SQLiteDb {
|
|
|
157
147
|
const release = () => stmt.dispose();
|
|
158
148
|
try {
|
|
159
149
|
const val = callback(stmt);
|
|
160
|
-
|
|
161
|
-
val.then(release, release);
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
release();
|
|
165
|
-
}
|
|
150
|
+
val instanceof Promise ? val.then(release, release) : release();
|
|
166
151
|
return val;
|
|
167
152
|
}
|
|
168
153
|
catch (err) {
|
|
@@ -170,6 +155,24 @@ class SQLiteDb {
|
|
|
170
155
|
throw err;
|
|
171
156
|
}
|
|
172
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
|
+
}
|
|
173
176
|
/** Prepare an SQL statement.
|
|
174
177
|
* @param sql The SQLite SQL statement to prepare
|
|
175
178
|
* @param logErrors Determine if errors are logged or not
|
|
@@ -195,8 +198,8 @@ exports.SQLiteDb = SQLiteDb;
|
|
|
195
198
|
/** @public */
|
|
196
199
|
(function (SQLiteDb) {
|
|
197
200
|
/** Default transaction mode for SQLiteDbs.
|
|
198
|
-
|
|
199
|
-
|
|
201
|
+
* @see https://www.sqlite.org/lang_transaction.html
|
|
202
|
+
*/
|
|
200
203
|
let DefaultTxnMode;
|
|
201
204
|
(function (DefaultTxnMode) {
|
|
202
205
|
/** no default transaction is started. You must use BEGIN/COMMIT or SQLite will use implicit transactions */
|
package/lib/cjs/SQLiteDb.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SQLiteDb.js","sour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AR,gBAAQ,KAAR,gBAAQ,QAwDxB","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module SQLiteDb\r\n */\r\n\r\nimport { CloudSqlite, IModelJsNative } from \"@bentley/imodeljs-native\";\r\nimport { DbResult, IDisposable, OpenMode } from \"@itwin/core-bentley\";\r\nimport { LocalFileName } from \"@itwin/core-common\";\r\nimport { IModelHost } from \"./IModelHost\";\r\nimport { SqliteStatement, StatementCache } from \"./SqliteStatement\";\r\n\r\n/* eslint-disable @typescript-eslint/unified-signatures */\r\n\r\n/** A SQLiteDb file\r\n * @public\r\n */\r\nexport class SQLiteDb implements IDisposable {\r\n /** @internal */\r\n public readonly nativeDb = new IModelHost.platform.SQLiteDb();\r\n private _sqliteStatementCache = new StatementCache<SqliteStatement>();\r\n\r\n /** @internal */\r\n public static createCloudContainer(args: CloudSqlite.ContainerAccessProps): SQLiteDb.CloudContainer {\r\n return new IModelHost.platform.CloudContainer(args);\r\n }\r\n /** @internal */\r\n public static createCloudCache(args: CloudSqlite.CacheProps): SQLiteDb.CloudCache {\r\n return new IModelHost.platform.CloudCache(args);\r\n }\r\n /** @internal */\r\n public static startCloudPrefetch(container: SQLiteDb.CloudContainer, dbName: string, args?: CloudSqlite.PrefetchProps): SQLiteDb.CloudPrefetch {\r\n return new IModelHost.platform.CloudPrefetch(container, dbName, args);\r\n }\r\n /** @internal */\r\n public static createBlobIO(): SQLiteDb.BlobIO {\r\n return new IModelHost.platform.BlobIO();\r\n }\r\n\r\n /** alias for closeDb. */\r\n public dispose(): void {\r\n this.closeDb();\r\n }\r\n\r\n /** Create a SQLiteDb\r\n * @param dbName The path to the SQLiteDb file to create.\r\n */\r\n public createDb(dbName: string, container?: SQLiteDb.CloudContainer, params?: SQLiteDb.CreateParams): void {\r\n this.nativeDb.createDb(dbName, container, params);\r\n }\r\n\r\n /** Open a SQLiteDb.\r\n * @param dbName The path to the SQLiteDb file to open\r\n */\r\n public openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams): void;\r\n /**\r\n * @param container optional CloudContainer holding database\r\n * @internal\r\n */\r\n public openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams, container?: SQLiteDb.CloudContainer): void;\r\n\r\n /** @internal */\r\n public openDb(dbName: string, openMode: OpenMode | SQLiteDb.OpenParams, container?: SQLiteDb.CloudContainer): void {\r\n this.nativeDb.openDb(dbName, openMode, container);\r\n }\r\n\r\n /** Close SQLiteDb.\r\n * @param saveChanges if true, call `saveChanges` before closing db.\r\n */\r\n public closeDb(saveChanges?: boolean): void {\r\n if (saveChanges && this.isOpen)\r\n this.saveChanges();\r\n this._sqliteStatementCache.clear();\r\n this.nativeDb.closeDb();\r\n }\r\n\r\n /** Returns true if the SQLiteDb is open */\r\n public get isOpen(): boolean { return this.nativeDb.isOpen(); }\r\n\r\n /**\r\n * 1. open a database\r\n * 2. call a function supplying the open SQliteDb as argument. If it is async, await its return.\r\n * 3. close the database (even if exceptions are thrown)\r\n */\r\n public static withOpenDb<T>(args: {\r\n /** The name of the database to open */\r\n dbName: string;\r\n /** either an object with the open parameters or just OpenMode value. */\r\n openMode?: OpenMode | SQLiteDb.OpenParams;\r\n /** @internal */\r\n container?: SQLiteDb.CloudContainer;\r\n }, operation: (db: SQLiteDb) => T): T {\r\n const db = new SQLiteDb();\r\n db.openDb(args.dbName, args.openMode ?? OpenMode.Readonly, args.container);\r\n let fromPromise = false;\r\n\r\n try {\r\n const result = operation(db);\r\n if (result instanceof Promise) {\r\n fromPromise = true;\r\n const doClose = () => db.closeDb();\r\n result.then(doClose, doClose);\r\n }\r\n return result;\r\n } finally {\r\n if (!fromPromise)\r\n db.closeDb();\r\n }\r\n }\r\n\r\n /**\r\n * 1. acquire the write lock on a CloudContainer\r\n * 2. open a ReadWrite database in the container\r\n * 3. call a function with the opened database as an argument\r\n * 4. close the database\r\n * 5. release the write lock and upload changes.\r\n * @internal\r\n */\r\n public static async withLockedContainer(\r\n args: {\r\n /** the name to be displayed in the event of lock collisions */\r\n user: string;\r\n /** the name of the database within the container */\r\n dbName: string;\r\n /** the CloudContainer on which the operation will be performed */\r\n container: SQLiteDb.CloudContainer;\r\n /** if present, function called when the write lock is currently held by another user. */\r\n busyHandler?: CloudSqlite.WriteLockBusyHandler;\r\n },\r\n /** an asynchronous operation performed on the database with the write lock held. */\r\n operation: (db: SQLiteDb) => Promise<void>) {\r\n const fn = async () => SQLiteDb.withOpenDb({ ...args, openMode: OpenMode.ReadWrite }, operation);\r\n await CloudSqlite.withWriteLock(args.user, args.container, fn, args.busyHandler);\r\n }\r\n\r\n /** vacuum this database\r\n * @see https://www.sqlite.org/lang_vacuum.html\r\n */\r\n public vacuum(args?: {\r\n /** new page size\r\n * @see https://www.sqlite.org/pragma.html#pragma_page_size\r\n */\r\n pageSize?: number;\r\n /** if present, name of new file to vacuum into */\r\n into?: LocalFileName;\r\n }) {\r\n this.nativeDb.vacuum(args);\r\n }\r\n\r\n /** Commit the outermost transaction, writing changes to the file. Then, restart the transaction. */\r\n public saveChanges(): void {\r\n this.nativeDb.saveChanges();\r\n }\r\n\r\n /** Abandon (cancel) the outermost transaction, discarding all changes since last save. Then, restart the transaction. */\r\n public abandonChanges(): void {\r\n this.nativeDb.abandonChanges();\r\n }\r\n\r\n /**\r\n * Use a prepared SQL statement, potentially from the statement cache. If the requested statement doesn't exist\r\n * in the statement cache, a new statement is prepared. After the callback completes, the statement is reset and saved\r\n * in the statement cache so it can be reused in the future. Use this method for SQL statements that will be\r\n * reused often and are expensive to prepare. The statement cache holds the most recently used statements, discarding\r\n * the oldest statements as it fills. For statements you don't intend to reuse, instead use [[withSqliteStatement]].\r\n * @param sql The SQLite SQL statement to execute\r\n * @param callback the callback to invoke on the prepared statement\r\n * @returns the value returned by `callback`.\r\n */\r\n public withPreparedSqliteStatement<T>(sql: string, callback: (stmt: SqliteStatement) => T): T {\r\n const stmt = this._sqliteStatementCache.findAndRemove(sql) ?? this.prepareSqliteStatement(sql);\r\n const release = () => this._sqliteStatementCache.addOrDispose(stmt);\r\n try {\r\n const val: T = callback(stmt);\r\n if (val instanceof Promise) {\r\n val.then(release, release);\r\n } else {\r\n release();\r\n }\r\n return val;\r\n } catch (err) {\r\n release();\r\n throw err;\r\n }\r\n }\r\n\r\n /**\r\n * Prepared and execute a callback on a SQL statement. After the callback completes the statement is disposed.\r\n * Use this method for SQL statements are either not expected to be reused, or are not expensive to prepare.\r\n * For statements that will be reused often, instead use [[withPreparedSqliteStatement]].\r\n * @param sql The SQLite SQL statement to execute\r\n * @param callback the callback to invoke on the prepared statement\r\n * @returns the value returned by `callback`.\r\n */\r\n public withSqliteStatement<T>(sql: string, callback: (stmt: SqliteStatement) => T): T {\r\n const stmt = this.prepareSqliteStatement(sql);\r\n const release = () => stmt.dispose();\r\n try {\r\n const val: T = callback(stmt);\r\n if (val instanceof Promise) {\r\n val.then(release, release);\r\n } else {\r\n release();\r\n }\r\n return val;\r\n } catch (err) {\r\n release();\r\n throw err;\r\n }\r\n }\r\n\r\n /** Prepare an SQL statement.\r\n * @param sql The SQLite SQL statement to prepare\r\n * @param logErrors Determine if errors are logged or not\r\n * @internal\r\n */\r\n public prepareSqliteStatement(sql: string, logErrors = true): SqliteStatement {\r\n const stmt = new SqliteStatement(sql);\r\n stmt.prepare(this.nativeDb, logErrors);\r\n return stmt;\r\n }\r\n\r\n /** execute an SQL statement */\r\n public executeSQL(sql: string): DbResult {\r\n const stmt = this.prepareSqliteStatement(sql);\r\n try {\r\n return stmt.step();\r\n } finally {\r\n stmt.dispose();\r\n }\r\n }\r\n}\r\n\r\n/** @public */\r\nexport namespace SQLiteDb {\r\n /** A CloudSqlite container that may be connected to a CloudCache.\r\n * @internal\r\n */\r\n export type CloudContainer = IModelJsNative.CloudContainer;\r\n /** @internal */\r\n export type CloudCache = IModelJsNative.CloudCache;\r\n /** @internal */\r\n export type CloudPrefetch = IModelJsNative.CloudPrefetch;\r\n /** Incremental IO for blobs\r\n * @internal\r\n */\r\n export type BlobIO = IModelJsNative.BlobIO;\r\n\r\n /** Default transaction mode for SQLiteDbs.\r\n * @see https://www.sqlite.org/lang_transaction.html\r\n */\r\n export enum DefaultTxnMode {\r\n /** no default transaction is started. You must use BEGIN/COMMIT or SQLite will use implicit transactions */\r\n None = 0,\r\n /** A deferred transaction is started when the file is first opened. This is the default. */\r\n Deferred = 1,\r\n /** An immediate transaction is started when the file is first opened. */\r\n Immediate = 2,\r\n /** An exclusive transaction is started when the file is first opened. */\r\n Exclusive = 3\r\n }\r\n\r\n /** parameters common to opening or creating a new SQLiteDb */\r\n export interface OpenOrCreateParams {\r\n /** If true, do not require that the `be_Prop` table exist */\r\n rawSQLite?: boolean;\r\n /** @see immutable option at https://www.sqlite.org/c3ref/open.html */\r\n immutable?: boolean;\r\n /** Do not attempt to verify that the file is a valid sQLite file before opening. */\r\n skipFileCheck?: boolean;\r\n /** the default transaction mode\r\n * @see [[SQLiteDb.DefaultTxnMode]]\r\n */\r\n defaultTxn?: 0 | 1 | 2 | 3;\r\n /** see query parameters from 'URI Filenames' in https://www.sqlite.org/c3ref/open.html */\r\n queryParam?: string;\r\n }\r\n\r\n /** Parameters for opening an existing SQLiteDb */\r\n export interface OpenParams extends OpenOrCreateParams {\r\n /** use OpenMode.ReadWrite to open the file with write access */\r\n openMode: OpenMode;\r\n }\r\n\r\n /** Parameters for creating a new SQLiteDb */\r\n export interface CreateParams extends OpenOrCreateParams {\r\n /** see https://www.sqlite.org/pragma.html#pragma_page_size */\r\n pageSize?: number;\r\n }\r\n\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"SQLiteDb.js","sourceRoot":"","sources":["../../src/SQLiteDb.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAGH,sDAAsE;AAEtE,+CAA4C;AAC5C,6CAA0C;AAC1C,uDAAoE;AAEpE,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CAAC,UAAU;YACjB,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;QAE1C,IAAI,CAAC,UAAU,CAAC,aAAa,aAAa,EAAE,CAAC,CAAC;QAC9C,IAAI;YACF,SAAS,EAAE,CAAC;YACZ,IAAI,CAAC,UAAU,CAAC,WAAW,aAAa,EAAE,CAAC,CAAC;SAC7C;QAAC,OAAO,CAAC,EAAE;YACV,IAAI,CAAC,UAAU,CAAC,eAAe,aAAa,EAAE,CAAC,CAAC;YAChD,MAAM,CAAC,CAAC;SACT;IACH,CAAC;IAED;;;;SAIK;IACE,sBAAsB,CAAC,GAAW,EAAE,SAAS,GAAG,IAAI;QACzD,MAAM,IAAI,GAAG,IAAI,iCAAe,CAAC,GAAG,CAAC,CAAC;QACtC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;QACvC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,+BAA+B;IACxB,UAAU,CAAC,GAAW;QAC3B,MAAM,IAAI,GAAG,IAAI,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"]}
|
|
@@ -40,8 +40,9 @@ export declare type BindParameter = number | string;
|
|
|
40
40
|
export declare class SqliteStatement implements IterableIterator<any>, IDisposable {
|
|
41
41
|
private _sql;
|
|
42
42
|
private _stmt;
|
|
43
|
+
private _db;
|
|
43
44
|
constructor(_sql: string);
|
|
44
|
-
get stmt(): IModelJsNative.SqliteStatement
|
|
45
|
+
get stmt(): IModelJsNative.SqliteStatement;
|
|
45
46
|
get sql(): string;
|
|
46
47
|
/** Check if this statement has been prepared successfully or not */
|
|
47
48
|
get isPrepared(): boolean;
|
|
@@ -52,7 +53,7 @@ export declare class SqliteStatement implements IterableIterator<any>, IDisposab
|
|
|
52
53
|
* @throws if the SQL statement cannot be prepared. Normally, prepare fails due to SQL syntax errors or references to tables or properties that do not exist.
|
|
53
54
|
* The error.message property will provide details.
|
|
54
55
|
*/
|
|
55
|
-
prepare(db: IModelJsNative.
|
|
56
|
+
prepare(db: IModelJsNative.AnyDb, logErrors?: boolean): void;
|
|
56
57
|
/** Indicates whether the prepared statement makes no **direct* changes to the content of the file
|
|
57
58
|
* or not. See [SQLite docs](https://www.sqlite.org/c3ref/stmt_readonly.html) for details.
|
|
58
59
|
*/
|
|
@@ -62,6 +63,13 @@ export declare class SqliteStatement implements IterableIterator<any>, IDisposab
|
|
|
62
63
|
reset(): void;
|
|
63
64
|
/** Call this function when finished with this statement. This releases the native resources held by the statement. */
|
|
64
65
|
dispose(): void;
|
|
66
|
+
/**
|
|
67
|
+
* Call `step` on this statement and determine whether a new row is available.
|
|
68
|
+
* Use this method only when this statement has been prepared with a SELECT statement.
|
|
69
|
+
* @return true if a new row is available, false otherwise.
|
|
70
|
+
* @throws if `step` returns anything other than BE_SQLITE_ROW or BE_SQLITE_DONE.
|
|
71
|
+
*/
|
|
72
|
+
nextRow(): boolean;
|
|
65
73
|
/** Binds a value to the specified SQL parameter.
|
|
66
74
|
* The value must be of one of these types:
|
|
67
75
|
* JavaScript Type | SQLite Type
|
|
@@ -145,6 +153,10 @@ export declare class SqliteStatement implements IterableIterator<any>, IDisposab
|
|
|
145
153
|
* @param columnIx Index of SQL column in query result (0-based)
|
|
146
154
|
*/
|
|
147
155
|
getValue(columnIx: number): SqliteValue;
|
|
156
|
+
/** Determine whether the value of the specified column is null
|
|
157
|
+
* @param colIndex Index of SQL column in query result (0-based)
|
|
158
|
+
*/
|
|
159
|
+
isValueNull(colIndex: number): boolean;
|
|
148
160
|
/** Get a size in bytes of a blob or text column
|
|
149
161
|
* @param colIndex Index of SQL column in query result (0-based)
|
|
150
162
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SqliteStatement.d.ts","sourceRoot":"","sources":["../../src/SqliteStatement.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"SqliteStatement.d.ts","sourceRoot":"","sources":["../../src/SqliteStatement.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAwB,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AG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;IAI5C,KAAK;CAIb"}
|
|
@@ -50,6 +50,7 @@ class SqliteStatement {
|
|
|
50
50
|
prepare(db, logErrors = true) {
|
|
51
51
|
if (this.isPrepared)
|
|
52
52
|
throw new Error("SqliteStatement is already prepared");
|
|
53
|
+
this._db = db;
|
|
53
54
|
this._stmt = new IModelHost_1.IModelHost.platform.SqliteStatement();
|
|
54
55
|
this._stmt.prepare(db, this._sql, logErrors);
|
|
55
56
|
}
|
|
@@ -57,20 +58,37 @@ class SqliteStatement {
|
|
|
57
58
|
* or not. See [SQLite docs](https://www.sqlite.org/c3ref/stmt_readonly.html) for details.
|
|
58
59
|
*/
|
|
59
60
|
get isReadonly() {
|
|
60
|
-
return this.
|
|
61
|
+
return this.stmt.isReadonly();
|
|
61
62
|
}
|
|
62
63
|
/** Reset this statement so that the next call to step will return the first row, if any.
|
|
63
64
|
*/
|
|
64
65
|
reset() {
|
|
65
|
-
this.
|
|
66
|
+
this.stmt.reset();
|
|
66
67
|
}
|
|
67
68
|
/** Call this function when finished with this statement. This releases the native resources held by the statement. */
|
|
68
69
|
dispose() {
|
|
69
70
|
if (this._stmt) {
|
|
70
71
|
this._stmt.dispose(); // free native statement
|
|
71
72
|
this._stmt = undefined;
|
|
73
|
+
this._db = undefined;
|
|
72
74
|
}
|
|
73
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Call `step` on this statement and determine whether a new row is available.
|
|
78
|
+
* Use this method only when this statement has been prepared with a SELECT statement.
|
|
79
|
+
* @return true if a new row is available, false otherwise.
|
|
80
|
+
* @throws if `step` returns anything other than BE_SQLITE_ROW or BE_SQLITE_DONE.
|
|
81
|
+
*/
|
|
82
|
+
nextRow() {
|
|
83
|
+
const rc = this.step();
|
|
84
|
+
switch (rc) {
|
|
85
|
+
case core_bentley_1.DbResult.BE_SQLITE_ROW:
|
|
86
|
+
return true;
|
|
87
|
+
case core_bentley_1.DbResult.BE_SQLITE_DONE:
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
throw new core_bentley_1.BentleyError(rc, this._db.getLastError());
|
|
91
|
+
}
|
|
74
92
|
/** Binds a value to the specified SQL parameter.
|
|
75
93
|
* The value must be of one of these types:
|
|
76
94
|
* JavaScript Type | SQLite Type
|
|
@@ -91,28 +109,28 @@ class SqliteStatement {
|
|
|
91
109
|
bindValue(parameter, value) {
|
|
92
110
|
let stat;
|
|
93
111
|
if (value === undefined || value === null) {
|
|
94
|
-
stat = this.
|
|
112
|
+
stat = this.stmt.bindNull(parameter);
|
|
95
113
|
}
|
|
96
114
|
else if (typeof (value) === "number") {
|
|
97
115
|
if (Number.isInteger(value))
|
|
98
|
-
stat = this.
|
|
116
|
+
stat = this.stmt.bindInteger(parameter, value);
|
|
99
117
|
else
|
|
100
|
-
stat = this.
|
|
118
|
+
stat = this.stmt.bindDouble(parameter, value);
|
|
101
119
|
}
|
|
102
120
|
else if (typeof (value) === "boolean") {
|
|
103
|
-
stat = this.
|
|
121
|
+
stat = this.stmt.bindInteger(parameter, value ? 1 : 0);
|
|
104
122
|
}
|
|
105
123
|
else if (typeof (value) === "string") {
|
|
106
|
-
stat = this.
|
|
124
|
+
stat = this.stmt.bindString(parameter, value);
|
|
107
125
|
}
|
|
108
126
|
else if (!!value.id) {
|
|
109
|
-
stat = this.
|
|
127
|
+
stat = this.stmt.bindId(parameter, value.id);
|
|
110
128
|
}
|
|
111
129
|
else if (!!value.guid) {
|
|
112
|
-
stat = this.
|
|
130
|
+
stat = this.stmt.bindGuid(parameter, value.guid);
|
|
113
131
|
}
|
|
114
132
|
else if (value instanceof Uint8Array) {
|
|
115
|
-
stat = this.
|
|
133
|
+
stat = this.stmt.bindBlob(parameter, value);
|
|
116
134
|
}
|
|
117
135
|
else
|
|
118
136
|
throw new core_common_1.IModelError(core_bentley_1.DbResult.BE_SQLITE_ERROR, `Parameter value ${value} is of an unsupported data type.`);
|
|
@@ -128,48 +146,48 @@ class SqliteStatement {
|
|
|
128
146
|
* @param val integer to bind.
|
|
129
147
|
*/
|
|
130
148
|
bindInteger(parameter, val) {
|
|
131
|
-
this.checkBind(this.
|
|
149
|
+
this.checkBind(this.stmt.bindInteger(parameter, val));
|
|
132
150
|
}
|
|
133
151
|
/** Bind a double parameter
|
|
134
152
|
* @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')
|
|
135
153
|
* @param val double to bind.
|
|
136
154
|
*/
|
|
137
155
|
bindDouble(parameter, val) {
|
|
138
|
-
this.checkBind(this.
|
|
156
|
+
this.checkBind(this.stmt.bindDouble(parameter, val));
|
|
139
157
|
}
|
|
140
158
|
/** Bind a string parameter
|
|
141
159
|
* @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')
|
|
142
160
|
* @param val string to bind.
|
|
143
161
|
*/
|
|
144
162
|
bindString(parameter, val) {
|
|
145
|
-
this.checkBind(this.
|
|
163
|
+
this.checkBind(this.stmt.bindString(parameter, val));
|
|
146
164
|
}
|
|
147
165
|
/** Bind an Id64String parameter as a 64-bit integer
|
|
148
166
|
* @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')
|
|
149
167
|
* @param val Id to bind.
|
|
150
168
|
*/
|
|
151
169
|
bindId(parameter, id) {
|
|
152
|
-
this.checkBind(this.
|
|
170
|
+
this.checkBind(this.stmt.bindId(parameter, id));
|
|
153
171
|
}
|
|
154
172
|
/** Bind a Guid parameter
|
|
155
173
|
* @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')
|
|
156
174
|
* @param val Guid to bind.
|
|
157
175
|
*/
|
|
158
176
|
bindGuid(parameter, guid) {
|
|
159
|
-
this.checkBind(this.
|
|
177
|
+
this.checkBind(this.stmt.bindGuid(parameter, guid));
|
|
160
178
|
}
|
|
161
179
|
/** Bind a blob parameter
|
|
162
180
|
* @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')
|
|
163
181
|
* @param val blob to bind.
|
|
164
182
|
*/
|
|
165
183
|
bindBlob(parameter, blob) {
|
|
166
|
-
this.checkBind(this.
|
|
184
|
+
this.checkBind(this.stmt.bindBlob(parameter, blob));
|
|
167
185
|
}
|
|
168
186
|
/** Bind null to a parameter
|
|
169
187
|
* @param parameter Index (1-based) or name of the parameter (including the initial ':', '@' or '$')
|
|
170
188
|
*/
|
|
171
189
|
bindNull(parameter) {
|
|
172
|
-
this.checkBind(this.
|
|
190
|
+
this.checkBind(this.stmt.bindNull(parameter));
|
|
173
191
|
}
|
|
174
192
|
/** Bind values to all parameters in the statement.
|
|
175
193
|
* @param values The values to bind to the parameters.
|
|
@@ -201,7 +219,7 @@ class SqliteStatement {
|
|
|
201
219
|
* @throws [IModelError]($common) in case of errors
|
|
202
220
|
*/
|
|
203
221
|
clearBindings() {
|
|
204
|
-
const stat = this.
|
|
222
|
+
const stat = this.stmt.clearBindings();
|
|
205
223
|
if (stat !== core_bentley_1.DbResult.BE_SQLITE_OK)
|
|
206
224
|
throw new core_common_1.IModelError(stat, "Error in clearBindings");
|
|
207
225
|
}
|
|
@@ -216,41 +234,45 @@ class SqliteStatement {
|
|
|
216
234
|
* - [DbResult.BE_SQLITE_DONE]($core-bentley) if the statement has been executed successfully.
|
|
217
235
|
* - Error status in case of errors.
|
|
218
236
|
*/
|
|
219
|
-
step() { return this.
|
|
237
|
+
step() { return this.stmt.step(); }
|
|
220
238
|
/** Get the query result's column count (only for SQL SELECT statements). */
|
|
221
|
-
getColumnCount() { return this.
|
|
239
|
+
getColumnCount() { return this.stmt.getColumnCount(); }
|
|
222
240
|
/** Get the value for the column at the given index in the query result.
|
|
223
241
|
* @param columnIx Index of SQL column in query result (0-based)
|
|
224
242
|
*/
|
|
225
|
-
getValue(columnIx) { return new SqliteValue(this.
|
|
243
|
+
getValue(columnIx) { return new SqliteValue(this.stmt, columnIx); }
|
|
244
|
+
/** Determine whether the value of the specified column is null
|
|
245
|
+
* @param colIndex Index of SQL column in query result (0-based)
|
|
246
|
+
*/
|
|
247
|
+
isValueNull(colIndex) { return this.stmt.isValueNull(colIndex); }
|
|
226
248
|
/** Get a size in bytes of a blob or text column
|
|
227
249
|
* @param colIndex Index of SQL column in query result (0-based)
|
|
228
250
|
*/
|
|
229
|
-
getColumnBytes(colIndex) { return this.
|
|
251
|
+
getColumnBytes(colIndex) { return this.stmt.getColumnBytes(colIndex); }
|
|
230
252
|
/** Get a value as a blob
|
|
231
253
|
* @param colIndex Index of SQL column in query result (0-based)
|
|
232
254
|
*/
|
|
233
|
-
getValueBlob(colIndex) { return this.
|
|
255
|
+
getValueBlob(colIndex) { return this.stmt.getValueBlob(colIndex); }
|
|
234
256
|
/** Get a value as a double
|
|
235
257
|
* @param colIndex Index of SQL column in query result (0-based)
|
|
236
258
|
*/
|
|
237
|
-
getValueDouble(colIndex) { return this.
|
|
259
|
+
getValueDouble(colIndex) { return this.stmt.getValueDouble(colIndex); }
|
|
238
260
|
/** Get a value as a integer
|
|
239
261
|
* @param colIndex Index of SQL column in query result (0-based)
|
|
240
262
|
*/
|
|
241
|
-
getValueInteger(colIndex) { return this.
|
|
263
|
+
getValueInteger(colIndex) { return this.stmt.getValueInteger(colIndex); }
|
|
242
264
|
/** Get a value as a string
|
|
243
265
|
* @param colIndex Index of SQL column in query result (0-based)
|
|
244
266
|
*/
|
|
245
|
-
getValueString(colIndex) { return this.
|
|
267
|
+
getValueString(colIndex) { return this.stmt.getValueString(colIndex); }
|
|
246
268
|
/** Get a value as an Id
|
|
247
269
|
* @param colIndex Index of SQL column in query result (0-based)
|
|
248
270
|
*/
|
|
249
|
-
getValueId(colIndex) { return this.
|
|
271
|
+
getValueId(colIndex) { return this.stmt.getValueId(colIndex); }
|
|
250
272
|
/** Get a value as a Guid
|
|
251
273
|
* @param colIndex Index of SQL column in query result (0-based)
|
|
252
274
|
*/
|
|
253
|
-
getValueGuid(colIndex) { return this.
|
|
275
|
+
getValueGuid(colIndex) { return this.stmt.getValueGuid(colIndex); }
|
|
254
276
|
/** Get the current row.
|
|
255
277
|
* The returned row is formatted as JavaScript object where every SELECT clause item becomes a property in the JavaScript object.
|
|
256
278
|
*
|