@itwin/core-backend
Version:
iTwin.js backend components
206 lines • 11.9 kB
TypeScript
import { IModelJsNative } from "@bentley/imodeljs-native";
import { ECSchemaProps, ECSqlReader, QueryBinder, QueryOptions } from "@itwin/core-common";
import { ECSqlStatement, ECSqlWriteStatement } from "./ECSqlStatement";
import { SqliteStatement } from "./SqliteStatement";
import { _nativeDb } from "./internal/Symbols";
/** Modes for how to open [ECDb]($backend) files.
* @public
*/
export declare enum ECDbOpenMode {
Readonly = 0,
ReadWrite = 1,
/** Opens the file read-write and upgrades the file if necessary to the latest file format version. */
FileUpgrade = 2
}
/** An ECDb file
* @public
*/
export declare class ECDb implements Disposable {
private _nativeDb?;
private readonly _statementCache;
private _sqliteStatementCache;
/** only for tests
* @internal
*/
resetSqliteCache(size: number): void;
constructor();
/** Call this function when finished with this ECDb object. This releases the native resources held by the
* ECDb object.
*/
[Symbol.dispose](): void;
/**
* Attach an iModel file to this connection and load and register its schemas.
* @note There are some reserve tablespace names that cannot be used. They are 'main', 'schema_sync_db', 'ecchange' & 'temp'
* @param fileName IModel file name
* @param alias identifier for the attached file. This identifer is used to access schema from the attached file. e.g. if alias is 'abc' then schema can be accessed using 'abc.MySchema.MyClass'
*/
attachDb(fileName: string, alias: string): void;
/**
* Detach the attached file from this connection. The attached file is closed and its schemas are unregistered.
* @note There are some reserve tablespace names that cannot be used. They are 'main', 'schema_sync_db', 'ecchange' & 'temp'
* @param alias identifer that was used in the call to [[attachDb]]
*/
detachDb(alias: string): void;
/** @deprecated in 5.0 - will not be removed until after 2026-06-13. Use [Symbol.dispose] instead. */
dispose(): void;
/** Create an ECDb
* @param pathName The path to the ECDb file to create.
* @throws [IModelError]($common) if the operation failed.
*/
createDb(pathName: string): void;
/** Open the ECDb.
* @param pathName The path to the ECDb file to open
* @param openMode Open mode
* @throws [IModelError]($common) if the operation failed.
*/
openDb(pathName: string, openMode?: ECDbOpenMode): void;
/** Returns true if the ECDb is open */
get isOpen(): boolean;
/** Close the Db after saving any uncommitted changes.
* @throws [IModelError]($common) if the database is not open.
*/
closeDb(): void;
/** @internal use to test statement caching */
clearStatementCache(): void;
/** @internal use to test statement caching */
getCachedStatementCount(): number;
/** Commit the outermost transaction, writing changes to the file. Then, restart the transaction.
* @param changesetName The name of the operation that generated these changes.
* @throws [IModelError]($common) if the database is not open or if the operation failed.
*/
saveChanges(changesetName?: string): void;
/** Abandon (cancel) the outermost transaction, discarding all changes since last save. Then, restart the transaction.
* @throws [IModelError]($common) if the database is not open or if the operation failed.
*/
abandonChanges(): void;
/** Import a schema.
*
* If the import was successful, the database is automatically saved to disk.
* @param pathName Path to ECSchema XML file to import.
* @throws [IModelError]($common) if the database is not open or if the operation failed.
*/
importSchema(pathName: string): void;
/**
* Returns the full schema for the input name.
* @param name The name of the schema e.g. 'ECDbMeta'
* @returns The SchemaProps for the requested schema
* @throws if the schema can not be found or loaded.
*/
getSchemaProps(name: string): ECSchemaProps;
/**
* Use a prepared ECSQL statement, potentially from the statement cache. If the requested statement doesn't exist
* in the statement cache, a new statement is prepared. After the callback completes, the statement is reset and saved
* in the statement cache so it can be reused in the future. Use this method for ECSQL statements that will be
* reused often and are expensive to prepare. The statement cache holds the most recently used statements, discarding
* the oldest statements as it fills. For statements you don't intend to reuse, instead use [[withStatement]].
* @param sql The SQLite SQL statement to execute
* @param callback the callback to invoke on the prepared statement
* @param logErrors Determines if error will be logged if statement fail to prepare
* @returns the value returned by `callback`.
* @see [[withWriteStatement]]
* @beta
*/
withCachedWriteStatement<T>(ecsql: string, callback: (stmt: ECSqlWriteStatement) => T, logErrors?: boolean): T;
/**
* Prepared and execute a callback on an ECSQL statement. After the callback completes the statement is disposed.
* Use this method for ECSQL statements are either not expected to be reused, or are not expensive to prepare.
* For statements that will be reused often, instead use [[withPreparedStatement]].
* @param sql The SQLite SQL statement to execute
* @param callback the callback to invoke on the prepared statement
* @param logErrors Determines if error will be logged if statement fail to prepare
* @returns the value returned by `callback`.
* @see [[withCachedWriteStatement]]
* @beta
*/
withWriteStatement<T>(ecsql: string, callback: (stmt: ECSqlWriteStatement) => T, logErrors?: boolean): T;
/** Prepare an ECSQL statement.
* @param ecsql The ECSQL statement to prepare
* @param logErrors Determines if error will be logged if statement fail to prepare
* @throws [IModelError]($common) if there is a problem preparing the statement.
* @beta
*/
prepareWriteStatement(ecsql: string, logErrors?: boolean): ECSqlWriteStatement;
/**
* Use a prepared ECSQL statement, potentially from the statement cache. If the requested statement doesn't exist
* in the statement cache, a new statement is prepared. After the callback completes, the statement is reset and saved
* in the statement cache so it can be reused in the future. Use this method for ECSQL statements that will be
* reused often and are expensive to prepare. The statement cache holds the most recently used statements, discarding
* the oldest statements as it fills. For statements you don't intend to reuse, instead use [[withStatement]].
* @param sql The SQLite SQL statement to execute
* @param callback the callback to invoke on the prepared statement
* @param logErrors Determines if error will be logged if statement fail to prepare
* @returns the value returned by `callback`.
* @see [[withStatement]]
* @public
* @deprecated in 4.11 - will not be removed until after 2026-06-13. Use [[createQueryReader]] for SELECT statements and [[withCachedWriteStatement]] for INSERT/UPDATE/DELETE instead.
*/
withPreparedStatement<T>(ecsql: string, callback: (stmt: ECSqlStatement) => T, logErrors?: boolean): T;
/**
* Prepared and execute a callback on an ECSQL statement. After the callback completes the statement is disposed.
* Use this method for ECSQL statements are either not expected to be reused, or are not expensive to prepare.
* For statements that will be reused often, instead use [[withPreparedStatement]].
* @param sql The SQLite SQL statement to execute
* @param callback the callback to invoke on the prepared statement
* @param logErrors Determines if error will be logged if statement fail to prepare
* @returns the value returned by `callback`.
* @see [[withPreparedStatement]]
* @public
* @deprecated in 4.11 - will not be removed until after 2026-06-13. Use [[createQueryReader]] for SELECT statements and [[withWriteStatement]] for INSERT/UPDATE/DELETE instead.
*/
withStatement<T>(ecsql: string, callback: (stmt: ECSqlStatement) => T, logErrors?: boolean): T;
/** Prepare an ECSQL statement.
* @param ecsql The ECSQL statement to prepare
* @param logErrors Determines if error will be logged if statement fail to prepare
* @throws [IModelError]($common) if there is a problem preparing the statement.
* @deprecated in 4.11 - will not be removed until after 2026-06-13. Use [[prepareWriteStatement]] when preparing an INSERT/UPDATE/DELETE statement or [[createQueryReader]] to execute a SELECT statement.
*/
prepareStatement(ecsql: string, logErrors?: boolean): ECSqlStatement;
/**
* Use a prepared SQL statement, potentially from the statement cache. If the requested statement doesn't exist
* in the statement cache, a new statement is prepared. After the callback completes, the statement is reset and saved
* in the statement cache so it can be reused in the future. Use this method for SQL statements that will be
* reused often and are expensive to prepare. The statement cache holds the most recently used statements, discarding
* the oldest statements as it fills. For statements you don't intend to reuse, instead use [[withSqliteStatement]].
* @param sql The SQLite SQL statement to execute
* @param callback the callback to invoke on the prepared statement
* @param logErrors Determines if error will be logged if statement fail to prepare
* @returns the value returned by `callback`.
* @see [[withPreparedStatement]]
* @public
*/
withPreparedSqliteStatement<T>(sql: string, callback: (stmt: SqliteStatement) => T, logErrors?: boolean): T;
/**
* Prepared and execute a callback on a SQL statement. After the callback completes the statement is disposed.
* Use this method for SQL statements are either not expected to be reused, or are not expensive to prepare.
* For statements that will be reused often, instead use [[withPreparedSqliteStatement]].
* @param sql The SQLite SQL statement to execute
* @param callback the callback to invoke on the prepared statement
* @param logErrors Determines if error will be logged if statement fail to prepare
* @returns the value returned by `callback`.
* @public
*/
withSqliteStatement<T>(sql: string, callback: (stmt: SqliteStatement) => T, logErrors?: boolean): T;
/** Prepare an SQL statement.
* @param sql The SQLite SQL statement to prepare
* @param logErrors Determines if error will be logged if statement fail to prepare
* @throws [IModelError]($common) if there is a problem preparing the statement.
* @internal
*/
prepareSqliteStatement(sql: string, logErrors?: boolean): SqliteStatement;
/** @internal */
get [_nativeDb](): IModelJsNative.ECDb;
/** Allow to execute query and read results along with meta data. The result are streamed.
*
* See also:
* - [ECSQL Overview]($docs/learning/backend/ExecutingECSQL)
* - [Code Examples]($docs/learning/backend/ECSQLCodeExamples)
* - [ECSQL Row Format]($docs/learning/ECSQLRowFormat)
*
* @param params The values to bind to the parameters (if the ECSQL has any).
* @param config Allow to specify certain flags which control how query is executed.
* @returns Returns an [ECSqlReader]($common) which helps iterate over the result set and also give access to metadata.
* @public
* */
createQueryReader(ecsql: string, params?: QueryBinder, config?: QueryOptions): ECSqlReader;
}
//# sourceMappingURL=ECDb.d.ts.map