Skip to content

6.删除

afumu edited this page Jun 6, 2023 · 1 revision

根据ID删除

  resultDb := gplus.DeleteById[User](6)
  fmt.Println(resultDb.Error)
  fmt.Println(resultDb.RowsAffected)
  //  DELETE FROM `users` WHERE `id` = 6

根据多个ID删除

  resultDb := gplus.DeleteByIds[User]([]int{7, 8, 9})
  fmt.Println(resultDb.Error)
  fmt.Println(resultDb.RowsAffected)
  //   DELETE FROM `users` WHERE `id` IN (7,8,9)

根据条件删除

  query, u := gplus.NewQuery[User]()
  query.Eq(&u.Username, "afumu")
  resultDb := gplus.Delete[User](query)
  fmt.Println(resultDb.Error)
  fmt.Println(resultDb.RowsAffected)
  // DELETE FROM `users` WHERE username = 'afumu'
Clone this wiki locally