import { AsyncLocalStorage } from "node:async_hooks"; import { AnyMySqlSelectQueryBuilder, AnyMySqlTable } from "drizzle-orm/mysql-core"; import { ForgeSqlOrmOptions } from "../core"; import { MySqlSelectDynamic } from "drizzle-orm/mysql-core/query-builders/select.types"; /** * Interface representing the cache application context. * Stores information about tables that are being processed within a cache context. */ export interface CacheApplicationContext { /** Set of table names (in lowercase) that are being processed within the cache context */ tables: Set; } /** * Interface representing the local cache application context. * Stores cached query results in memory for the duration of a local cache context. * * @interface LocalCacheApplicationContext */ export interface LocalCacheApplicationContext { /** * Cache object mapping query hash keys to cached results * @property {Record} cache - Map of query keys to cached data */ cache: Record; } /** * AsyncLocalStorage instance for managing cache context across async operations. * This allows tracking which tables are being processed within a cache context * without explicitly passing context through function parameters. */ export declare const cacheApplicationContext: AsyncLocalStorage; /** * AsyncLocalStorage instance for managing local cache context across async operations. * This allows storing and retrieving cached query results within a local cache context * without explicitly passing context through function parameters. */ export declare const localCacheApplicationContext: AsyncLocalStorage; /** * Saves a table name to the current cache context if one exists. * This function is used to track which tables are being processed within * a cache context for proper cache invalidation. * * @param table - The Drizzle table schema to track * @returns Promise that resolves when the table is saved to context * * @example * ```typescript * await saveTableIfInsideCacheContext(usersTable); * ``` */ export declare function saveTableIfInsideCacheContext(table: T): Promise; export declare function saveQueryLocalCacheQuery>(query: T, rows: unknown[], options: ForgeSqlOrmOptions): Promise; /** * Retrieves a query result from the local cache context. * This function checks if a query result is already cached in memory. * * @param query - The Drizzle query to check for cached results * @param options - Option Property * @returns Promise that resolves to cached data if found, undefined otherwise * * @example * ```typescript * const query = db.select({ id: users.id, name: users.name }).from(users); * const cachedResult = await getQueryLocalCacheQuery(query); * if (cachedResult) { * return cachedResult; // Use cached data * } * // Execute query and cache result * ``` */ export declare function getQueryLocalCacheQuery>(query: T, options: ForgeSqlOrmOptions): Promise; /** * Evicts cached queries from the local cache context that involve the specified table. * This function removes cached query results that contain the given table name. * * @param table - The Drizzle table schema to evict cache for * @param options - ForgeSQL ORM options containing cache configuration * @returns Promise that resolves when cache eviction is complete * * @example * ```typescript * // After inserting/updating/deleting from users table * await evictLocalCacheQuery(usersTable, forgeSqlOptions); * // All cached queries involving users table are now removed * ``` */ export declare function evictLocalCacheQuery(table: T, options: ForgeSqlOrmOptions): Promise; /** * Checks if the given SQL query contains any tables that are currently being processed * within a cache context. This is used to determine if cache should be bypassed * for queries that affect tables being modified within the context. * * @param sql - The SQL query string to check * @param options - ForgeSQL ORM options containing cache configuration * @returns Promise that resolves to true if the SQL contains tables in cache context * * @example * ```typescript * const shouldBypassCache = await isTableContainsTableInCacheContext( * "SELECT * FROM users WHERE id = 1", * forgeSqlOptions * ); * ``` */ export declare function isTableContainsTableInCacheContext(sql: string, options: ForgeSqlOrmOptions): Promise; //# sourceMappingURL=cacheContextUtils.d.ts.map