-
Notifications
You must be signed in to change notification settings - Fork 208
/
ConcurrentQuery.ts
744 lines (704 loc) · 25.6 KB
/
ConcurrentQuery.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module iModels
*/
import { BentleyError, CompressedId64Set, DbResult, Id64, Id64String, OrderedId64Iterable } from "@itwin/core-bentley";
import { Point2d, Point3d } from "@itwin/core-geometry";
import { Base64 } from "js-base64";
/**
* Specifies the format of the rows returned by the `query` and `restartQuery` methods of
* [IModelConnection]($frontend), [IModelDb]($backend), and [ECDb]($backend).
*
* @public
* @extensions
*/
export enum QueryRowFormat {
/** Each row is an object in which each non-null column value can be accessed by its name as defined in the ECSql.
* Null values are omitted.
*/
UseECSqlPropertyNames,
/** Each row is an array of values accessed by an index corresponding to the property's position in the ECSql SELECT statement.
* Null values are included if they are followed by a non-null column, but trailing null values at the end of the array are omitted.
*/
UseECSqlPropertyIndexes,
/** Each row is an object in which each non-null column value can be accessed by a [remapped property name]($docs/learning/ECSqlRowFormat.md).
* This format is backwards-compatible with the format produced by iTwin.js 2.x. Null values are omitted.
*/
UseJsPropertyNames,
}
/**
* Specify limit or range of rows to return
* @public
* @extensions
* */
export interface QueryLimit {
/** Number of rows to return */
count?: number;
/** Offset from which to return rows */
offset?: number;
}
/** @public */
export interface QueryPropertyMetaData {
/** The class name is set to empty if the property is a generated one, otherwise, it is the name of the ECClass that the property is contained within. */
className: string;
/** Access string is the property's alias if the property is a generated one, otherwise it is the ECSQL property path. */
accessString?: string;
/** True if the property is a generated one. False, if the property directly refers to one of the classes in the FROM or JOIN clauses.
* Note: Using a column alias always generates a property. So in the ECSQL <c>SELECT AssetID, Length * Breadth AS Area FROM myschema.Cubicle</c> the first column (AssetID) would not be a generated property, but the second (Area) would be.
*/
generated: boolean;
/** The index of the property value if the result is formatted as an array */
index: number;
/** The JSON name is the property's alias if the property is a generated one, otherwise, it is the ECSQL property path for the system property.
* The JSON names are unique and _%d is added for duplicate property JSON names to make them unique.
*/
jsonName: string;
/** The name is the property's alias if the property is a generated one, otherwise, it is the name of the property. */
name: string;
/** If this property is a PrimitiveECProperty, extend type is the extended type name of this property, if it is not defined locally will be inherited from base property if one exists, otherwise extended type is set to an empty string. */
extendType: string;
/** The type name is set to 'navigation' if the property is a navigation property, otherwise, it is the type name for the property. */
typeName: string;
}
/** @beta */
export interface DbRuntimeStats {
cpuTime: number;
totalTime: number;
timeLimit: number;
memLimit: number;
memUsed: number;
}
/**
* Quota hint for the query.
* @public
* @extensions
* */
export interface QueryQuota {
/** Max time allowed in seconds. This is hint and may not be honoured but help in prioritize request */
time?: number;
/** Max memory allowed in bytes. This is hint and may not be honoured but help in prioritize request */
memory?: number;
}
/**
* Config for all request made to concurrent query engine.
* @public
* @extensions
*/
export interface BaseReaderOptions {
/** Determine priority of this query default to 0, used as hint and can be overriden by backend. */
priority?: number;
/** If specified cancel last query (if any) with same restart token and queue the new query */
restartToken?: string;
/** For editing apps this can be set to true and all query will run on primary connection
* his may cause slow queries execution but the most recent data changes will be visitable via query
*/
usePrimaryConn?: boolean;
/** Restrict time or memory for query but use as hint and may be changed base on backend settings */
quota?: QueryQuota;
/**
* @internal
* Allow query to be be deferred by milliseconds specified. This parameter is ignore by default unless
* concurrent query is configure to honour it.
*/
delay?: number;
}
/**
* ECSql query config
* @public
* @extensions
* */
export interface QueryOptions extends BaseReaderOptions {
/**
* default to false. It abbreviate blobs to single bytes. This help cases where wildcard is
* used in select clause. Use BlobReader api to read individual blob specially if its of large size.
* */
abbreviateBlobs?: boolean;
/**
* default to false. It will suppress error and will not log it. Useful in cases where we expect query
* can fail.
*/
suppressLogErrors?: boolean;
/** This is used internally. If true it query will return meta data about query. */
includeMetaData?: boolean;
/** Limit range of rows returned by query*/
limit?: QueryLimit;
/**
* Convert ECClassId, SourceECClassId, TargetECClassId and RelClassId to respective name.
* When true, XXXXClassId property will be returned as className.
* */
convertClassIdsToClassNames?: boolean;
/**
* Determine row format.
*/
rowFormat?: QueryRowFormat;
}
/** @beta */
export type BlobRange = QueryLimit;
/** @beta */
export interface BlobOptions extends BaseReaderOptions {
range?: BlobRange;
}
/** @public */
export class QueryOptionsBuilder {
public constructor(private _options: QueryOptions = {}) { }
public getOptions(): QueryOptions { return this._options; }
/**
* @internal
* Allow to set priority of query. Query will be inserted int queue base on priority value. This value will be ignored if concurrent query is configured with ignored priority is true.
* @param val integer value which can be negative as well. By default its zero.
* @returns @type QueryOptionsBuilder for fluent interface.
*/
public setPriority(val: number) {
this._options.priority = val;
return this;
}
/**
* Allow to set restart token. If restart token is set then any other query(s) in queue with same token is cancelled if its not already executed.
* @param val A string token identifying a use case in which previous query with same token is cancelled.
* @returns @type QueryOptionsBuilder for fluent interface.
*/
public setRestartToken(val: string) {
this._options.restartToken = val;
return this;
}
/**
* Allow to set quota restriction for query. Its a hint and may be overriden or ignored by concurrent query manager.
* @param val @type QueryQuota Specify time and memory that can be used by a query.
* @returns @type QueryOptionsBuilder for fluent interface.
*/
public setQuota(val: QueryQuota) {
this._options.quota = val;
return this;
}
/**
* Force a query to be executed synchronously against primary connection. This option is ignored if provided by frontend.
* @param val A boolean value to force use primary connection on main thread to execute query.
* @returns @type QueryOptionsBuilder for fluent interface.
*/
public setUsePrimaryConnection(val: boolean) {
this._options.usePrimaryConn = val;
return this;
}
/**
* By default all blobs are abbreviated to save memory and network bandwidth. If set to false, all blob data will be returned by query as is.
* Use @type BlobReader to access blob data more efficiently.
* @param val A boolean value, if set to false will return complete blob type property data. This could cost time and network bandwidth.
* @returns @type QueryOptionsBuilder for fluent interface.
*/
public setAbbreviateBlobs(val: boolean) {
this._options.abbreviateBlobs = val;
return this;
}
/**
* When query fail to prepare it will log error. This setting will suppress log errors in case where query come from user typing it and its expected to fail often.
* @param val A boolean value, if set to true, any error logging will be suppressed.
* @returns @type QueryOptionsBuilder for fluent interface.
*/
public setSuppressLogErrors(val: boolean) {
this._options.suppressLogErrors = val;
return this;
}
/**
* If set ECClassId, SourceECClassId and TargetECClassId system properties will return qualified name of class instead of a @typedef Id64String.
* @param val A boolean value.
* @returns @type QueryOptionsBuilder for fluent interface.
*/
public setConvertClassIdsToNames(val: boolean) {
this._options.convertClassIdsToClassNames = val;
return this;
}
/**
* Specify limit for query. Limit determine number of rows and offset in result-set.
* @param val Specify count and offset from within the result-set of a ECSQL query.
* @returns @type QueryOptionsBuilder for fluent interface.
*/
public setLimit(val: QueryLimit) {
this._options.limit = val;
return this;
}
/**
* Specify row format returned by concurrent query manager.
* @param val @enum QueryRowFormat specifying format for result.
* @returns @type QueryOptionsBuilder for fluent interface.
*/
public setRowFormat(val: QueryRowFormat) {
this._options.rowFormat = val;
return this;
}
/**
* @internal
* Defers execution of query in queue by specified milliseconds. This parameter is ignored by default unless concurrent query is configure to not ignore it.
* @param val Number of milliseconds.
* @returns @type QueryOptionsBuilder for fluent interface.
*/
public setDelay(val: number) {
this._options.delay = val;
return this;
}
}
/** @beta */
export class BlobOptionsBuilder {
public constructor(private _options: BlobOptions = {}) { }
public getOptions(): BlobOptions { return this._options; }
/**
* @internal
* Allow to set priority of blob request. Blob request will be inserted int queue base on priority value. This value will be ignored if concurrent query is configured with ignored priority is true.
* @param val integer value which can be negative as well. By default its zero.
* @returns @type BlobOptionsBuilder for fluent interface.
*/
public setPriority(val: number) {
this._options.priority = val;
return this;
}
/**
* Allow to set restart token. If restart token is set then any other blob request in queue with same token is cancelled if its not already executed.
* @param val A string token identifying a use case in which previous blob request with same token is cancelled.
* @returns @type BlobOptionsBuilder for fluent interface.
*/
public setRestartToken(val: string) {
this._options.restartToken = val;
return this;
}
/**
* Allow to set quota restriction for blob request. Its a hint and may be overriden or ignored by concurrent query manager.
* @param val @type QueryQuota Specify time and memory that can be used by a query.
* @returns @type BlobOptionsBuilder for fluent interface.
*/
public setQuota(val: QueryQuota) {
this._options.quota = val;
return this;
}
/**
* Force a blob request to be executed synchronously against primary connection. This option is ignored if provided by frontend.
* @param val A boolean value to force use primary connection on main thread to execute blob request.
* @returns @type BlobOptionsBuilder for fluent interface.
*/
public setUsePrimaryConnection(val: boolean) {
this._options.usePrimaryConn = val;
return this;
}
/**
* Specify range with in the blob that need to be returned.
* @param val Specify offset and count of bytes that need to be returned.
* @returns @type BlobOptionsBuilder for fluent interface.
*/
public setRange(val: BlobRange) {
this._options.range = val;
return this;
}
/**
* @internal
* Defers execution of blob request in queue by specified milliseconds. This parameter is ignored by default unless concurrent query is configure to not ignore it.
* @param val Number of milliseconds.
* @returns @type BlobOptionsBuilder for fluent interface.
*/
public setDelay(val: number) {
this._options.delay = val;
return this;
}
}
/** @internal */
export enum QueryParamType {
Boolean = 0,
Double = 1,
Id = 2,
IdSet = 3,
Integer = 4,
Long = 5,
Null = 6,
// eslint-disable-next-line @typescript-eslint/no-shadow
Point2d = 7,
// eslint-disable-next-line @typescript-eslint/no-shadow
Point3d = 8,
String = 9,
Blob = 10,
Struct = 11,
}
/**
* Bind values to an ECSQL query.
*
* All binding class methods accept an `indexOrName` parameter as a `string | number` type and a value to bind to it.
* A binding must be mapped either by a positional index or a string/name. See the examples below.
*
* @example
* Parameter By Index:
* ```sql
* SELECT a, v FROM test.Foo WHERE a=? AND b=?
* ```
* The first `?` is index 1 and the second `?` is index 2. The parameter index starts with 1 and not 0.
*
* @example
* Parameter By Name:
* ```sql
* SELECT a, v FROM test.Foo WHERE a=:name_a AND b=:name_b
* ```
* Using "name_a" as the `indexOrName` will bind the provided value to `name_a` in the query. And the same goes for
* using "name_b" and the `name_b` binding respectively.
*
* @see
* - [ECSQL Parameters]($docs/learning/ECSQL.md#ecsql-parameters)
* - [ECSQL Parameter Types]($docs/learning/ECSQLParameterTypes)
* - [ECSQL Code Examples]($docs/learning/backend/ECSQLCodeExamples#parameter-bindings)
*
* @public
*/
export class QueryBinder {
private _args = {};
private verify(indexOrName: string | number) {
if (typeof indexOrName === "number") {
if (indexOrName < 1)
throw new Error("expect index to be >= 1");
return;
}
if (!/^[a-zA-Z_]+\w*$/i.test(indexOrName)) {
throw new Error("expect named parameter to meet identifier specification");
}
}
/**
* Bind boolean value to ECSQL statement.
* @param indexOrName Specify parameter index or its name used in ECSQL statement.
* @param val Boolean value to bind to ECSQL statement.
* @returns @type QueryBinder to allow fluent interface.
*/
public bindBoolean(indexOrName: string | number, val: boolean) {
this.verify(indexOrName);
const name = String(indexOrName);
Object.defineProperty(this._args, name, {
enumerable: true,
value: {
type: QueryParamType.Boolean,
value: val,
},
});
return this;
}
/**
* Bind blob value to ECSQL statement.
* @param indexOrName Specify parameter index or its name used in ECSQL statement.
* @param val Blob value to bind to ECSQL statement.
* @returns @type QueryBinder to allow fluent interface.
*/
public bindBlob(indexOrName: string | number, val: Uint8Array) {
this.verify(indexOrName);
const name = String(indexOrName);
const base64 = Base64.fromUint8Array(val);
Object.defineProperty(this._args, name, {
enumerable: true, value: {
type: QueryParamType.Blob,
value: base64,
},
});
return this;
}
/**
* Bind double value to ECSQL statement.
* @param indexOrName Specify parameter index or its name used in ECSQL statement.
* @param val Double value to bind to ECSQL statement.
* @returns @type QueryBinder to allow fluent interface.
*/
public bindDouble(indexOrName: string | number, val: number) {
this.verify(indexOrName);
const name = String(indexOrName);
Object.defineProperty(this._args, name, {
enumerable: true, value: {
type: QueryParamType.Double,
value: val,
},
});
return this;
}
/**
* Bind @typedef Id64String value to ECSQL statement.
* @param indexOrName Specify parameter index or its name used in ECSQL statement.
* @param val @typedef Id64String value to bind to ECSQL statement.
* @returns @type QueryBinder to allow fluent interface.
*/
public bindId(indexOrName: string | number, val: Id64String) {
this.verify(indexOrName);
const name = String(indexOrName);
Object.defineProperty(this._args, name, {
enumerable: true, value: {
type: QueryParamType.Id,
value: val,
},
});
return this;
}
/**
* Bind @type OrderedId64Iterable to ECSQL statement.
* @param indexOrName Specify parameter index or its name used in ECSQL statement.
* @param val @type OrderedId64Iterable value to bind to ECSQL statement.
* @returns @type QueryBinder to allow fluent interface.
*/
public bindIdSet(indexOrName: string | number, val: OrderedId64Iterable) {
this.verify(indexOrName);
const name = String(indexOrName);
OrderedId64Iterable.uniqueIterator(val);
Object.defineProperty(this._args, name, {
enumerable: true, value: {
type: QueryParamType.IdSet,
value: CompressedId64Set.sortAndCompress(OrderedId64Iterable.uniqueIterator(val)),
},
});
return this;
}
/**
* Bind integer to ECSQL statement.
* @param indexOrName Specify parameter index or its name used in ECSQL statement.
* @param val Integer value to bind to ECSQL statement.
* @returns @type QueryBinder to allow fluent interface.
*/
public bindInt(indexOrName: string | number, val: number) {
this.verify(indexOrName);
const name = String(indexOrName);
Object.defineProperty(this._args, name, {
enumerable: true, value: {
type: QueryParamType.Integer,
value: val,
},
});
return this;
}
/**
* Bind struct to ECSQL statement. Struct specified as object.
* @param indexOrName Specify parameter index or its name used in ECSQL statement.
* @param val struct value to bind to ECSQL statement.
* @returns @type QueryBinder to allow fluent interface.
*/
public bindStruct(indexOrName: string | number, val: object) {
this.verify(indexOrName);
const name = String(indexOrName);
Object.defineProperty(this._args, name, {
enumerable: true, value: {
type: QueryParamType.Struct,
value: val,
},
});
return this;
}
/**
* Bind long to ECSQL statement.
* @param indexOrName Specify parameter index or its name used in ECSQL statement.
* @param val Long value to bind to ECSQL statement.
* @returns @type QueryBinder to allow fluent interface.
*/
public bindLong(indexOrName: string | number, val: number) {
this.verify(indexOrName);
const name = String(indexOrName);
Object.defineProperty(this._args, name, {
enumerable: true, value: {
type: QueryParamType.Long,
value: val,
},
});
return this;
}
/**
* Bind string to ECSQL statement.
* @param indexOrName Specify parameter index or its name used in ECSQL statement.
* @param val String value to bind to ECSQL statement.
* @returns @type QueryBinder to allow fluent interface.
*/
public bindString(indexOrName: string | number, val: string) {
this.verify(indexOrName);
const name = String(indexOrName);
Object.defineProperty(this._args, name, {
enumerable: true, value: {
type: QueryParamType.String,
value: val,
},
});
return this;
}
/**
* Bind null to ECSQL statement.
* @param indexOrName Specify parameter index or its name used in ECSQL statement.
* @returns @type QueryBinder to allow fluent interface.
*/
public bindNull(indexOrName: string | number) {
this.verify(indexOrName);
const name = String(indexOrName);
Object.defineProperty(this._args, name, {
enumerable: true, value: {
type: QueryParamType.Null,
value: null,
},
});
return this;
}
/**
* Bind @type Point2d to ECSQL statement.
* @param indexOrName Specify parameter index or its name used in ECSQL statement.
* @param val @type Point2d value to bind to ECSQL statement.
* @returns @type QueryBinder to allow fluent interface.
*/
public bindPoint2d(indexOrName: string | number, val: Point2d) {
this.verify(indexOrName);
const name = String(indexOrName);
Object.defineProperty(this._args, name, {
enumerable: true, value: {
type: QueryParamType.Point2d,
value: val,
},
});
return this;
}
/**
* Bind @type Point3d to ECSQL statement.
* @param indexOrName Specify parameter index or its name used in ECSQL statement.
* @param val @type Point3d value to bind to ECSQL statement.
* @returns @type QueryBinder to allow fluent interface.
*/
public bindPoint3d(indexOrName: string | number, val: Point3d) {
this.verify(indexOrName);
const name = String(indexOrName);
Object.defineProperty(this._args, name, {
enumerable: true, value: {
type: QueryParamType.Point3d,
value: val,
},
});
return this;
}
private static bind(params: QueryBinder, nameOrId: string | number, val: any) {
if (typeof val === "boolean") {
params.bindBoolean(nameOrId, val);
} else if (typeof val === "number") {
params.bindDouble(nameOrId, val);
} else if (typeof val === "string") {
params.bindString(nameOrId, val);
} else if (val instanceof Uint8Array) {
params.bindBlob(nameOrId, val);
} else if (val instanceof Point2d) {
params.bindPoint2d(nameOrId, val);
} else if (val instanceof Point3d) {
params.bindPoint3d(nameOrId, val);
} else if (val instanceof Array && val.length > 0 && typeof val[0] === "string" && Id64.isValidId64(val[0])) {
params.bindIdSet(nameOrId, val);
} else if (typeof val === "undefined" || val === null) {
params.bindNull(nameOrId);
} else if (typeof val === "object" && !Array.isArray(val)) {
params.bindStruct(nameOrId, val);
} else {
throw new Error("unsupported type");
}
}
/**
* Allow bulk bind either parameters by index as value array or by parameter names as object.
* @param args if array of values is provided then array index is used as index. If object is provided then object property name is used as parameter name of reach value.
* @returns @type QueryBinder to allow fluent interface.
*/
public static from(args: any[] | object | undefined): QueryBinder {
const params = new QueryBinder();
if (typeof args === "undefined")
return params;
if (Array.isArray(args)) {
let i = 1;
for (const val of args) {
this.bind(params, i++, val);
}
} else {
for (const prop of Object.getOwnPropertyNames(args)) {
this.bind(params, prop, (args as any)[prop]);
}
}
return params;
}
public serialize(): object {
return this._args;
}
}
/** @internal */
export enum DbRequestKind {
BlobIO = 0,
ECSql = 1
}
/** @internal */
export enum DbResponseKind {
BlobIO = DbRequestKind.BlobIO,
ECSql = DbRequestKind.ECSql,
NoResult = 2
}
/** @internal */
export enum DbResponseStatus {
Done = 1, /* query ran to completion. */
Cancel = 2, /* Requested by user.*/
Partial = 3, /* query was running but ran out of quota.*/
Timeout = 4, /* query time quota expired while it was in queue.*/
QueueFull = 5, /* could not submit the query as queue was full.*/
Error = 100, /* generic error*/
Error_ECSql_PreparedFailed = Error + 1, /* ecsql prepared failed*/
Error_ECSql_StepFailed = Error + 2, /* ecsql step failed*/
Error_ECSql_RowToJsonFailed = Error + 3, /* ecsql failed to serialized row to json.*/
Error_ECSql_BindingFailed = Error + 4, /* ecsql binding failed.*/
Error_BlobIO_OpenFailed = Error + 5, /* class or property or instance specified was not found or property as not of type blob.*/
Error_BlobIO_OutOfRange = Error + 6, /* range specified is invalid based on size of blob.*/
}
/** @internal */
export enum DbValueFormat {
ECSqlNames = 0,
JsNames = 1
}
/** @internal */
export interface DbRequest extends BaseReaderOptions {
kind?: DbRequestKind;
}
/** @internal */
export interface DbQueryRequest extends DbRequest, QueryOptions {
valueFormat?: DbValueFormat;
query: string;
args?: object;
}
/** @internal */
export interface DbBlobRequest extends DbRequest, BlobOptions {
className: string;
accessString: string;
instanceId: Id64String;
}
/** @internal */
export interface DbResponse {
stats: DbRuntimeStats;
status: DbResponseStatus;
kind: DbResponseKind;
error?: string;
}
/** @internal */
export interface DbQueryResponse extends DbResponse {
meta: QueryPropertyMetaData[];
data: any[];
rowCount: number;
}
/** @internal */
export interface DbBlobResponse extends DbResponse {
data?: Uint8Array;
rawBlobSize: number;
}
/** @public */
export class DbQueryError extends BentleyError {
public constructor(public readonly response: any, public readonly request?: any, rc?: DbResult) {
super(rc ?? DbResult.BE_SQLITE_ERROR, response.error, { response, request });
}
public static throwIfError(response: any, request?: any) {
if ((response.status as number) >= (DbResponseStatus.Error as number)) {
throw new DbQueryError(response, request);
}
if (response.status === DbResponseStatus.Cancel) {
throw new DbQueryError(response, request, DbResult.BE_SQLITE_INTERRUPT);
}
}
}
/** @internal */
export interface DbRequestExecutor<TRequest extends DbRequest, TResponse extends DbResponse> {
execute(request: TRequest): Promise<TResponse>;
}
/** @internal */
export interface DbQueryConfig {
globalQuota?: QueryQuota;
ignoreDelay?: boolean;
ignorePriority?: boolean;
requestQueueSize?: number;
workerThreads?: number;
}