export interface SybaseConnectionConfig {
    host: string;
    port: number;
    database: string;
    username: string;
    password: string;
    /** Connection/query timeout in seconds. Default: 30 */
    timeout?: number;
    /**
     * TDS network packet size in bytes. Larger values reduce round-trips
     * for big result sets. Default: 4096 (FreeTDS default is 512).
     */
    packetSize?: number;
    /**
     * Hard timeout for individual queries in ms. Acts as a last-resort
     * watchdog if db-lib's cooperative timeout fails to abort a stuck I/O
     * (e.g. server unresponsive after CANCEL). When this fires, the query
     * rejects with a timeout error and the connection is marked dead so the
     * pool replaces it.
     *
     * Defaults to `max(2 * timeout * 1000, 30000)` on the native side.
     */
    hardTimeoutMs?: number;
}
export interface SybasePoolConfig extends SybaseConnectionConfig {
    /** Maximum connections in pool. Default: 5 */
    max?: number;
    /** Connection idle timeout in ms. Default: 60000 (60s) */
    idleTimeoutMs?: number;
    /** Connection acquire timeout in ms. Default: 10000 (10s) */
    acquireTimeoutMs?: number;
    /** How often to run idle cleanup in ms. Default: 30000 (30s) */
    cleanupIntervalMs?: number;
    /** Enable health check ping before returning connection from pool. Default: false */
    healthCheck?: boolean;
    /** Max retries for transient connection failures. Default: 2 */
    retries?: number;
    /** Delay between retries in ms. Default: 500 */
    retryDelayMs?: number;
    /** Query logger callback. Called for every query executed through the pool. */
    logger?: SybaseLogger;
}
export interface QueryResult<T = Record<string, unknown>> {
    rows: T[];
    columns: string[];
    rowCount: number;
    affectedRows: number;
}
/**
 * Query log entry passed to the logger callback.
 */
export interface SybaseQueryLog {
    /** The SQL string that was executed. */
    sql: string;
    /** Execution duration in milliseconds. */
    durationMs: number;
    /** Number of rows returned/affected. */
    rowCount: number;
    /** Whether the query resulted in an error. */
    error?: Error;
    /** Timestamp when the query started. */
    timestamp: Date;
}
/**
 * Logger interface for query observability.
 *
 * @example
 * ```ts
 * const logger: SybaseLogger = {
 *   query(log) {
 *     console.log(`[${log.durationMs}ms] ${log.sql}`);
 *   }
 * };
 * ```
 */
export interface SybaseLogger {
    /** Called after every query execution (success or failure). */
    query(log: SybaseQueryLog): void;
}
/**
 * Observable pool metrics for monitoring.
 */
export interface SybasePoolMetrics {
    /** Total connections ever created. */
    totalConnectionsCreated: number;
    /** Total connections that have been destroyed. */
    totalConnectionsDestroyed: number;
    /** Total queries executed through the pool. */
    totalQueriesExecuted: number;
    /** Total query errors encountered. */
    totalQueryErrors: number;
    /** Total acquire timeouts. */
    totalAcquireTimeouts: number;
    /** Average query duration in ms (rolling). */
    avgQueryDurationMs: number;
    /** Current pool size. */
    currentSize: number;
    /** Current active (in-use) connections. */
    currentActive: number;
    /** Current idle connections. */
    currentIdle: number;
    /** Current queue length. */
    currentWaiting: number;
}
/**
 * A single Sybase connection wrapping the native FreeTDS handle.
 *
 * Normally you won't use this directly — use `SybasePool` instead.
 * This class manages the lifecycle of a single db-lib connection.
 */
export declare class SybaseConnection {
    private readonly config;
    private handle;
    private closed;
    private inUse;
    /** Promise queue to serialize queries on a single DBPROCESS (not thread-safe). */
    private queryQueue;
    constructor(config: SybaseConnectionConfig);
    connect(): Promise<void>;
    query<T = Record<string, unknown>>(sql: string, options?: {
        maxRows?: number;
        hardTimeoutMs?: number;
    }): Promise<QueryResult<T>>;
    private executeQuery;
    close(): void;
    get isConnected(): boolean;
    /** @internal */
    get _inUse(): boolean;
    /** @internal */
    set _inUse(val: boolean);
}
/**
 * Production-grade connection pool for Sybase ASE.
 *
 * Features:
 * - max pool sizing with automatic scaling
 * - Health checks (dead connection detection + optional ping)
 * - Idle connection cleanup
 * - Acquire timeout with fair queuing
 * - Retry on transient connection failures
 * - Graceful drain/shutdown
 * - Observable metrics for monitoring
 * - Query logging middleware
 *
 * @example
 * ```ts
 * const pool = new SybasePool({
 *   host: "sybase-host",
 *   port: 5000,
 *   database: "mydb",
 *   username: "sa",
 *   password: "secret",
 *   max: 10,
 *   logger: { query(log) { console.log(`[${log.durationMs}ms] ${log.sql}`); } }
 * });
 *
 * const result = await pool.query("SELECT 1 AS val");
 * console.log(pool.metrics);
 * await pool.drain();
 * ```
 */
export declare class SybasePool {
    private pool;
    private waitQueue;
    private closed;
    private draining;
    private cleanupTimer;
    private readonly cfg;
    private _totalConnectionsCreated;
    private _totalConnectionsDestroyed;
    private _totalQueriesExecuted;
    private _totalQueryErrors;
    private _totalAcquireTimeouts;
    private _queryDurationSum;
    private _queryDurationCount;
    private _activeCount;
    /** Number of connections currently being created (prevents exceeding max). */
    private _pendingCreates;
    constructor(config: SybasePoolConfig);
    /**
     * Acquire a connection from the pool.
     * - Validates existing connections (health check)
     * - Creates new connections up to `max`
     * - Queues if pool is full
     */
    acquire(): Promise<SybaseConnection>;
    /**
     * Release a connection back to the pool.
     */
    release(conn: SybaseConnection): void;
    /**
     * Execute a query using a pooled connection (auto acquire/release).
     * Retries on transient connection failures.
     */
    query<T = Record<string, unknown>>(sql: string, options?: {
        maxRows?: number;
        hardTimeoutMs?: number;
    }): Promise<QueryResult<T>>;
    /**
     * Gracefully drain the pool — finish all in-flight operations, then close.
     *
     * New acquire() calls will be rejected immediately.
     * Returns a promise that resolves when all active connections are released.
     *
     * @param timeoutMs - Maximum time to wait for drain. Default: 30000ms
     */
    drain(timeoutMs?: number): Promise<void>;
    private _drainResolve?;
    private checkDrainComplete;
    /**
     * Close all connections and shut down the pool.
     */
    close(): Promise<void>;
    /** Number of total connections in the pool. */
    get size(): number;
    /** Number of idle (available) connections. */
    get idle(): number;
    /** Number of active (in-use) connections. */
    get active(): number;
    /** Number of waiters in queue. */
    get waiting(): number;
    /** Whether the pool is currently draining. */
    get isDraining(): boolean;
    /** Whether the pool is closed. */
    get isClosed(): boolean;
    /** @internal Get the configured logger (if any). */
    get logger(): SybaseLogger | undefined;
    /**
     * Get a snapshot of pool metrics for monitoring/observability.
     */
    get metrics(): SybasePoolMetrics;
    private createConnection;
    private removeFromPool;
    private serveWaiter;
    /**
     * Remove idle connections that have exceeded the idle timeout.
     */
    private cleanupIdle;
    private delay;
}
//# sourceMappingURL=connection.d.ts.map