/**
 * Database Connection Layer for Drizzle ORM
 * Provides PostgreSQL connection with pooling, SSL support, and read replicas
 * Matches Sequelize database configuration for parity
 */
import { drizzle, PostgresJsDatabase } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';
import type { Transaction as TransactionType } from '../types/internal.js';
declare global {
    var __baasix_db: ReturnType<typeof drizzle> | null;
    var __baasix_sql: ReturnType<typeof postgres> | null;
    var __baasix_readSql: ReturnType<typeof postgres> | null;
}
type DrizzleDb = ReturnType<typeof drizzle>;
export type TransactionClient = Parameters<Parameters<DrizzleDb['transaction']>[0]>[0];
export type Transaction = TransactionType;
/**
 * Initialize database connection
 * Synchronous function that starts async cache initialization
 */
export declare function initializeDatabase(): PostgresJsDatabase<Record<string, unknown>>;
/**
 * Initialize database with cache service (async version)
 * Use this when you need to ensure cache is ready before proceeding
 */
export declare function initializeDatabaseWithCache(): Promise<PostgresJsDatabase<Record<string, unknown>>>;
/**
 * Get database instance (synchronous - initializes if needed)
 */
export declare function getDatabase(): PostgresJsDatabase<Record<string, unknown>>;
export declare const db: PostgresJsDatabase<Record<string, unknown>>;
/**
 * Get postgres SQL client (for raw queries)
 */
export declare function getSqlClient(): postgres.Sql<{}>;
export declare const sqlClient: ReturnType<typeof postgres>;
/**
 * Get read replica SQL client (if configured)
 */
export declare function getReadSqlClient(): postgres.Sql<{}>;
/**
 * Close database connections
 */
export declare function closeDatabase(): Promise<void>;
/**
 * Create a new transaction with Sequelize-compatible API
 * Returns a transaction that must be explicitly committed or rolled back
 *
 * Usage matching Sequelize:
 *   const transaction = await createTransaction();
 *   try {
 *     await transaction.insert(table).values(data);
 *     await transaction.commit();
 *   } catch (error) {
 *     await transaction.rollback();
 *     throw error;
 *   }
 */
export declare function createTransaction(): Promise<Transaction>;
/**
 * Test database connection
 */
export declare function testConnection(): Promise<boolean>;
/**
 * Get PostgreSQL server version
 * Returns { major: number, minor: number, full: string }
 * Caches the result after first call
 */
export declare function getPostgresVersion(): Promise<{
    major: number;
    minor: number;
    full: string;
}>;
/**
 * Check if PostgreSQL version supports a feature
 * @param minMajor Minimum major version required
 * @param minMinor Minimum minor version required (default: 0)
 */
export declare function isPgVersionAtLeast(minMajor: number, minMinor?: number): Promise<boolean>;
/**
 * Get helper to extract instance ID
 */
export declare function getInstanceId(instance: any): any;
declare const _default: {
    db: PostgresJsDatabase<Record<string, unknown>>;
    sql: postgres.Sql<{}>;
    initializeDatabase: typeof initializeDatabase;
    initializeDatabaseWithCache: typeof initializeDatabaseWithCache;
    getDatabase: typeof getDatabase;
    getSqlClient: typeof getSqlClient;
    getReadSqlClient: typeof getReadSqlClient;
    closeDatabase: typeof closeDatabase;
    createTransaction: typeof createTransaction;
    testConnection: typeof testConnection;
    getInstanceId: typeof getInstanceId;
    getPostgresVersion: typeof getPostgresVersion;
    isPgVersionAtLeast: typeof isPgVersionAtLeast;
};
export default _default;
export { getCacheService, closeCacheService, initializeCacheService } from '../services/CacheService.js';
//# sourceMappingURL=db.d.ts.map