pop icon indicating copy to clipboard operation
pop copied to clipboard

Need to get sql.Result from genericDestroy()

Open mong0520 opened this issue 7 years ago • 4 comments

Description

While trying to delete a record by ID, via Destroy(), it will be great help for us to know the affected rows information instead of just success or not by error as the return value.

After digging into the code, I found that in dialect.go calls genericExec() to execute SQL command, it can obtain sql.Result which contains the information regarding to affected rows but it drops it.

...
_, err := s.Exec(stmt)
...

It's better to keep the information and return to caller to make decision.

Steps to Reproduce the Problem

  1. Create a record by ValidateAndCreate()
  2. Delete the record by Destroy()
  3. Verify the return value from Destroy(), I can only know if error occurs or not but not affected rows.

Expected Behavior

I can get both result and error information from Destroy()

mong0520 avatar Oct 05 '18 02:10 mong0520

I dug into this a little, if I am not mistaken, there are two ways you can use .Destroy, you could pass in a single record or you could pass in a slice. In either scenario, as long as no errors occur, would you not know the number of records affected? It would be the number of records you passed in to .Destroy.

ClaytonNorthey92 avatar Nov 01 '18 02:11 ClaytonNorthey92

I think it would be better if the function would return affected no. of rows as a return value along with the error. Let me know if it is fine. I would like to give a shot.

sivagollapalli avatar Nov 14 '18 16:11 sivagollapalli

It will be great to get the no. of rows along with error!

mong0520 avatar Nov 14 '18 16:11 mong0520

@sivagollapalli If you can make it without breaking changes, go ahead. :) Otherwise, you'll have to introduce a variant for the impacted function(s).

stanislas-m avatar Dec 08 '18 14:12 stanislas-m