@imqueue/pg-cache
Version:
PostgreSQL managed cache on Redis for @imqueue-based service methods
33 lines (32 loc) • 3.17 kB
TypeScript
/*!
* I'm Queue Software Project
* Copyright (C) 2025 imqueue.com <support@imqueue.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* If you want to use this code in a closed source (commercial) project, you can
* purchase a proprietary commercial license. Please contact us at
* <support@imqueue.com> to get commercial licensing options.
*/
import { ILogger } from '@imqueue/core';
import { PgCacheable } from './PgCache';
export type ClassDecorator = <T extends new (...args: any[]) => {}>(constructor: T) => T & PgCacheable;
export type MethodDecorator = (target: any, methodName: string | symbol, descriptor: TypedPropertyDescriptor<(...args: any[]) => any>) => void;
export declare const DEFAULT_CACHE_TTL = 86400000;
export declare const PG_CACHE_DEBUG: boolean;
export declare const PG_CACHE_TRIGGER = "CREATE FUNCTION post_change_notify_trigger()\nRETURNS TRIGGER\nLANGUAGE plpgsql\nAS $$\nDECLARE\n rec RECORD;\n payload TEXT;\n payload_items TEXT[];\n column_names TEXT[];\n column_name TEXT;\n column_value TEXT;\n channel CHARACTER VARYING(255);\nBEGIN\n channel := TG_TABLE_NAME;\n\n CASE TG_OP\n WHEN 'INSERT', 'UPDATE' THEN rec := NEW;\n WHEN 'DELETE' THEN rec := OLD;\n ELSE RAISE EXCEPTION 'NOTIFY: Invalid operation \"%\"!',\n TG_OP;\n END CASE;\n\n SELECT array_agg(\"c\".\"column_name\"::TEXT)\n INTO column_names\n FROM \"information_schema\".\"columns\" AS \"c\"\n WHERE \"c\".\"table_name\" = TG_TABLE_NAME;\n\n FOREACH column_name IN ARRAY column_names\n LOOP\n EXECUTE FORMAT('SELECT $1.%I::TEXT', column_name)\n INTO column_value\n USING rec;\n\n payload_items := ARRAY_CAT(\n payload_items,\n ARRAY [column_name, column_value]\n );\n END LOOP;\n\n payload := json_build_object(\n 'timestamp', CURRENT_TIMESTAMP,\n 'operation', TG_OP,\n 'schema', TG_TABLE_SCHEMA,\n 'table', TG_TABLE_NAME,\n 'record', TO_JSON(JSON_OBJECT(payload_items))\n );\n\n PERFORM PG_NOTIFY(channel, payload);\n\n RETURN rec;\nEND;\n$$;\n";
export declare function setInfo(logger: ILogger, res: any, key: string, decorator: Function): any;
export declare function setError(logger: ILogger, err: any, key: string, decorator: Function): void;
export declare function fetchError(logger: ILogger, err: any, key: string, decorator: Function): void;
export declare function initError(logger: ILogger, className: string, methodName: string, decorator: Function): void;