prorm API Reference
    Preparing search index...

    Class AuditLogger

    AuditLogger - Provides persistent audit logging for model changes

    const auditLogger = new AuditLogger(prorm);
    await auditLogger.setupHooks();

    // Manually log an action
    await auditLogger.logAction('CREATE', 'User', 1, {}, { name: 'John' });

    // Get audit history
    const history = await auditLogger.getHistory('User', 1);
    Index
    • Log an audit action

      Parameters

      • action: "UPDATE" | "DELETE" | "CREATE"

        The type of action (CREATE, UPDATE, DELETE)

      • tableName: string

        The name of the table

      • recordId: string | number

        The primary key of the record

      • OptionaloldValues: Record<string, any>

        The previous values (for UPDATE/DELETE)

      • OptionalnewValues: Record<string, any>

        The new values (for CREATE/UPDATE)

      Returns Promise<void>

    • Get audit history for a table and optional record

      Parameters

      • tableName: string

        The name of the table

      • OptionalrecordId: string | number

        Optional record ID to filter by

      • Optionaloptions: { limit?: number; offset?: number; startDate?: Date; endDate?: Date }

        Query options

      Returns Promise<AuditLog[]>

    • Setup hooks for all models to automatically log changes

      This method iterates through all registered models and adds beforeCreate, beforeUpdate, and beforeDestroy hooks

      Returns void