How can I get soft deleted entity from typeorm in postgreSQL?
When handling soft-deleted entities in a PostgreSQL database, a common practice is to set up a flag column in the table, such as or . This way, when an entity is "deleted," it is not actually removed from the database; instead, the flag field is updated. Next, I will explain in detail how to retrieve soft-deleted entities from such a setup and provide relevant SQL query examples.1. Using the FlagAssume we have a table named that includes a boolean column named . When an employee is soft-deleted, is set to .To retrieve all soft-deleted employees, we can use the following SQL query:This query retrieves all records where the field is , i.e., all soft-deleted employees.2. Using the TimestampAnother common practice is to use a column in the table, which is a timestamp type. When a record is soft-deleted, this column is set to the specific time of the soft deletion; for records that are not soft-deleted, the column remains .To retrieve all soft-deleted entities, we can use the following SQL query:This query selects all records where the field is not .ExampleAssume we have an table that includes the fields , , , and .The soft-deletion of an employee can be performed as follows:Then, use the queries mentioned earlier to retrieve all soft-deleted employees:These methods can effectively help us manage and query soft-deleted entities, maintaining database integrity and tracking historical records without fully deleting data.