import * as tls from "node:tls"; import { type ColumnDef, type ExternalTableData, RecordBatch } from "@maxjustus/chttp/native"; import type { ClickHouseSettings } from "../settings.ts"; import { type CollectableAsyncGenerator } from "../util.ts"; import { type Packet, type ServerHello } from "./types.ts"; import type { QueryParamValue } from "../types.ts"; export type { CollectableAsyncGenerator } from "../util.ts"; export type { QueryParamValue } from "../types.ts"; export interface TcpClientOptions { host: string; port: number; database?: string; user?: string; password?: string; debug?: boolean; /** Compression: 'lz4', 'zstd', or false to disable */ compression?: "lz4" | "zstd" | false; /** Connection timeout in ms (default: 10000) */ connectTimeout?: number; /** Query timeout in ms (default: 30000) */ queryTimeout?: number; /** Keep-alive interval in ms. 0 or undefined = disabled. */ keepAliveIntervalMs?: number; /** TLS options. true for defaults, or tls.ConnectionOptions for custom config. */ tls?: boolean | tls.ConnectionOptions; /** Grace period in ms after sending CANCEL before forceful socket close (default: 2000) */ cancelGracePeriodMs?: number; /** Default settings applied to all queries and inserts (can be overridden per-call) */ settings?: ClickHouseSettings; } export interface ColumnSchema { name: string; type: string; } export interface InsertOptions { signal?: AbortSignal; /** Batch size for row object mode (default: 10000) */ batchSize?: number; /** Optional schema to validate against server schema */ schema?: ColumnDef[]; /** Per-insert settings (merged with client defaults, overrides them) */ settings?: ClickHouseSettings; /** Custom query ID for tracking in system.query_log and KILL QUERY */ queryId?: string; } export type { ExternalTableData }; export interface QueryOptions { /** Per-query settings (merged with client defaults, overrides them) */ settings?: ClickHouseSettings; /** * Query parameters (substitution values). Supports scalars and complex types. * Type is inferred from the query's {name: Type} syntax. * ```typescript * { arr: [1, 2, 3] } // Array(UInt32) * { tags: ['foo', 'bar'] } // Array(String) * { m: { a: 1, b: 2 } } // Map(String, UInt32) * { t: [1, 'hello'] } // Tuple(UInt32, String) - arrays work for tuples * ``` */ params?: Record; signal?: AbortSignal; /** External tables to send with the query (available as temporary tables in the SQL) */ externalTables?: Record; /** Custom query ID for tracking in system.query_log and KILL QUERY */ queryId?: string; } export declare class TcpClient { private socket; private reader; private writer; private options; private defaultSettings; private _serverHello; private currentSchema; private sessionTimezone; private busy; private log; /** Write with backpressure - waits for drain if socket buffer is full */ private writeWithBackpressure; /** Server info from handshake, available after connect() */ get serverHello(): ServerHello | null; private ensureConnected; /** Session timezone, updated by server TimezoneUpdate packets */ get timezone(): string | null; constructor(options: TcpClientOptions); connect(options?: { signal?: AbortSignal; }): Promise; private handshake; /** Insert a single RecordBatch. */ insert(sql: string, data: RecordBatch, options?: InsertOptions): CollectableAsyncGenerator; /** Insert an iterable of RecordBatches. */ insert(sql: string, data: Iterable | AsyncIterable, options?: InsertOptions): CollectableAsyncGenerator; /** * Insert row objects with auto-coercion using server schema. * * By default with `INSERT INTO table VALUES`, all columns must be provided. * To omit columns and use server DEFAULT expressions, specify an explicit column list: * ```typescript * client.insert("INSERT INTO table (col1, col2) VALUES", rows) * ``` * Only the specified columns will be sent; omitted columns use their server-side defaults. */ insert(sql: string, data: Iterable> | AsyncIterable>, options?: InsertOptions): CollectableAsyncGenerator; private insertImpl; /** * Send INSERT query and wait for schema response from server. * Returns the schema (column definitions) for the target table. */ private sendInsertQueryAndGetSchema; private readProgress; private readProfileInfo; private parseLogBlock; private createAccumulators; private accumulateProgress; private processProfileEventsBlock; private readBlock; query(sql: string, options?: QueryOptions): CollectableAsyncGenerator; private queryImpl; /** Encode a RecordBatch as a Data packet with the given table name. */ private encodeBatchAsDataPacket; /** Send external tables as Data packets before the query delimiter. */ private sendExternalTables; /** Drain remaining packets until EndOfStream or Exception. Used when query is abandoned early. */ private drainPackets; /** * Send a ping packet and wait for pong response. * Useful for checking connection health. */ ping(): Promise; private startKeepAliveTimer; close(): void; /** * Async disposable support for "await using" syntax. * Automatically closes connection when scope exits. */ [Symbol.asyncDispose](): Promise; /** * Static factory that connects and returns a disposable client. * Usage: await using client = await TcpClient.connect(options); */ static connect(options: TcpClientOptions, connectOptions?: { signal?: AbortSignal; }): Promise; } //# sourceMappingURL=client.d.ts.map