import type { CacheDependency } from '../interfaces'; /** * Options for DbDependency */ export interface DbDependencyOptions { /** * Name for this dependency (used in cache key generation) * Default: 'db' */ name?: string; /** * Data source name to use for querying * If not specified, uses the default data source */ dataSourceName?: string; } /** * Database-based cache dependency * * This dependency monitors database query results. When the query result changes, * the cache becomes invalid. * * Common use case: Monitor MAX(updated_at) or COUNT(*) to detect data changes. * * @example * ```typescript * // Invalidate cache when user data changes * @Cacheable({ * key: (id) => `user:${id}:profile`, * dependencies: [ * new DbDependency( * 'SELECT updated_at FROM users WHERE id = ?', * (id) => [id] * ) * ] * }) * async getUserProfile(id: string) { } * * // Invalidate when any user in tenant changes * @Cacheable({ * key: (tenantId) => `users:list:${tenantId}`, * dependencies: [ * new DbDependency( * 'SELECT MAX(updated_at) FROM users WHERE tenant_id = ?', * (tenantId) => [tenantId] * ) * ] * }) * async getUserList(tenantId: string) { } * * // Use specific data source * @Cacheable({ * key: (id) => `product:${id}:details`, * dependencies: [ * new DbDependency( * 'SELECT updated_at FROM products WHERE id = ?', * (id) => [id], * { dataSourceName: 'readReplicas' } * ) * ] * }) * async getProductDetails(id: string) { } * * // With custom name and data source * new DbDependency( * 'SELECT COUNT(*) FROM events', * [], * { name: 'eventCount', dataSourceName: 'analytics' } * ) * ``` */ export declare class DbDependency implements CacheDependency { private readonly sql; private readonly paramsFactory?; private readonly options?; private static fallbackDataSource; private static defaultDataSourceName; constructor(sql: string, paramsFactory?: (...args: any[]) => any[], options?: DbDependencyOptions); /** * Get DataSource for executing queries * Priority: 1. Specific dataSourceName from options, 2. Default from getDataSourceByName, 3. Fallback */ private getDataSource; getKey(): string; getData(): Promise; isChanged(oldData: any): Promise; /** * Simple hash code generation for strings */ private hashCode; }