typeorm icon indicating copy to clipboard operation
typeorm copied to clipboard

DeleteResult / UpdateResult not implemented for all Drivers

Open marko-asplund opened this issue 8 years ago • 41 comments

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?

marko-asplund avatar Jun 27 '18 06:06 marko-asplund

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.

pleerock avatar Jul 02 '18 20:07 pleerock

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

marko-asplund avatar Jul 03 '18 17:07 marko-asplund

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

pleerock avatar Jul 03 '18 18:07 pleerock

@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.

edevil avatar Oct 17 '18 15:10 edevil

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

thibaud-sanchez avatar Jan 17 '19 17:01 thibaud-sanchez

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

pleerock avatar Jan 18 '19 10:01 pleerock

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

HardySoftware avatar Jan 31 '19 13:01 HardySoftware

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.

akosasante avatar Aug 09 '19 02:08 akosasante

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

varogonz95 avatar Aug 21 '19 15:08 varogonz95

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

this didn't work for me, it just returns an empty object. I use [email protected].

dennbagas avatar Sep 03 '19 15:09 dennbagas

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

Has it been fixed?

liv1n9 avatar Feb 03 '20 10:02 liv1n9

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..

VinayKrMittal avatar Feb 10 '20 10:02 VinayKrMittal

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

AndreySavenkov avatar Mar 06 '20 20:03 AndreySavenkov

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

danielb7390 avatar May 03 '20 19:05 danielb7390

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

TBG-FR avatar May 31 '20 15:05 TBG-FR

Is there any alternative solution for this?

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

adelsagemilang avatar Jun 09 '20 05:06 adelsagemilang

Same issue

sqlite

ynwd avatar Aug 20 '20 16:08 ynwd

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

Has it been fixed?

+1

ibraah88 avatar Sep 30 '20 13:09 ibraah88

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

TBG-FR avatar Oct 10 '20 10:10 TBG-FR

Same issue in mssql driver

viniciusmolina12 avatar Dec 16 '20 14:12 viniciusmolina12