import type { BetterSqlite3Database, NativeDatabase } from '../types.js';
import { Repository } from './repository/base.js';
/** DB instance with optional advisory lock path. */
export type LockedDatabase = BetterSqlite3Database & {
    __lockPath?: string;
};
/**
 * Return the git worktree/repo root for the given directory (or cwd).
 * Uses `git rev-parse --show-toplevel` which returns the correct root
 * for both regular repos and git worktrees.
 * Results are cached per-process when called without arguments.
 * The cache is keyed on cwd so it invalidates if the working directory changes
 * (e.g. MCP server serving multiple sessions).
 */
export declare function findRepoRoot(fromDir?: string): string | null;
/** Reset the cached repo root (for testing). */
export declare function _resetRepoRootCache(): void;
export declare function acquireAdvisoryLock(dbPath: string): void;
export declare function releaseAdvisoryLock(lockPath: string): void;
export declare function openDb(dbPath: string): LockedDatabase;
export declare function closeDb(db: LockedDatabase): void;
/**
 * Synchronously close any DB handles queued by `closeDbDeferred()`.
 * Call before deleting DB files or in test teardown to avoid EBUSY on Windows.
 */
export declare function flushDeferredClose(): void;
/**
 * Schedule DB close on the next event loop tick. Useful for incremental
 * builds where the WAL checkpoint in db.close() is expensive (~250ms on
 * Windows) and doesn't need to block the caller.
 *
 * The advisory lock is released immediately so subsequent opens succeed.
 * The actual handle close (+ WAL checkpoint) happens asynchronously.
 * Call `flushDeferredClose()` before deleting the DB file.
 */
export declare function closeDbDeferred(db: LockedDatabase): void;
/** A better-sqlite3 handle optionally paired with a NativeDatabase. */
export interface LockedDatabasePair {
    db: LockedDatabase;
    nativeDb?: NativeDatabase;
}
/** Close both handles: NativeDatabase first (fast), then better-sqlite3 (releases lock). */
export declare function closeDbPair(pair: LockedDatabasePair): void;
/** Close NativeDatabase immediately, defer better-sqlite3 WAL checkpoint. */
export declare function closeDbPairDeferred(pair: LockedDatabasePair): void;
export declare function findDbPath(customPath?: string): string;
/** Open a database in readonly mode, with a user-friendly error if the DB doesn't exist. */
export declare function openReadonlyOrFail(customPath?: string): BetterSqlite3Database;
/**
 * Open a Repository from either an injected instance or a DB path.
 *
 * When `opts.repo` is a Repository instance, returns it directly (no DB opened).
 * When the native engine is available, opens a NativeDatabase (rusqlite) and
 * wraps it in NativeRepository. Otherwise falls back to better-sqlite3 via
 * SqliteRepository.
 */
export declare function openRepo(customDbPath?: string, opts?: {
    repo?: Repository;
    engine?: 'native' | 'wasm' | 'auto';
}): {
    repo: Repository;
    close(): void;
};
/**
 * Open a readonly DB with an optional NativeDatabase alongside it.
 *
 * Returns the better-sqlite3 handle (for backwards compat) plus an optional
 * NativeDatabase for modules that can use batched Rust query methods.
 * Callers should use nativeDb when available and fall back to db.prepare().
 */
export declare function openReadonlyWithNative(customPath?: string): {
    db: BetterSqlite3Database;
    nativeDb: NativeDatabase | undefined;
    close(): void;
};
//# sourceMappingURL=connection.d.ts.map