UNPKG

@ibm/mapepire-js

Version:
180 lines (179 loc) 6.5 kB
/// <reference types="node" /> import { EventEmitter } from "stream"; import WebSocket from "ws"; import { Query } from "./query"; import { ConnectionResult, DaemonServer, ExplainResults, GetTraceDataResult, JDBCOptions, JobLogEntry, QueryOptions, ServerTraceDest, ServerTraceLevel, SetConfigResult, ServerRequest, VersionCheckResult } from "./types"; import { ExplainType, JobStatus, TransactionEndType } from "./states"; export declare const DEFAULT_PORT = 8076; /** * Represents a SQL job that manages connections and queries to a database. */ export declare class SQLJob { options: JDBCOptions; /** * A counter to generate unique IDs for each SQLJob instance. */ protected static uniqueIdCounter: number; private socket; protected responseEmitter: EventEmitter; protected status: JobStatus; protected traceFile: string | undefined; protected isTracingChannelData: boolean; protected uniqueId: string; id: string | undefined; /** * Generates a new unique ID with an optional prefix. * * @param prefix - An optional prefix for the unique ID. * @returns A unique ID string. */ static getNewUniqueId(prefix?: string): string; /** * Constructs a new SQLJob instance with the specified options. * * @param options - The options for configuring the SQL job. */ constructor(options?: JDBCOptions); /** * Enables local tracing of the channel data. */ enableLocalTrace(): void; /** * Establishes a WebSocket connection to the specified DB2 server. * * @param db2Server - The server details for the connection. * @returns A promise that resolves to the WebSocket instance. */ private getChannel; /** * Sends a message to the connected database server. * * @param content - The message content to send. * @returns A promise that resolves to the server's response. */ send<T>(content: ServerRequest): Promise<T>; /** * Retrieves the current status of the job. * * @returns The current status of the job. */ getStatus(): JobStatus; /** * Gets the count of ongoing requests for the job. * * @returns The number of ongoing requests. */ getRunningCount(): number; /** * Connects to the specified DB2 server and initializes the SQL job. * * @param db2Server - The server details for the connection. * @returns A promise that resolves to the connection result. */ connect(db2Server: DaemonServer): Promise<ConnectionResult>; /** * Creates a query object for the specified SQL statement. * * @param sql - The SQL statement to query. * @param opts - Optional settings for the query. * @returns A new Query instance. */ query<T>(sql: string, opts?: QueryOptions): Query<T>; /** * Executes an SQL command and returns the result. * * @param sql - The SQL command to execute. * @param opts - Optional settings for the command. * @returns A promise that resolves to the command execution result. */ execute<T>(sql: string, opts?: QueryOptions): Promise<import("./types").QueryResult<T>>; /** * Retrieves the version information from the database server. * * @returns A promise that resolves to the version check result. */ getVersion(): Promise<VersionCheckResult>; /** * Explains a SQL statement and returns the results. * @param statement - The SQL statement to explain. * @param type - The type of explain to perform (default is ExplainType.Run). * @returns A promise that resolves to the explain results. */ explain<T>(statement: string, type?: ExplainType): Promise<ExplainResults<T>>; /** * Retrieves the file path of the trace file, if available. * * @returns The trace file path or undefined. */ getTraceFilePath(): string | undefined; /** * Retrieves trace data from the backend. * * @returns A promise that resolves to the trace data result. */ getTraceData(): Promise<GetTraceDataResult>; /** * Configures the trace options on the backend. * * @param dest - The destination for the trace data. * @param level - The level of tracing to apply. * @returns A promise that resolves to the result of the configuration. */ setTraceConfig(dest: ServerTraceDest, level: ServerTraceLevel): Promise<SetConfigResult>; /** * Creates a command-line SQL query. * * @param cmd - The command-line SQL command to execute. * @returns A new Query instance for the command. */ clcommand(cmd: string): Query<any>; /** * Checks if the job is under commit control based on the transaction isolation level. * * @returns A boolean indicating if the job is under commit control. */ underCommitControl(): boolean; /** * Retrieves the count of pending transactions. * * @returns A promise that resolves to the count of pending transactions. */ getPendingTransactions(): Promise<number>; /** * Ends the current transaction by committing or rolling back. * * @param type - The type of transaction ending (commit or rollback). * @returns A promise that resolves to the result of the transaction operation. */ endTransaction(type: TransactionEndType): Promise<import("./types").QueryResult<JobLogEntry>>; /** * Retrieves the unique ID assigned to this SQLJob instance. * * @returns The unique ID. */ getUniqueId(): string; /** * Closes the SQL job and cleans up resources. */ close(): Promise<void>; /** * Retrieves the WebSocket instance associated with the SQL job. * Normally the user should not access the socket directly, * but this is useful for testing scenarios like unexpected socket close, etc. * * @returns The WebSocket instance. */ getSocket(): WebSocket; /** * Disposes of the resources associated with the SQL job. */ private dispose; } /** * Converts a database URI into a DaemonServer object. * * @param uri - The URI representing the database connection details. * @returns A DaemonServer object containing the parsed details. * @throws An error if the URI has an invalid protocol or missing required fields. */ export declare function UrlToDaemon(uri: string): DaemonServer;