FG
💻 Software🗄️ Databases

DeleteResult / UpdateResult not implemented for all Drivers

Fresh5 days ago
Mar 14, 20260 views
Confidence Score71%
71%

Problem

Issue type: [ ] question [x] bug report [ ] feature request [ ] documentation issue Database system/driver: [ ] `cordova` [ ] `mongodb` [ ] `mssql` [ ] `mysql` / `mariadb` [ ] `oracle` [x] `postgres` [ ] `sqlite` [ ] `sqljs` [ ] `react-native` TypeORM version: [ ] `latest` [ ] `@next` [x] `0.2.7` (or put your version here) Steps to reproduce or a small repository showing the problem: 1. invoke `Repository.delete` 2. the returned `DeleteResult` does not include any info at all. Expecting to include the number of affected rows. I'm having trouble with `Repository.delete`: the operation successfully removes the entity from the database, but `DeleteResult` does not contain count of entities deleted, it's just `DeleteResult { raw: [] }`. This occurs with v0.2.7. Also, there doesn't appear to be a tag for version 0.2.7 on GitHub though there's a release on npmjs. Why is that? Why doesn't `DeleteResult` specify a property for the number of rows affected?

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Implement DeleteResult Count for Postgres Driver in TypeORM

Medium Risk

The Postgres driver in TypeORM version 0.2.7 does not return the count of affected rows in the DeleteResult object after executing the Repository.delete method. This is due to the lack of implementation for capturing the number of rows affected by the delete operation in this specific version.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Update TypeORM to Latest Version

    Upgrade TypeORM to the latest stable version where the DeleteResult includes the count of affected rows. This is the most straightforward fix as newer versions have addressed this issue.

    bash
    npm install typeorm@latest
  2. 2

    Modify Delete Method Implementation

    If upgrading is not an option, modify the delete method in the Postgres driver to include the count of affected rows. This requires editing the source code of TypeORM to capture the result of the delete operation.

    typescript
    // Example modification in PostgresDriver.ts
    const result = await this.connection.query(`DELETE FROM ${tableName} WHERE ${whereClause}`);
    return new DeleteResult(result.rowCount, result.rows);
  3. 3

    Test the Delete Operation

    After applying the fix, test the delete operation to ensure the DeleteResult now includes the count of affected rows. Create a test case that deletes an entity and checks the returned DeleteResult.

    typescript
    const result = await repository.delete(entityId);
    console.log(result.affected); // Should log the number of rows deleted
  4. 4

    Check for Other Driver Implementations

    Review other drivers in TypeORM to ensure they also implement the DeleteResult correctly. This helps maintain consistency across different database systems.

    typescript
    // Check implementation in other driver files
  5. 5

    Review GitHub Issues for Related Bugs

    Search the TypeORM GitHub repository for similar issues or bugs reported by other users. This can provide insights into whether this issue has been addressed in newer versions or if there are workarounds.

    bash
    // Visit GitHub issues page for TypeORM

Validation

Confirm that after the fix, invoking Repository.delete returns a DeleteResult object that includes the 'affected' property with the correct count of deleted rows. Run unit tests to validate the functionality.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

typeormormtypescriptbugnew-featuredriver:-postgresdriver:-mongodb