/** @packageDocumentation
 * @module iModels
 */
import { BentleyError, DbResult, Id64String, OrderedId64Iterable } from "@itwin/core-bentley";
import { Point2d, Point3d } from "@itwin/core-geometry";
/**
 * Specifies the format of the rows returned by the `query` and `restartQuery` methods of
 * [IModelConnection]($frontend), [IModelDb]($backend), and [ECDb]($backend).
 *
 * @public
 * @extensions
 */
export declare 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 = 0,
    /** 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 = 1,
    /** 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.
     * @depreacted in 4.11.  Switch to UseECSqlPropertyIndexes for best performance, and UseECSqlPropertyNames if you want a JSON object as the result.
     */
    UseJsPropertyNames = 2
}
/**
 * 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 extend type is set to an empty string.
     * @deprecated in 4.11 - will not be removed until after 2026-06-13. Use extendedType instead
     */
    extendType: string;
    /** If this property is a PrimitiveECProperty, extended 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 will be undefined. */
    extendedType?: 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;
    prepareTime: 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.
     * @deprecated in 4.11 - will not be removed until after 2026-06-13. Use ecsql function ec_classname to get class name instead.
     * */
    convertClassIdsToClassNames?: boolean;
    /**
     * Determine row format.
     */
    rowFormat?: QueryRowFormat;
}
/** @beta */
export type BlobRange = QueryLimit;
/** @beta */
export interface BlobOptions extends BaseReaderOptions {
    range?: BlobRange;
}
/** @public */
export declare class QueryOptionsBuilder {
    private _options;
    constructor(_options?: QueryOptions);
    getOptions(): QueryOptions;
    /**
     * @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.
     */
    setPriority(val: number): 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.
     */
    setRestartToken(val: string): 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.
     */
    setQuota(val: QueryQuota): 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.
     */
    setUsePrimaryConnection(val: boolean): 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.
     */
    setAbbreviateBlobs(val: boolean): 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.
     */
    setSuppressLogErrors(val: boolean): 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.
     * @deprecated in 4.11 - will not be removed until after 2026-06-13. Use ecsql function ec_classname to get class name instead.
     */
    setConvertClassIdsToNames(val: boolean): 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.
     */
    setLimit(val: QueryLimit): this;
    /**
     * Specify row format returned by concurrent query manager.
     * @param val @enum QueryRowFormat specifying format for result.
     * @returns @type QueryOptionsBuilder for fluent interface.
     */
    setRowFormat(val: QueryRowFormat): 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.
     */
    setDelay(val: number): this;
}
/** @beta */
export declare class BlobOptionsBuilder {
    private _options;
    constructor(_options?: BlobOptions);
    getOptions(): BlobOptions;
    /**
     * @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.
     */
    setPriority(val: number): 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.
     */
    setRestartToken(val: string): 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.
     */
    setQuota(val: QueryQuota): 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.
     */
    setUsePrimaryConnection(val: boolean): 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.
     */
    setRange(val: BlobRange): 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.
     */
    setDelay(val: number): this;
}
/** @internal */
export declare enum QueryParamType {
    Boolean = 0,
    Double = 1,
    Id = 2,
    IdSet = 3,
    Integer = 4,
    Long = 5,
    Null = 6,
    Point2d = 7,
    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 declare class QueryBinder {
    private _args;
    private verify;
    /**
     * 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.
     */
    bindBoolean(indexOrName: string | number, val: boolean): 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.
     */
    bindBlob(indexOrName: string | number, val: Uint8Array): 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.
     */
    bindDouble(indexOrName: string | number, val: number): 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.
     */
    bindId(indexOrName: string | number, val: Id64String): 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.
     */
    bindIdSet(indexOrName: string | number, val: OrderedId64Iterable): 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.
     */
    bindInt(indexOrName: string | number, val: number): 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.
     */
    bindStruct(indexOrName: string | number, val: object): 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.
     */
    bindLong(indexOrName: string | number, val: number): 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.
     */
    bindString(indexOrName: string | number, val: string): 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.
     */
    bindNull(indexOrName: string | number): 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.
     */
    bindPoint2d(indexOrName: string | number, val: Point2d): 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.
     */
    bindPoint3d(indexOrName: string | number, val: Point3d): this;
    private static bind;
    /**
     * 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.
     */
    static from(args: any[] | object | undefined): QueryBinder;
    serialize(): object;
}
/** @internal */
export declare enum DbRequestKind {
    BlobIO = 0,
    ECSql = 1
}
/** @internal */
export declare enum DbResponseKind {
    BlobIO = 0,
    ECSql = 1,
    NoResult = 2
}
/** @internal */
export declare 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.*/
    ShuttingDown = 6,/*  Shutdown is in progress. */
    Error = 100,/*  generic error*/
    Error_ECSql_PreparedFailed = 101,/*  ecsql prepared failed*/
    Error_ECSql_StepFailed = 102,/*  ecsql step failed*/
    Error_ECSql_RowToJsonFailed = 103,/*  ecsql failed to serialized row to json.*/
    Error_ECSql_BindingFailed = 104,/*  ecsql binding failed.*/
    Error_BlobIO_OpenFailed = 105,/*  class or property or instance specified was not found or property as not of type blob.*/
    Error_BlobIO_OutOfRange = 106
}
/** @internal */
export declare 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 declare class DbQueryError extends BentleyError {
    readonly response: any;
    readonly request?: any;
    constructor(response: any, request?: any, rc?: DbResult);
    static throwIfError(response: any, request?: any): void;
}
/** @internal */
export interface DbRequestExecutor<TRequest extends DbRequest, TResponse extends DbResponse> {
    execute(request: TRequest): Promise<TResponse>;
}
/** @internal */
export interface DbQueryConfig {
    globalQuota?: QueryQuota;
    /** For testing */
    ignoreDelay?: boolean;
    /** Priority of request is ignored */
    ignorePriority?: boolean;
    /** Max queue size after which queries are rejected with error QueueFull */
    requestQueueSize?: number;
    /** Number of worker thread, default to 4 */
    workerThreads?: number;
    /** Use thread connection to prepare the statement */
    doNotUsePrimaryConnToPrepare?: boolean;
    /** After no activity for given time concurrent query will automatically shutdown */
    autoShutdownWhenIdleForSeconds?: number;
    /** Maximum number of statement cache per worker. Default to 40 */
    statementCacheSizePerWorker?: number;
    monitorPollInterval?: number;
    /** Set memory map io for each worker connection size in bytes. Default to zero mean do not use mmap io */
    memoryMapFileSize?: number;
    /** How often to measure progress of a running ECSql statement which is used to enforced time limit */
    progressOpCount?: number;
}
//# sourceMappingURL=ConcurrentQuery.d.ts.map