import { DBListenerManager } from './DBListenerManager'; /** * Object returned by SQL Query executions { * insertId: Represent the auto-generated row id if applicable * rowsAffected: Number of affected rows if result of a update query * message: if status === 1, here you will find error description * rows: if status is undefined or 0 this object will contain the query results * } * * @interface QueryResult */ export type QueryResult = { insertId?: number; rowsAffected: number; rows?: { /** Raw array with all dataset */ _array: any[]; /** The lengh of the dataset */ length: number; /** A convenience function to acess the index based the row object * @param idx the row index * @returns the row structure identified by column names */ item: (idx: number) => any; }; /** * Query metadata, avaliable only for select query results */ metadata?: ColumnMetadata[]; }; /** * Column metadata * Describes some information about columns fetched by the query */ export type ColumnMetadata = { /** The name used for this column for this resultset */ columnName: string; /** The declared column type for this column, when fetched directly from a table or a View resulting from a table column. "UNKNOWN" for dynamic values, like function returned ones. */ columnDeclaredType: string; /** * The index for this column for this resultset*/ columnIndex: number; }; /** * Allows the execution of bulk of sql commands * inside a transaction * If a single query must be executed many times with different arguments, its preferred * to declare it a single time, and use an array of array parameters. */ export type SQLBatchTuple = [string] | [string, Array | Array>]; /** * status: 0 or undefined for correct execution, 1 for error * message: if status === 1, here you will find error description * rowsAffected: Number of affected rows if status == 0 */ export type BatchQueryResult = { rowsAffected?: number; }; /** * Result of loading a file and executing every line as a SQL command * Similar to BatchQueryResult */ export interface FileLoadResult extends BatchQueryResult { commands?: number; } export declare enum RowUpdateType { SQLITE_INSERT = 18, SQLITE_DELETE = 9, SQLITE_UPDATE = 23 } export interface TableUpdateOperation { opType: RowUpdateType; rowId: number; } export interface UpdateNotification extends TableUpdateOperation { table: string; } export interface BatchedUpdateNotification { rawUpdates: UpdateNotification[]; tables: string[]; groupedUpdates: Record; } export type UpdateCallback = (update: UpdateNotification) => void; export type BatchedUpdateCallback = (update: BatchedUpdateNotification) => void; export declare enum TransactionEvent { COMMIT = 0, ROLLBACK = 1 } export type TransactionCallback = (eventType: TransactionEvent) => void; export type ContextLockID = string; export declare enum ConcurrentLockType { READ = 0, WRITE = 1 } export type OpenOptions = { location?: string; /** * The number of concurrent read connections to use. * Setting this value to zero will only open a single write connection. * Setting this value > 0 will open the DB in WAL mode with [numReadConnections] * read connections and a single write connection. This allows for concurrent * read operations during a write operation. */ numReadConnections?: number; }; export type Open = (dbName: string, options?: OpenOptions) => QuickSQLiteConnection; export interface ISQLite { open: Open; close: (dbName: string) => void; delete: (dbName: string, location?: string) => void; refreshSchema: (dbName: string) => Promise; requestLock: (dbName: string, id: ContextLockID, type: ConcurrentLockType) => QueryResult; releaseLock(dbName: string, id: ContextLockID): void; executeInContext: (dbName: string, id: ContextLockID, query: string, params: any[]) => Promise; attach: (mainDbName: string, dbNameToAttach: string, alias: string, location?: string) => void; detach: (mainDbName: string, alias: string) => void; executeBatch: (dbName: string, commands: SQLBatchTuple[], id: ContextLockID) => Promise; loadFile: (dbName: string, location: string, id: ContextLockID) => Promise; } export interface LockOptions { timeoutMs?: number; } export interface LockContext { execute: (sql: string, args?: any[]) => Promise; } export interface TransactionContext extends LockContext { commit: () => Promise; rollback: () => Promise; } export type QuickSQLiteConnection = { close: () => void; refreshSchema: () => Promise; execute: (sql: string, args?: any[]) => Promise; readLock: (callback: (context: LockContext) => Promise, options?: LockOptions) => Promise; readTransaction: (callback: (context: TransactionContext) => Promise, options?: LockOptions) => Promise; writeLock: (callback: (context: LockContext) => Promise, options?: LockOptions) => Promise; writeTransaction: (callback: (context: TransactionContext) => Promise, options?: LockOptions) => Promise; delete: () => void; /** * The attach method should only be called if there are no active locks/transactions. */ attach: (dbNameToAttach: string, alias: string, location?: string) => void; /** * The detach method should only be called if there are no active locks/transactions. */ detach: (alias: string) => void; executeBatch: (commands: SQLBatchTuple[]) => Promise; loadFile: (location: string) => Promise; /** * Register a callback which will be fired for each ROWID table change event. * Table changes are reported immediately. * Changes might not yet be committed if using a transaction. * - Listen to transaction events in listenerManager if extra logic is required * For most use cases use `registerTablesChangedHook` instead. * @returns a function which will deregister the callback */ registerUpdateHook(callback: UpdateCallback): () => void; /** * Register a callback which will be fired whenever a update to a ROWID table * has been committed. * Changes inside write locks will be buffered until the lock is released or * if a transaction inside the lock has been committed. * Reverting a transaction inside a write lock will not fire table updates. * @returns a function which will deregister the callback */ registerTablesChangedHook(callback: BatchedUpdateCallback): () => void; listenerManager: DBListenerManager; }; //# sourceMappingURL=types.d.ts.map