Posts

Showing posts with the label TypeORM

Fix: How to get updated column using typeorm EventSubscriber afterTransactionCommit?

 In TypeORM, you can use an `EventSubscriber` to listen for various database events, including events that occur after a transaction commit. To get the updated columns after a transaction commit, you can utilize the `afterTransactionCommit` event. Here's how you can achieve this: 1. **Create an EventSubscriber**:    First, create an `EventSubscriber` class that listens for the `afterTransactionCommit` event.    ```typescript    import { EventSubscriber, EntitySubscriberInterface, EventSubscriberInterface, InsertEvent, UpdateEvent, RemoveEvent, Entity, EntityManager } from 'typeorm';    @EventSubscriber()    export class YourEventSubscriber implements EntitySubscriberInterface<Entity> {        constructor(            private readonly entityManager: EntityManager,        ) {            this.entityManager = entityManager;            this.entityManager.registerSubscriber(this);        }        listenTo() {            return Entity; // Replace 'Entity' with the ent