Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeleteResult / UpdateResult not implemented for all Drivers #2415

Closed
marko-asplund opened this issue Jun 27, 2018 · 41 comments · Fixed by #7884
Closed

DeleteResult / UpdateResult not implemented for all Drivers #2415

marko-asplund opened this issue Jun 27, 2018 · 41 comments · Fixed by #7884

Comments

@marko-asplund
Copy link

marko-asplund commented Jun 27, 2018

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?

@pleerock
Copy link
Member

pleerock commented Jul 2, 2018

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?

I'll fix that.

Why doesn't DeleteResult specify a property for the number of rows affected?

because it wasn't implemented. We already have this feature reported, but noone still took on its implementation. Please feel free, its an easy feature to implement.

@marko-asplund
Copy link
Author

@pleerock Can you give a reference to an earlier report? I just tried, but was unable to find one.

@pleerock
Copy link
Member

pleerock commented Jul 3, 2018

I could find only #1308 which is related, need to search deeper to find that one. But anyway, you don't need that issue if you want to implement it. You know what your goal, you can easily do that. But please be sure to implement it for all drivers if you are going to do it. That's easy feature to implement

@edevil
Copy link

edevil commented Oct 17, 2018

@pleerock Currently the behavior is different between Postgres and MySQL, for example.

MySQL returns: {"raw":{"fieldCount":0,"affectedRows":0,"insertId":0,"serverStatus":34,"warningCount":0,"message":"","protocol41":true,"changedRows":0}}

Postgres returns: {"raw": []}

So in a sense it seems MySQL already has this feature implemented but not Postgres.

@thibaud-sanchez
Copy link

I have the same problem with SQLite and 0.2.8
It returns : {"raw": []}

@pleerock
Copy link
Member

raw is just raw result returned by underlying database driver. As I pointed above we need to implement this feature request.

@HardySoftware
Copy link

MongoDb does not return anything, neither raw nor affected regardless if the record is found/deleted or not.

@akosasante
Copy link
Contributor

In case it helps anyone else in the future, for postgres I ended up just using

       await this.db.createQueryBuilder()
            .delete()
            .whereInIds(id)
            .returning("id")
            .execute();

It returns a DeleteResult like: { raw: [ {id: 1} ], affected: 1 }. You could also do .returning("*") if you want the full object returned.

@varogonz95
Copy link

Is this implemented? I'm facing this issue too with sqlite3 and typeorm@^0.2.12

@dennbagas
Copy link

       await this.db.createQueryBuilder()
            .delete()
            .whereInIds(id)
            .returning("id")
            .execute();

this didn't work for me, it just returns an empty object. I use typeorm@0.2.18.

@liv1n9
Copy link

liv1n9 commented Feb 3, 2020

MongoDb does not return anything, neither raw nor affected regardless if the record is found/deleted or not.

Has it been fixed?

@VinayKrMittal
Copy link

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?

same issue for me. any solution..

@AndreySavenkov
Copy link

Same issue. Deleting record in MongoDB results an empty DeleteResult object

@danielb7390
Copy link

Trying to change from sequelize... and i hit this "bug", quite sad this issue is still open..

@TBG-FR
Copy link

TBG-FR commented May 31, 2020

@AndreySavenkov Same here. I'm curious, how did you managed that then ?

@adelsagemilang
Copy link

Is there any alternative solution for this?

Same issue. Deleting record in MongoDB results an empty DeleteResult object

@ynwd
Copy link

ynwd commented Aug 20, 2020

Same issue

sqlite

@ibraah88
Copy link

MongoDb does not return anything, neither raw nor affected regardless if the record is found/deleted or not.

Has it been fixed?

+1

@TBG-FR
Copy link

TBG-FR commented Oct 10, 2020

@imnotjames can you also add driver:mongodb (or should we open another issue ?)

@imnotjames imnotjames changed the title Repository.delete doesn't return the number of affected rows Delete / Update not implemented for all Drivers Oct 17, 2020
@imnotjames imnotjames changed the title Delete / Update not implemented for all Drivers DeleteResult / UpdateResult not implemented for all Drivers Oct 17, 2020
@viniciusmolina12
Copy link

Same issue in mssql driver

