question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is there some way to get the number of rows deleted by a query builder's `delete` method?

See original GitHub issue

Is your feature request related to a problem?

The query builder docs mention a delete method: https://orm.masoniteproject.com/query-builder#deletes, but I don’t see any way of figuring out how many rows were affected by that delete.

What do we currently have to do now?

Right now, I’m turning around and immediately doing a SELECT ROW_COUNT() query, which may be a MySQL specific solution.

Describe the solution you’d like

It would be nice to have a standard way of fetching the number of rows affected by the delete. Perhaps delete() could return the count of deleted rows? I’m not sure if that would count as a breaking change or not. The docs don’t seem to mention what delete returns, but the implementation clearly does return… something: https://github.com/MasoniteFramework/orm/blob/685a30409cd4b971c24c932d78b684a2be085f58/src/masoniteorm/query/QueryBuilder.py#L530-L565, although the docstring disagrees with the implementation: the docstring says it returns self, when it actually returns the result of self.new_connection().query

Describe alternatives you’ve considered

No response

Would this be a breaking change ?

  • Yes

Anything else ?

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
josephmancusocommented, Jun 28, 2022

I will work on this one but it won’t be available until Masonite ORM 3 around September since this is changing existing functionality in a way that could not be backwards compatable

0reactions
josephmancusocommented, Jul 2, 2022

This wil also be a bit tricky because the SoftDeleteMixin changes the DELETE to an UPDATE. so will need to figure out how to get the results for an update clause as well

Read more comments on GitHub >

github_iconTop Results From Across the Web

best number of rows to delete in a delete query [closed]
You want to delete everything in the table. Then truncate table is the right approach. Your delete query needs to do a full...
Read more >
MySQL 8.0 Reference Manual :: 13.2.2 DELETE Statement
The DELETE statement deletes rows from tbl_name and returns the number of deleted rows. To check the number of deleted rows, call the...
Read more >
Query Deleted Records in Salesforce: 3 Easy Methods - Learn
To access all the records irrespective of their deletion status, Salesforce requires one to use the QUERY ALL construct. Let us now look...
Read more >
The best ways to use SQL DELETE Statement in a SQL table
There are several best practices to consider when using a SQL delete statement to remove data from a SQL table. Learn how to...
Read more >
Deleting many rows from a big table - Ask TOM
Deleting many rows from a big table Tom: We have a 6 millons rows table and we need to clean it. This process...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found