本文整理汇总了Golang中github.com/jinzhu/gorm.DB.Delete方法的典型用法代码示例。如果您正苦于以下问题:Golang DB.Delete方法的具体用法?Golang DB.Delete怎么用?Golang DB.Delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jinzhu/gorm.DB
的用法示例。
在下文中一共展示了DB.Delete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: deleteAccountHandler
//Deletes a certain account from the db
func deleteAccountHandler(db *gorm.DB, acc account, rendr render.Render) {
if err := db.Delete(&acc).Error; err != nil {
rendr.Text(http.StatusInternalServerError, err.Error())
} else {
rendr.Text(http.StatusOK, "Account deleted")
}
}
示例2: MediaDelete
func MediaDelete(db gorm.DB, r render.Render, params martini.Params) {
var media models.Media
if err := db.First(&media, params["id"]).Error; err != nil {
r.JSON(http.StatusNotFound, map[string]interface{}{"error": "Media not found"})
return
}
db.Delete(media)
r.JSON(http.StatusNoContent, nil)
}
示例3: ProjectDelete
func ProjectDelete(db gorm.DB, r render.Render, params martini.Params) {
var project models.Project
if err := db.First(&project, params["id"]).Error; err != nil {
r.JSON(http.StatusNotFound, map[string]interface{}{"error": "Project not found"})
return
}
db.Delete(project)
r.JSON(http.StatusNoContent, nil)
}
示例4: GroupDelete
func GroupDelete(db gorm.DB, r render.Render, params martini.Params) {
var group models.Group
if err := db.First(&group, params["id"]).Error; err != nil {
r.JSON(http.StatusNotFound, map[string]interface{}{"error": "Group not found"})
return
}
db.Delete(group)
r.JSON(http.StatusNoContent, nil)
}
示例5: DelRole
func (p *AuthDao) DelRole(db *gorm.DB, user uint, name string, resource_type string, resource_id uint) {
role := p.getRole(db, name, resource_type, resource_id)
for _, pe := range role.Permissions {
if pe.UserID == user {
db.Delete(&pe)
return
}
}
}
示例6: deleteUserHandler
//Deletes a user based on a given path `id` param
func deleteUserHandler(db *gorm.DB, params martini.Params, ren render.Render) {
u, err := findUserFromIDParam(db, params["id"])
if err != nil {
ren.Text(err.toMartiniRender())
return
}
if db.Delete(&u).Error != nil {
ren.Text(http.StatusInternalServerError, err.Error())
return
}
ren.Text(http.StatusOK, fmt.Sprintf("User with id: %d was deleted", u.ID))
}
示例7: deleteTodoHandler
func deleteTodoHandler(params martini.Params, rendr render.Render, db *gorm.DB) {
id, err := strconv.Atoi(params["id"])
if err != nil {
panic(err)
}
t, err := findTodo(db, &todo{ID: id})
if err != nil {
rendr.Text(http.StatusBadRequest, err.Error())
return
}
db.Delete(&t)
rendr.JSON(http.StatusOK, t)
}
示例8: GetDeleteTaskHandler
// GetDeleteTaskHandler creates HTTP handler for Delete Task operation
func GetDeleteTaskHandler(db *gorm.DB) echo.HandlerFunc {
return func(c *echo.Context) error {
id, err := strconv.ParseInt(c.Param("id"), 10, 64)
if err != nil {
return c.JSON(http.StatusBadRequest, NewApiError(err.Error()))
}
task := model.Task{Id: id}
if err := db.Delete(&task).Error; err != nil {
return c.JSON(http.StatusInternalServerError, NewApiError(err.Error()))
}
return c.JSON(http.StatusOK, task)
}
}
示例9: BeforeDelete
// BeforeDelete invokes required actions before deletion.
func (u *Repo) BeforeDelete(tx *gorm.DB) error {
tags := Tags{}
tx.Model(
u,
).Related(
&tags,
)
for _, tag := range tags {
if err := tx.Delete(tag).Error; err != nil {
return err
}
}
return nil
}
示例10: upgrade_v3
func upgrade_v3(db gorm.DB) {
// Hash the passwords
logging.Info("Migrating 2 => 3")
var unhashed []user.AuthenticationMethod
db.Where("method_type = ?", user.AUTH_PASSWD).Find(&unhashed)
for i := 0; i < len(unhashed); i++ {
hashed, err := user.HashedPasswordAuth(unhashed[i].Value)
if err != nil {
logging.Error("data", "Could not transform password. ID ", unhashed[i].ID)
} else {
hashed.UserID = unhashed[i].UserID
db.Create(&hashed)
db.Delete(&unhashed[i])
}
}
}
示例11: DeleteSpaceSetting
func DeleteSpaceSetting(db gorm.DB, router *gin.Engine) {
router.DELETE("/space_setting/:id", func(c *gin.Context) {
_id := c.Param("id")
if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
space_setting := &model.SpaceSetting{
SpaceSettingId: model.SpaceSettingId{Id: id},
}
if err := db.First(space_setting).Error; err == nil {
db.Delete(space_setting)
c.AbortWithStatus(http.StatusOK)
} else {
c.AbortWithStatus(http.StatusNotFound)
}
} else {
log.Print(err)
c.AbortWithError(http.StatusBadRequest, err)
}
})
}
示例12: DeleteWallEntry
func DeleteWallEntry(db gorm.DB, router *gin.Engine) {
router.DELETE("/wall_entry/:id", func(c *gin.Context) {
_id := c.Param("id")
if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
wall_entry := &model.WallEntry{
WallEntryId: model.WallEntryId{Id: id},
}
if err := db.First(wall_entry).Error; err == nil {
db.Delete(wall_entry)
c.AbortWithStatus(http.StatusOK)
} else {
c.AbortWithStatus(http.StatusNotFound)
}
} else {
log.Print(err)
c.AbortWithError(http.StatusBadRequest, err)
}
})
}
示例13: DeleteGroupAdmin
func DeleteGroupAdmin(db gorm.DB, router *gin.Engine) {
router.DELETE("/group_admin/:id", func(c *gin.Context) {
_id := c.Param("id")
if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
group_admin := &model.GroupAdmin{
GroupAdminId: model.GroupAdminId{Id: id},
}
if err := db.First(group_admin).Error; err == nil {
db.Delete(group_admin)
c.AbortWithStatus(http.StatusOK)
} else {
c.AbortWithStatus(http.StatusNotFound)
}
} else {
log.Print(err)
c.AbortWithError(http.StatusBadRequest, err)
}
})
}
示例14: DeleteModuleEnabled
func DeleteModuleEnabled(db gorm.DB, router *gin.Engine) {
router.DELETE("/module_enabled/:id", func(c *gin.Context) {
_id := c.Param("id")
if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
module_enabled := &model.ModuleEnabled{
ModuleEnabledId: model.ModuleEnabledId{Id: id},
}
if err := db.First(module_enabled).Error; err == nil {
db.Delete(module_enabled)
c.AbortWithStatus(http.StatusOK)
} else {
c.AbortWithStatus(http.StatusNotFound)
}
} else {
log.Print(err)
c.AbortWithError(http.StatusBadRequest, err)
}
})
}
示例15: DeleteUserHttpSession
func DeleteUserHttpSession(db gorm.DB, router *gin.Engine) {
router.DELETE("/user_http_session/:id", func(c *gin.Context) {
_id := c.Param("id")
if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
user_http_session := &model.UserHttpSession{
UserHttpSessionId: model.UserHttpSessionId{Id: id},
}
if err := db.First(user_http_session).Error; err == nil {
db.Delete(user_http_session)
c.AbortWithStatus(http.StatusOK)
} else {
c.AbortWithStatus(http.StatusNotFound)
}
} else {
log.Print(err)
c.AbortWithError(http.StatusBadRequest, err)
}
})
}