@itwin/core-backend
Version:
iTwin.js backend components
278 lines • 9.39 kB
TypeScript
/** @packageDocumentation
* @module SQLiteDb
*/
import { DbValueType, Id64String } from "@itwin/core-bentley";
import { ECDb } from "./ECDb";
import { IModelDb } from "./IModelDb";
/** Changed value type
* @beta
*/
type SqliteValue = Uint8Array | number | string | null | undefined;
/** Array of changed values
* @beta
*/
type SqliteValueArray = SqliteValue[];
/**
* Format option when converting change from array to column/value object.
* @beta
*/
export interface ChangeFormatArgs {
/** include table name */
includeTableName?: true;
/** include op code */
includeOpCode?: true;
/** include null columns */
includeNullColumns?: true;
/** include value version */
includeStage?: true;
/** include primary key in update change */
includePrimaryKeyInUpdateNew?: true;
}
/** Operation that cause the change
* @beta
*/
export type SqliteChangeOp = "Inserted" | "Updated" | "Deleted";
/** Stage is version of value that needed to be read
* @beta
*/
export type SqliteValueStage = "Old" | "New";
/** Db from which schema will be read. It should be from timeline to which changeset belong.
* @beta
*/
export type AnyDb = IModelDb | ECDb;
/** Arg to open a changeset file from disk
* @beta
*/
export interface SqliteChangesetReaderArgs {
/** db from which schema will be read. It should be at or ahead of the latest changeset being opened.*/
readonly db: AnyDb;
/** invert the changeset operations */
readonly invert?: true;
/** do not check if column of change match db schema instead ignore addition columns */
readonly disableSchemaCheck?: true;
}
/**
* Represent sqlite change.
* @beta
*/
export interface SqliteChange {
/** name of table */
$table?: string;
/** SQLite operation that created this change */
$op?: SqliteChangeOp;
/** version of data in change. */
$stage?: SqliteValueStage;
/** columns in change */
[key: string]: any;
}
/**
* Read raw sqlite changeset from disk and enumerate changes.
* It also optionally let you format change with schema from
* a db provided.
* @beta
*/
export declare class SqliteChangesetReader implements Disposable {
/** db from where sql schema will be read */
readonly db: AnyDb;
private readonly _nativeReader;
private _schemaCache;
private _disableSchemaCheck;
private _changeIndex;
protected constructor(
/** db from where sql schema will be read */
db: AnyDb);
/**
* Open changeset file from disk
* @param args fileName of changeset reader and other options.
* @returns SqliteChangesetReader instance
*/
static openFile(args: {
readonly fileName: string;
} & SqliteChangesetReaderArgs): SqliteChangesetReader;
/**
* Group changeset file into single changeset and open that changeset.
* @param args - The arguments for opening the changeset group. Requires an open db.
* @returns The SqliteChangesetReader instance.
*/
static openGroup(args: {
readonly changesetFiles: string[];
} & SqliteChangesetReaderArgs): SqliteChangesetReader;
/**
* Open txn change in iModel.
* @param args iModel and other options.
* @returns SqliteChangesetReader instance
*/
static openTxn(args: {
txnId: Id64String;
} & SqliteChangesetReaderArgs): SqliteChangesetReader;
/**
* Writes the changeset to a file.
* @note can be use with openGroup() or openLocalChanges() to persist changeset.
* @param args - The arguments for writing to the file.
* @param args.fileName - The name of the file to write to.
* @param args.containsSchemaChanges - Indicates whether the changeset contains schema changes.
* @param args.overwriteFile - Indicates whether to override the file if it already exists. Default is false.
*/
writeToFile(args: {
fileName: string;
containsSchemaChanges: boolean;
overwriteFile?: boolean;
}): void;
/**
* Open local changes in iModel.
* @param args iModel and other options.
* @param args.db must be of type IModelDb
* @returns SqliteChangesetReader instance
*/
static openLocalChanges(args: Omit<SqliteChangesetReaderArgs, "db"> & {
db: IModelDb;
includeInMemoryChanges?: true;
}): SqliteChangesetReader;
/** check if schema check is disabled or not */
get disableSchemaCheck(): boolean;
/** Move to next change in changeset
* @returns true if there is current change false if reader is end of changeset.
* @beta
*/
step(): boolean;
/** Check if reader current on a row
* @beta
*/
get hasRow(): boolean;
/** Check if its current change is indirect
* @beta
*/
get isIndirect(): boolean;
/** Get count of columns in current change
* @beta
*/
get columnCount(): number;
/** Get operation that caused the change
* @beta
*/
get op(): SqliteChangeOp;
/** Get primary key value array
* @beta
*/
get primaryKeyValues(): SqliteValueArray;
/** Get primary key columns.
* @note To this to work db arg must be set when opening changeset file.
* @beta
*/
getPrimaryKeyColumnNames(): string[];
/** Get current change table.
* @beta
*/
get tableName(): string;
/**
* Get changed binary value for a column
* @param columnIndex index of column in current change
* @param stage old or new value for change.
* @returns value for changed column
* @beta
*/
getChangeValueType(columnIndex: number, stage: SqliteValueStage): DbValueType | undefined;
/**
* Get changed binary value for a column
* @param columnIndex index of column in current change
* @param stage old or new value for change.
* @returns value for changed column
* @beta
*/
getChangeValueBinary(columnIndex: number, stage: SqliteValueStage): Uint8Array | null | undefined;
/**
* Get changed double value for a column
* @param columnIndex index of column in current change
* @param stage old or new value for change.
* @returns value for changed column
* @beta
*/
getChangeValueDouble(columnIndex: number, stage: SqliteValueStage): number | null | undefined;
/**
* Get changed Id value for a column
* @param columnIndex index of column in current change
* @param stage old or new value for change.
* @returns value for changed column
* @beta
*/
getChangeValueId(columnIndex: number, stage: SqliteValueStage): Id64String | null | undefined;
/**
* Get changed integer value for a column
* @param columnIndex index of column in current change
* @param stage old or new value for change.
* @returns value for changed column
* @beta
*/
getChangeValueInteger(columnIndex: number, stage: SqliteValueStage): number | null | undefined;
/**
* Get changed text value for a column
* @param columnIndex index of column in current change
* @param stage old or new value for change.
* @returns value for changed column
* @beta
*/
getChangeValueText(columnIndex: number, stage: SqliteValueStage): string | null | undefined;
/**
* Check if change value is null
* @param columnIndex index of column in current change
* @param stage old or new value for change.
* @returns true if value is null
* @beta
*/
isColumnValueNull(columnIndex: number, stage: SqliteValueStage): boolean | undefined;
/**
* Get change value type
* @param columnIndex index of column in current change
* @param stage old or new value for change.
* @returns change value type
* @beta
*/
getColumnValueType(columnIndex: number, stage: SqliteValueStage): DbValueType | undefined;
/**
* Get changed value for a column
* @param columnIndex index of column in current change
* @param stage old or new value for change.
* @returns value for changed column
* @beta
*/
getChangeValue(columnIndex: number, stage: SqliteValueStage): SqliteValue;
/**
* Get all changed value in current change as array
* @param stage old or new values for current change.
* @returns array of values.
* @beta
*/
getChangeValuesArray(stage: SqliteValueStage): SqliteValueArray | undefined;
/**
* Get change as object and format its content.
* @param stage old or new value for current change.
* @param args change format options
* @returns return object or undefined
* @beta
*/
getChangeValuesObject(stage: SqliteValueStage, args?: ChangeFormatArgs): SqliteChange | undefined;
/**
* Get list of column for a table. This function also caches the result.
* @note To this to work db arg must be set when opening changeset file.
* @param tableName name of the table for which columns are requested.
* @returns columns of table.
* @beta
*/
getColumnNames(tableName: string): string[];
/** index of current change
* @beta
*/
get changeIndex(): number;
/**
* Close changeset
* @beta
*/
close(): void;
/**
* Dispose this object
* @beta
*/
[Symbol.dispose](): void;
}
export {};
//# sourceMappingURL=SqliteChangesetReader.d.ts.map