Gorm for batch deletion


Golang uses the Gorm framework for batch deletion. How to write this statement?

func DeleteUsers(id []int64) error {
    return db.Table("users").Delete(id).Error

After using the above method, all the data in the table will be cleared.


You can update the code as below to solve the issue.

func DeleteUsers(id []int64) error {
    return db.Table("users").Where("users.id", id).Delete(struct{}{}).Error

Answered By – Chandan

Answer Checked By – Mary Flores (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.