UNPKG

@sqb/connect

Version:

Multi-dialect database connection framework written with TypeScript

117 lines (116 loc) 3.43 kB
import { Adapter } from './adapter.js'; import { CursorStream, CursorStreamOptions } from './cursor-stream.js'; import { FieldInfoMap } from './field-info-map.js'; import { SqbConnection } from './sqb-connection.js'; import { ObjectRow, QueryRequest } from './types.js'; interface CursorEvents { close: () => void; error: (error: unknown) => void; eof: () => void; reset: () => void; move: (row: any, rowNum: number) => void; fetch: (row: any, rowNum: number) => void; } declare const Cursor_base: import("strict-typed-events").Type<import("strict-typed-events").TypedEventEmitter<any, CursorEvents, CursorEvents>>; export declare class Cursor extends Cursor_base { private readonly _connection; private readonly _fields; private readonly _prefetchRows; private readonly _request; private _intlcur?; private _taskQueue; private _fetchCache; private _rowNum; private _fetchedAll; private _fetchedRows; private _row; private _cache?; constructor(connection: SqbConnection, fields: FieldInfoMap, adapterCursor: Adapter.Cursor, request: QueryRequest); /** * Returns the Connection instance */ get connection(): SqbConnection; /** * Returns if cursor is before first record. */ get isBof(): boolean; /** * Returns if cursor is closed. */ get isClosed(): boolean; /** * Returns if cursor is after last record. */ get isEof(): boolean; /** * Returns number of fetched record count from database. */ get fetchedRows(): number; /** * Returns object instance which contains information about fields. */ get fields(): FieldInfoMap; /** * Returns current row */ get row(): any; /** * Returns current row number. */ get rowNum(): number; /** * Enables cache */ cached(): void; /** * Closes cursor */ close(): Promise<void>; /** * If cache is enabled, this call fetches and keeps all records in the internal cache. * Otherwise it throws error. Once all all records fetched, * you can close Cursor safely and can continue to use it in memory. * Returns number of fetched rows */ fetchAll(): Promise<number>; /** * Moves cursor to given row number. * cursor can move both forward and backward if cache enabled. * Otherwise it throws error. */ moveTo(rowNum: number): Promise<ObjectRow>; /** * Moves cursor forward by one row and returns that row. * And also it allows iterating over rows easily. */ next(): Promise<ObjectRow>; /** * Moves cursor back by one row and returns that row. * And also it allows iterating over rows easily. */ prev(): Promise<ObjectRow>; /** * Moves cursor before first row. (Required cache enabled) */ reset(): void; /** * Moves cursor by given step. If caching is enabled, * cursor can move both forward and backward. Otherwise it throws error. */ seek(step: number): Promise<ObjectRow>; /** * Creates and returns a readable stream. */ toStream(options?: CursorStreamOptions): CursorStream; toString(): string; inspect(): string; /** * */ _seek(step: number, silent?: boolean): Promise<number>; /** * */ _fetchRows(): Promise<void>; } export {};