@Juraj-Masiar
Copy link

This should be fixed also for the "INSERT" where Postgres returns number of inserted rows.
I'm using .onConflict('do nothing') so I now don't know if the row was inserted or not. At least here I can use .returning('id') as a workaround.

@pliniopvv
Copy link

Not fixed to SQLite3?

UpdateResult { generatedMaps: [], raw: [] }

@nebkat
Copy link
Contributor

nebkat commented Jan 9, 2021

Am proposing that processing of results is moved to individual drivers as part of #7058 e666d7d.

@SalahAdDin
Copy link

Two years and same problem with Mongo: it always returns {}, it does not matter if it deletes the user or not, it does not return any error.

@Zyles
Copy link

Zyles commented Apr 19, 2021

Why is this not a priority?

@Kolobamanacas
Copy link

So, am I correct: there is no way to check whether any rows have been affected by delete method for PostgreSQL, right?

@matomesc
Copy link

@Kolobamanacas this works as expected for postgres on 0.2.32:

// Deleting one row
const result = await repo.delete(userA.id);
// Return result is
DeleteResult { raw: [], affected: 1 }

@nbaua
Copy link

nbaua commented Jun 2, 2021

No one really looking in to UpdateResult or DeleteResult for mongodb, its been a while this thread is still open..

@VictorLM
Copy link

VictorLM commented Jul 5, 2021

Still getting empty result using MongoDB driver.

@imnotjames
Copy link
Contributor

The logic for query results have been moved into the drivers via #7753

This means implementing it is up to the drivers.

The MongoDB driver doesn't return lots of this because it's EXTREMELY janky. It was implemented to query by not really doing things like any other driver & hacks up the whole TypeORM library to make it barely work..

Might still be able to make it sort of work, though, if the underlying module supports it.

Even then, though, it might not help much because it doesn't use the query builder and all that jazz.

@imnotjames
Copy link
Contributor

This should be implemented for every driver now except for MongoDB with #7753 - to be in the next release.

@imnotjames
Copy link
Contributor

Opened a PR to implement it for the mongo EntityManager because that seems to be where that logic lives..

@marcosdipaolo
Copy link

marcosdipaolo commented Jul 24, 2021

And for the rest of the drivers? sqlite here, neither DeleteResult nor UpdateResult have the right info

@imnotjames
Copy link
Contributor

And for the rest of the drivers? sqlite here, neither DeleteResult nor UpdateResult have the right info

With the master branch?

@marcosdipaolo
Copy link

And for the rest of the drivers? sqlite here, neither DeleteResult nor UpdateResult have the right info

With the master branch?

"typeorm": "^0.2.34",

@imnotjames
Copy link
Contributor

imnotjames commented Jul 27, 2021

This code has not been released yet. We're aiming for a release this week.

We'll also be aiming to do a "bleeding edge" set of releases.

@jdeg
Copy link

jdeg commented Aug 20, 2021

I'm still having this issue in SQLite3. Any news about it?

@imnotjames
Copy link
Contributor

I'm still having this issue in SQLite3. Any news about it?

Should be released at this point. If it's not working for your use case please open a new issue.

@HazemHa
Copy link

HazemHa commented Jan 20, 2022

it is not solved yet
MySQL version: 8.0.27

but you can do it by yourself

async remove(id: string): Promise<DeleteResult> {
        const deletedRow = await this.nodesRepository.findOne({ uuid: id });
        const deleteResultNode = await this.nodesRepository.delete({ uuid: id })
        if (deleteResultNode.affected > 0) {
            deleteResultNode.raw.push(deletedRow)
        }

        return deleteResultNode;

    }

@DanielYoung-Till
Copy link

2024 now.

@SteTSC
Copy link

SteTSC commented Feb 12, 2024

2024 now.

As noted by @DanielYoung-Till this is still not resolved in 0.3.20.

Code:

  update(id: number, myEntity: Partial<MyEntity>): Promise<MyEntity> {
    return this.repository
      .update({ id }, myEntity)
      .then((event) => {
        console.log(event);
      });

Expected:

{ generatedMaps: [], raw: [], affected: 1 }

Actual:

{ generatedMaps: [], raw: [{ id:123, ...etc }], affected: 1 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.